mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-08-03 08:20:28 +00:00
Make exciting improvements
- Add Lua backtraces to redbean! - Wipe serving keys after redbean forks - Audit redbean to remove free via exit - Log SSL client ciphersuite preferences - Increase ASAN malloc() backtrace depth - Make GetSslRoots() behave as a singleton - Move leaks.c from LIBC_TESTLIB to LIBC_LOG - Add undocumented %n to printf() for newlines - Fix redbean memory leak reindexing inode change - Fix redbean memory leak with Fetch() DNS object - Restore original environ after __cxa_finalize() - Make backtrace always work after __cxa_finalize() - Introduce COUNTEXPR() diagnostic / benchmark tool - Fix a few more instances of errno being clobbered - Consolidate the ANSI color disabling internal APIs
This commit is contained in:
parent
f5831a62fa
commit
af645fcbec
61 changed files with 1354 additions and 814 deletions
85
libc/log/countexpr.h
Normal file
85
libc/log/countexpr.h
Normal file
|
@ -0,0 +1,85 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_LOG_COUNTEXPR_H_
|
||||
#define COSMOPOLITAN_LIBC_LOG_COUNTEXPR_H_
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/nexgen32e/bench.h"
|
||||
#include "libc/nexgen32e/bsr.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
/**
|
||||
* Shows nanosecond timings histogram for expr at exit().
|
||||
*/
|
||||
#define COUNTEXPR(expr) \
|
||||
COUNTEXPR_(expr, #expr, STRINGIFY(__FILE__), __LINE__, rdtsc, rdtsc, \
|
||||
"COUNTEXPR")
|
||||
|
||||
/**
|
||||
* Like COUNTEXPR() but can be used on function calls that return void.
|
||||
*/
|
||||
#define COUNTSTMT(stmt) \
|
||||
(void)COUNTEXPR_((stmt, 0), #stmt, STRINGIFY(__FILE__), __LINE__, rdtsc, \
|
||||
rdtsc, "COUNTSTMT")
|
||||
|
||||
/**
|
||||
* Same as COUNTEXPR() but uses Intel's expensive measurement technique.
|
||||
*/
|
||||
#define BENCHEXPR(expr) \
|
||||
COUNTEXPR_(expr, #expr, STRINGIFY(__FILE__), __LINE__, __startbench, \
|
||||
__endbench, "BENCHEXPR")
|
||||
|
||||
#define COUNTEXPR_(expr, code, file, line, start, stop, macro) \
|
||||
COUNTEXPR__(expr, STRINGIFY(code), file, line, start, stop, STRINGIFY(macro))
|
||||
|
||||
#define COUNTEXPR__(expr, code, file, line, start, stop, macro) \
|
||||
({ \
|
||||
struct countexpr *InfO; \
|
||||
uint64_t t1_, t2_, TiCkS, NaNoS; \
|
||||
t1_ = start(); \
|
||||
asm volatile("" ::: "memory"); \
|
||||
autotype(expr) ReS = (expr); \
|
||||
asm volatile("" ::: "memory"); \
|
||||
t2_ = stop(); \
|
||||
TiCkS = t2_ >= t1_ ? t2_ - t1_ : ~t1_ + t2_ + 1; \
|
||||
asm(".section .rodata.str1.1,\"aMS\",@progbits,1\n\t" \
|
||||
".align\t1\n" \
|
||||
"31340:\t.asciz\t" file "\n\t" \
|
||||
"31338:\t.asciz\t" code "\n" \
|
||||
"31332:\t.asciz\t" macro "\n" \
|
||||
".previous\n\t" \
|
||||
".section .yoink\n\t" \
|
||||
"nopl\tcountexpr_data(%%rip)\n\t" \
|
||||
".previous\n\t" \
|
||||
".section .sort.data.countexpr.2,\"a\",@progbits\n\t" \
|
||||
".align\t8\n31337:\t" \
|
||||
".quad\t" #line "\n\t" \
|
||||
".quad\t31340b\n\t" \
|
||||
".quad\t31338b\n\t" \
|
||||
".quad\t31332b\n\t" \
|
||||
".rept\t65\n\t" \
|
||||
".quad\t0\n\t" \
|
||||
".endr\n\t" \
|
||||
".previous\n\t" \
|
||||
"lea\t31337b(%%rip),%0" \
|
||||
: "=r"(InfO)); \
|
||||
/* approximation of round(x*.323018) which is usually */ \
|
||||
/* the ratio, between x86 rdtsc ticks and nanoseconds */ \
|
||||
NaNoS = (TiCkS * 338709) >> 20; \
|
||||
++InfO->logos[NaNoS ? bsrl(NaNoS) + 1 : 0]; \
|
||||
ReS; \
|
||||
})
|
||||
|
||||
struct countexpr {
|
||||
long line; /* zero for last entry */
|
||||
const char *file;
|
||||
const char *code;
|
||||
const char *macro;
|
||||
long logos[65];
|
||||
};
|
||||
|
||||
extern struct countexpr countexpr_data[];
|
||||
|
||||
void countexpr_report(void);
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_LOG_COUNTEXPR_H_ */
|
Loading…
Add table
Add a link
Reference in a new issue