mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-03 11:12:27 +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
82
libc/log/countexpr_report.c
Normal file
82
libc/log/countexpr_report.c
Normal file
|
@ -0,0 +1,82 @@
|
|||
/*-*- 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 2021 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 "libc/alg/alg.h"
|
||||
#include "libc/assert.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/log/countexpr.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
|
||||
static long GetLongSum(const long *h, size_t n) {
|
||||
long t;
|
||||
size_t i;
|
||||
for (t = i = 0; i < n; ++i) {
|
||||
if (__builtin_add_overflow(t, h[i], &t)) {
|
||||
t = LONG_MAX;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
static size_t GetRowCount(const long *h, size_t n) {
|
||||
while (n && !h[n - 1]) --n;
|
||||
return n;
|
||||
}
|
||||
|
||||
static void PrintHistogram(const long *h, size_t n, long t) {
|
||||
size_t i;
|
||||
long j, p;
|
||||
char s[101];
|
||||
unsigned long logos;
|
||||
for (i = 0; i < n; ++i) {
|
||||
p = (h[i] * 10000 + (t >> 1)) / t;
|
||||
assert(0 <= p && p <= 10000);
|
||||
if (p) {
|
||||
for (j = 0; j < p / 100; ++j) s[j] = '#';
|
||||
s[j] = 0;
|
||||
logos = i ? 1ul << (i - 1) : 0;
|
||||
kprintf("%'12lu %'16ld %3d.%02d%% %s%n", logos, h[i], p / 100, p % 100,
|
||||
s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void countexpr_report(void) {
|
||||
long hits;
|
||||
struct countexpr *p;
|
||||
for (p = countexpr_data; p->line; ++p) {
|
||||
if ((hits = GetLongSum(p->logos, 64))) {
|
||||
kprintf("%s:%d: %s(%s) %'ld hits\n", p->file, p->line, p->macro, p->code,
|
||||
hits);
|
||||
PrintHistogram(p->logos, 64, hits);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static textstartup void countexpr_init() {
|
||||
atexit(countexpr_report);
|
||||
}
|
||||
|
||||
const void *const countexpr_ctor[] initarray = {
|
||||
countexpr_init,
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue