forked from jart/blink
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
116 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ | ||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ | ||
╞══════════════════════════════════════════════════════════════════════════════╡ | ||
│ Copyright 2022 Justine Alexandra Roberts Tunney │ | ||
│ │ | ||
│ Permission to use, copy, modify, and/or distribute this software for │ | ||
│ any purpose with or without fee is hereby granted, provided that the │ | ||
│ above copyright notice and this permission notice appear in all copies. │ | ||
│ │ | ||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ | ||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ | ||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ | ||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ | ||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ | ||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ | ||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ | ||
│ PERFORMANCE OF THIS SOFTWARE. │ | ||
╚─────────────────────────────────────────────────────────────────────────────*/ | ||
#include "blink/log.h" | ||
#include "blink/stats.h" | ||
|
||
#define DEFINE_AVERAGE(S) struct Average S; | ||
#define DEFINE_COUNTER(S) long S; | ||
#include "blink/stats.inc" | ||
#undef DEFINE_AVERAGE | ||
#undef DEFINE_COUNTER | ||
|
||
#define APPEND(...) o += snprintf(b + o, n - o, __VA_ARGS__) | ||
|
||
void PrintStats(void) { | ||
#ifndef NDEBUG | ||
char b[2048]; | ||
int n = sizeof(b); | ||
int o = 0; | ||
b[0] = 0; | ||
#define DEFINE_COUNTER(S) APPEND("%-32s = %ld\n", #S, S); | ||
#define DEFINE_AVERAGE(S) APPEND("%-32s = %.6g\n", #S, S.a); | ||
#include "blink/stats.inc" | ||
#undef S | ||
WriteErrorString(b); | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#ifndef BLINK_STATS_H_ | ||
#define BLINK_STATS_H_ | ||
#include "blink/tsan.h" | ||
|
||
#ifndef NDEBUG | ||
// we don't care about the accuracy of statistics across threads. some | ||
// hardware architectures don't even seem to have atomic addition ops. | ||
#define STATISTIC(x) \ | ||
do { \ | ||
IGNORE_RACES_START(); \ | ||
x; \ | ||
IGNORE_RACES_END(); \ | ||
} while (0) | ||
#else | ||
#define STATISTIC(x) (void)0 | ||
#endif | ||
|
||
#define AVERAGE(S, x) S.a += ((x)-S.a) / ++S.i | ||
|
||
#ifndef NDEBUG | ||
#ifdef __GNUC__ | ||
#define GET_COUNTER(S) \ | ||
({ \ | ||
IGNORE_RACES_START(); \ | ||
long S_ = S; \ | ||
IGNORE_RACES_END(); \ | ||
S_; \ | ||
}) | ||
#else | ||
#define GET_COUNTER(S) (S) | ||
#endif | ||
#else | ||
#define GET_COUNTER(S) 0L | ||
#endif | ||
|
||
#define DEFINE_COUNTER(S) extern long S; | ||
#define DEFINE_AVERAGE(S) extern struct Average S; | ||
#include "blink/stats.inc" | ||
#undef DEFINE_COUNTER | ||
#undef DEFINE_AVERAGE | ||
|
||
struct Average { | ||
double a; | ||
long i; | ||
}; | ||
|
||
void PrintStats(void); | ||
|
||
#endif /* BLINK_STATS_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
DEFINE_COUNTER(instructions_cached) | ||
DEFINE_COUNTER(instructions_decoded) | ||
DEFINE_COUNTER(instructions_dispatched) | ||
DEFINE_COUNTER(page_overlaps) | ||
DEFINE_COUNTER(tlb_hits_1) | ||
DEFINE_COUNTER(tlb_hits_2) | ||
DEFINE_COUNTER(tlb_misses) |