1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
/* ztrace: what a traced program can say about itself.
*
* Link libztrace-agent.a (or libztrace-agent.so) and run the program under
* `ztrace run`. Run without a tracer, these do nothing.
*
* A statically linked agent sees the allocator and thread creation when the
* program is linked with:
* -Wl,--wrap=malloc,--wrap=calloc,--wrap=realloc,--wrap=free
* -Wl,--wrap=posix_memalign,--wrap=aligned_alloc,--wrap=memalign
* -Wl,--wrap=pthread_create,--wrap=fork
* and, when libc is linked statically too (glibc with -static), so that its
* own are still there to call:
* -Wl,-u,malloc,-u,pthread_create,-u,fork
*/
#ifndef ZTRACE_H
#define ZTRACE_H
#include <stddef.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/* A point in the run worth a moment of the recording: a `mark` event. */
void ztrace_mark(const char *label, uint64_t value);
/* Names `len` bytes at `ptr` (a `variable` event), records them, and keeps
* recording what changes in them: only the bytes that changed, at each event
* that ends a moment. The memory must stay mapped. More than 1 MiB is
* refused, with a line on stderr: watch the part that matters. */
void ztrace_watch(const void *ptr, size_t len, const char *name);
/* Records `len` bytes at `ptr` as they are now, once. At most 1 MiB. */
void ztrace_snapshot(const void *ptr, size_t len);
#ifdef __cplusplus
}
#endif
#endif
|