|
9 | 9 | * static inline so each translation unit can use them without pulling in a |
10 | 10 | * separate object; the getenv check resolves once per translation unit but |
11 | 11 | * the resolution itself is idempotent. |
| 12 | + * |
| 13 | + * Accepted env values: |
| 14 | + * unset, "", "0" -> all tracing off |
| 15 | + * "1", "steps" -> per-step VM bring-up timings (this header) |
| 16 | + * "syscalls" -> per-syscall histogram (debug/syscall-hist.c) |
| 17 | + * "all" -> both, comma-separated tokens also accepted |
| 18 | + * "1" is preserved as a legacy alias for "steps" so old scripts keep |
| 19 | + * working. The histogram mode never enables the step tracer and vice |
| 20 | + * versa, so a user can ask for one without paying for the other. |
12 | 21 | */ |
13 | 22 |
|
14 | 23 | #ifndef ELFUSE_STARTUP_TRACE_H |
|
30 | 39 | static pthread_once_t startup_trace_once = PTHREAD_ONCE_INIT; |
31 | 40 | static bool startup_trace_value; |
32 | 41 |
|
| 42 | +static inline bool startup_trace_env_has(const char *env, const char *tok) |
| 43 | +{ |
| 44 | + if (!env || !env[0]) |
| 45 | + return false; |
| 46 | + size_t toklen = strlen(tok); |
| 47 | + const char *p = env; |
| 48 | + while (*p) { |
| 49 | + const char *comma = strchr(p, ','); |
| 50 | + size_t len = comma ? (size_t) (comma - p) : strlen(p); |
| 51 | + if (len == toklen && memcmp(p, tok, toklen) == 0) |
| 52 | + return true; |
| 53 | + if (!comma) |
| 54 | + break; |
| 55 | + p = comma + 1; |
| 56 | + } |
| 57 | + return false; |
| 58 | +} |
| 59 | + |
33 | 60 | static inline void startup_trace_resolve(void) |
34 | 61 | { |
35 | 62 | const char *v = getenv("ELFUSE_STARTUP_TRACE"); |
36 | | - startup_trace_value = v && v[0] && strcmp(v, "0") != 0; |
| 63 | + if (!v || !v[0] || !strcmp(v, "0")) |
| 64 | + return; |
| 65 | + /* The legacy "1" knob enables steps. Recognize it both as the whole |
| 66 | + * value and as a token so compound forms like "1,syscalls" still |
| 67 | + * keep the step trace on alongside the histogram, instead of |
| 68 | + * silently dropping it. |
| 69 | + */ |
| 70 | + if (!strcmp(v, "1") || startup_trace_env_has(v, "1") || |
| 71 | + startup_trace_env_has(v, "steps") || startup_trace_env_has(v, "all")) |
| 72 | + startup_trace_value = true; |
37 | 73 | } |
38 | 74 |
|
39 | 75 | static inline bool startup_trace_enabled(void) |
|
0 commit comments