Define constructor for buffered writer argument
This commit is contained in:
parent
6d8e616902
commit
40a391408c
@ -14,10 +14,20 @@ typedef struct {
|
|||||||
void (*write_cb)(void *, const char *);
|
void (*write_cb)(void *, const char *);
|
||||||
void *cbopaque;
|
void *cbopaque;
|
||||||
char *buf;
|
char *buf;
|
||||||
size_t buf_size; /* must be one less than the capacity of buf array */
|
size_t buf_size;
|
||||||
size_t buf_end;
|
size_t buf_end;
|
||||||
} buf_write_arg_t;
|
} buf_write_arg_t;
|
||||||
|
|
||||||
|
JEMALLOC_ALWAYS_INLINE void
|
||||||
|
buf_write_init(buf_write_arg_t *arg, void (*write_cb)(void *, const char *),
|
||||||
|
void *cbopaque, char *buf, size_t buf_len) {
|
||||||
|
arg->write_cb = write_cb;
|
||||||
|
arg->cbopaque = cbopaque;
|
||||||
|
arg->buf = buf;
|
||||||
|
arg->buf_size = buf_len - 1; /* Accommodating '\0' at the end. */
|
||||||
|
arg->buf_end = 0;
|
||||||
|
}
|
||||||
|
|
||||||
void buf_write_flush(buf_write_arg_t *arg);
|
void buf_write_flush(buf_write_arg_t *arg);
|
||||||
void buf_write_cb(void *buf_write_arg, const char *s);
|
void buf_write_cb(void *buf_write_arg, const char *s);
|
||||||
|
|
||||||
|
@ -3694,14 +3694,15 @@ je_malloc_stats_print(void (*write_cb)(void *, const char *), void *cbopaque,
|
|||||||
if (config_debug) {
|
if (config_debug) {
|
||||||
stats_print(write_cb, cbopaque, opts);
|
stats_print(write_cb, cbopaque, opts);
|
||||||
} else {
|
} else {
|
||||||
char *stats_print_buf = (char *)iallocztm(tsdn,
|
char *buf = (char *)iallocztm(tsdn, STATS_PRINT_BUFSIZE,
|
||||||
STATS_PRINT_BUFSIZE, sz_size2index(STATS_PRINT_BUFSIZE),
|
sz_size2index(STATS_PRINT_BUFSIZE), false, NULL, true,
|
||||||
false, NULL, true, arena_get(TSDN_NULL, 0, true), true);
|
arena_get(TSDN_NULL, 0, true), true);
|
||||||
buf_write_arg_t stats_print_buf_arg = {write_cb, cbopaque,
|
buf_write_arg_t buf_arg;
|
||||||
stats_print_buf, STATS_PRINT_BUFSIZE - 1, 0};
|
buf_write_init(&buf_arg, write_cb, cbopaque, buf,
|
||||||
stats_print(buf_write_cb, &stats_print_buf_arg, opts);
|
STATS_PRINT_BUFSIZE);
|
||||||
buf_write_flush(&stats_print_buf_arg);
|
stats_print(buf_write_cb, &buf_arg, opts);
|
||||||
idalloctm(tsdn, stats_print_buf, NULL, NULL, true, true);
|
buf_write_flush(&buf_arg);
|
||||||
|
idalloctm(tsdn, buf, NULL, NULL, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
check_entry_exit_locking(tsdn);
|
check_entry_exit_locking(tsdn);
|
||||||
|
@ -629,15 +629,16 @@ prof_log_stop(tsdn_t *tsdn) {
|
|||||||
struct prof_emitter_cb_arg_s arg;
|
struct prof_emitter_cb_arg_s arg;
|
||||||
arg.fd = fd;
|
arg.fd = fd;
|
||||||
|
|
||||||
char *prof_log_stop_buf = (char *)iallocztm(tsdn,
|
char *buf = (char *)iallocztm(tsdn, PROF_LOG_STOP_BUFSIZE,
|
||||||
PROF_LOG_STOP_BUFSIZE, sz_size2index(PROF_LOG_STOP_BUFSIZE),
|
sz_size2index(PROF_LOG_STOP_BUFSIZE), false, NULL, true,
|
||||||
false, NULL, true, arena_get(TSDN_NULL, 0, true), true);
|
arena_get(TSDN_NULL, 0, true), true);
|
||||||
buf_write_arg_t prof_log_stop_buf_arg = {prof_emitter_write_cb, &arg,
|
buf_write_arg_t buf_arg;
|
||||||
prof_log_stop_buf, PROF_LOG_STOP_BUFSIZE - 1, 0};
|
buf_write_init(&buf_arg, prof_emitter_write_cb, &arg, buf,
|
||||||
|
PROF_LOG_STOP_BUFSIZE);
|
||||||
|
|
||||||
/* Emit to json. */
|
/* Emit to json. */
|
||||||
emitter_init(&emitter, emitter_output_json_compact, buf_write_cb,
|
emitter_init(&emitter, emitter_output_json_compact, buf_write_cb,
|
||||||
&prof_log_stop_buf_arg);
|
&buf_arg);
|
||||||
|
|
||||||
emitter_begin(&emitter);
|
emitter_begin(&emitter);
|
||||||
prof_log_emit_metadata(&emitter);
|
prof_log_emit_metadata(&emitter);
|
||||||
@ -646,8 +647,8 @@ prof_log_stop(tsdn_t *tsdn) {
|
|||||||
prof_log_emit_allocs(tsd, &emitter);
|
prof_log_emit_allocs(tsd, &emitter);
|
||||||
emitter_end(&emitter);
|
emitter_end(&emitter);
|
||||||
|
|
||||||
buf_write_flush(&prof_log_stop_buf_arg);
|
buf_write_flush(&buf_arg);
|
||||||
idalloctm(tsdn, prof_log_stop_buf, NULL, NULL, true, true);
|
idalloctm(tsdn, buf, NULL, NULL, true, true);
|
||||||
|
|
||||||
/* Reset global state. */
|
/* Reset global state. */
|
||||||
if (log_tables_initialized) {
|
if (log_tables_initialized) {
|
||||||
|
@ -462,8 +462,9 @@ prof_recent_alloc_dump(tsd_t *tsd, void (*write_cb)(void *, const char *),
|
|||||||
char *buf = (char *)iallocztm(tsd_tsdn(tsd), PROF_RECENT_PRINT_BUFSIZE,
|
char *buf = (char *)iallocztm(tsd_tsdn(tsd), PROF_RECENT_PRINT_BUFSIZE,
|
||||||
sz_size2index(PROF_RECENT_PRINT_BUFSIZE), false, NULL, true,
|
sz_size2index(PROF_RECENT_PRINT_BUFSIZE), false, NULL, true,
|
||||||
arena_get(tsd_tsdn(tsd), 0, false), true);
|
arena_get(tsd_tsdn(tsd), 0, false), true);
|
||||||
buf_write_arg_t buf_arg = {write_cb, cbopaque, buf,
|
buf_write_arg_t buf_arg;
|
||||||
PROF_RECENT_PRINT_BUFSIZE - 1, 0};
|
buf_write_init(&buf_arg, write_cb, cbopaque, buf,
|
||||||
|
PROF_RECENT_PRINT_BUFSIZE);
|
||||||
emitter_t emitter;
|
emitter_t emitter;
|
||||||
emitter_init(&emitter, emitter_output_json_compact, buf_write_cb,
|
emitter_init(&emitter, emitter_output_json_compact, buf_write_cb,
|
||||||
&buf_arg);
|
&buf_arg);
|
||||||
|
Loading…
Reference in New Issue
Block a user