Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stats: Do not expand dots of tm_name #10316

Closed
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/output-json-stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,20 +265,29 @@ json_t *StatsToJSON(const StatsTable *st, uint8_t flags)
for (x = 0; x < st->ntstats; x++) {
uint32_t offset = x * st->nstats;

// Stats for for this thread.
json_t *thread = json_object();
if (unlikely(thread == NULL)) {
json_decref(js_stats);
json_decref(threads);
return NULL;
}

/* for each counter */
for (u = offset; u < (offset + st->nstats); u++) {
if (st->tstats[u].name == NULL)
continue;

// Seems this holds, but assert in debug builds.
assert(strcmp(st->tstats[u].tm_name, st->tstats[u].tm_name) == 0);
Copy link
Contributor Author

@awelzel awelzel Feb 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ewh, this was meant to be - let me know whether to open v2 with that and any more suggestions or it can be fixed during the merge. Thanks.

Suggested change
assert(strcmp(st->tstats[u].tm_name, st->tstats[u].tm_name) == 0);
assert(strcmp(st->tstats[offset].tm_name, st->tstats[u].tm_name) == 0);


json_t *js_type = NULL;
const char *stat_name = st->tstats[u].short_name;
if (st->tstats[u].short_name == NULL) {
stat_name = st->tstats[u].name;
js_type = threads;
} else {
char str[256];
snprintf(str, sizeof(str), "%s.%s", st->tstats[u].tm_name, st->tstats[u].name);
js_type = OutputStats2Json(threads, str);
js_type = OutputStats2Json(thread, st->tstats[u].name);
}

if (js_type != NULL) {
Expand All @@ -292,6 +301,7 @@ json_t *StatsToJSON(const StatsTable *st, uint8_t flags)
}
}
}
json_object_set_new(threads, st->tstats[offset].tm_name, thread);
}
json_object_set_new(js_stats, "threads", threads);
}
Expand Down