trace: iter init tweaks

Rename trace_event_iter_init() to trace_event_iter_init_pattern(),
add trace_event_iter_init_all() for interating over all events.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Message-id: 20210601132414.432430-3-kraxel@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
Gerd Hoffmann 2021-06-01 15:24:03 +02:00 committed by Stefan Hajnoczi
parent 2adf216491
commit 117856c374
6 changed files with 31 additions and 16 deletions

View File

@ -1804,7 +1804,7 @@ void info_trace_events_completion(ReadLineState *rs, int nb_args, const char *st
TraceEventIter iter; TraceEventIter iter;
TraceEvent *ev; TraceEvent *ev;
char *pattern = g_strdup_printf("%s*", str); char *pattern = g_strdup_printf("%s*", str);
trace_event_iter_init(&iter, pattern); trace_event_iter_init_pattern(&iter, pattern);
while ((ev = trace_event_iter_next(&iter)) != NULL) { while ((ev = trace_event_iter_next(&iter)) != NULL) {
readline_add_completion(rs, trace_event_get_name(ev)); readline_add_completion(rs, trace_event_get_name(ev));
} }
@ -1822,7 +1822,7 @@ void trace_event_completion(ReadLineState *rs, int nb_args, const char *str)
TraceEventIter iter; TraceEventIter iter;
TraceEvent *ev; TraceEvent *ev;
char *pattern = g_strdup_printf("%s*", str); char *pattern = g_strdup_printf("%s*", str);
trace_event_iter_init(&iter, pattern); trace_event_iter_init_pattern(&iter, pattern);
while ((ev = trace_event_iter_next(&iter)) != NULL) { while ((ev = trace_event_iter_next(&iter)) != NULL) {
readline_add_completion(rs, trace_event_get_name(ev)); readline_add_completion(rs, trace_event_get_name(ev));
} }

View File

@ -127,7 +127,7 @@ void trace_init_vcpu(CPUState *vcpu)
{ {
TraceEventIter iter; TraceEventIter iter;
TraceEvent *ev; TraceEvent *ev;
trace_event_iter_init(&iter, NULL); trace_event_iter_init_all(&iter);
while ((ev = trace_event_iter_next(&iter)) != NULL) { while ((ev = trace_event_iter_next(&iter)) != NULL) {
if (trace_event_is_vcpu(ev) && if (trace_event_is_vcpu(ev) &&
trace_event_get_state_static(ev) && trace_event_get_state_static(ev) &&

View File

@ -91,7 +91,7 @@ TraceEvent *trace_event_name(const char *name)
TraceEventIter iter; TraceEventIter iter;
TraceEvent *ev; TraceEvent *ev;
trace_event_iter_init(&iter, NULL); trace_event_iter_init_all(&iter);
while ((ev = trace_event_iter_next(&iter)) != NULL) { while ((ev = trace_event_iter_next(&iter)) != NULL) {
if (strcmp(trace_event_get_name(ev), name) == 0) { if (strcmp(trace_event_get_name(ev), name) == 0) {
return ev; return ev;
@ -100,10 +100,16 @@ TraceEvent *trace_event_name(const char *name)
return NULL; return NULL;
} }
void trace_event_iter_init(TraceEventIter *iter, const char *pattern) void trace_event_iter_init_all(TraceEventIter *iter)
{ {
iter->event = 0; iter->event = 0;
iter->group = 0; iter->group = 0;
iter->pattern = NULL;
}
void trace_event_iter_init_pattern(TraceEventIter *iter, const char *pattern)
{
trace_event_iter_init_all(iter);
iter->pattern = pattern; iter->pattern = pattern;
} }
@ -130,7 +136,7 @@ void trace_list_events(FILE *f)
{ {
TraceEventIter iter; TraceEventIter iter;
TraceEvent *ev; TraceEvent *ev;
trace_event_iter_init(&iter, NULL); trace_event_iter_init_all(&iter);
while ((ev = trace_event_iter_next(&iter)) != NULL) { while ((ev = trace_event_iter_next(&iter)) != NULL) {
fprintf(f, "%s\n", trace_event_get_name(ev)); fprintf(f, "%s\n", trace_event_get_name(ev));
} }
@ -150,7 +156,7 @@ static void do_trace_enable_events(const char *line_buf)
TraceEvent *ev; TraceEvent *ev;
bool is_pattern = trace_event_is_pattern(line_ptr); bool is_pattern = trace_event_is_pattern(line_ptr);
trace_event_iter_init(&iter, line_ptr); trace_event_iter_init_pattern(&iter, line_ptr);
while ((ev = trace_event_iter_next(&iter)) != NULL) { while ((ev = trace_event_iter_next(&iter)) != NULL) {
if (!trace_event_get_state_static(ev)) { if (!trace_event_get_state_static(ev)) {
if (!is_pattern) { if (!is_pattern) {
@ -256,7 +262,7 @@ void trace_fini_vcpu(CPUState *vcpu)
trace_guest_cpu_exit(vcpu); trace_guest_cpu_exit(vcpu);
trace_event_iter_init(&iter, NULL); trace_event_iter_init_all(&iter);
while ((ev = trace_event_iter_next(&iter)) != NULL) { while ((ev = trace_event_iter_next(&iter)) != NULL) {
if (trace_event_is_vcpu(ev) && if (trace_event_is_vcpu(ev) &&
trace_event_get_state_static(ev) && trace_event_get_state_static(ev) &&

View File

@ -20,15 +20,24 @@ typedef struct TraceEventIter {
/** /**
* trace_event_iter_init: * trace_event_iter_init_all:
* @iter: the event iterator struct * @iter: the event iterator struct
* @pattern: optional pattern to filter events on name
* *
* Initialize the event iterator struct @iter, * Initialize the event iterator struct @iter,
* optionally using @pattern to filter out events * for all events.
*/
void trace_event_iter_init_all(TraceEventIter *iter);
/**
* trace_event_iter_init_pattern:
* @iter: the event iterator struct
* @pattern: pattern to filter events on name
*
* Initialize the event iterator struct @iter,
* using @pattern to filter out events
* with non-matching names. * with non-matching names.
*/ */
void trace_event_iter_init(TraceEventIter *iter, const char *pattern); void trace_event_iter_init_pattern(TraceEventIter *iter, const char *pattern);
/** /**
* trace_event_iter_next: * trace_event_iter_next:

View File

@ -55,7 +55,7 @@ static bool check_events(bool has_vcpu, bool ignore_unavailable, bool is_pattern
/* error for unavailable events */ /* error for unavailable events */
TraceEventIter iter; TraceEventIter iter;
TraceEvent *ev; TraceEvent *ev;
trace_event_iter_init(&iter, name); trace_event_iter_init_pattern(&iter, name);
while ((ev = trace_event_iter_next(&iter)) != NULL) { while ((ev = trace_event_iter_next(&iter)) != NULL) {
if (!ignore_unavailable && !trace_event_get_state_static(ev)) { if (!ignore_unavailable && !trace_event_get_state_static(ev)) {
error_setg(errp, "event \"%s\" is disabled", trace_event_get_name(ev)); error_setg(errp, "event \"%s\" is disabled", trace_event_get_name(ev));
@ -90,7 +90,7 @@ TraceEventInfoList *qmp_trace_event_get_state(const char *name,
} }
/* Get states (all errors checked above) */ /* Get states (all errors checked above) */
trace_event_iter_init(&iter, name); trace_event_iter_init_pattern(&iter, name);
while ((ev = trace_event_iter_next(&iter)) != NULL) { while ((ev = trace_event_iter_next(&iter)) != NULL) {
TraceEventInfo *value; TraceEventInfo *value;
bool is_vcpu = trace_event_is_vcpu(ev); bool is_vcpu = trace_event_is_vcpu(ev);
@ -153,7 +153,7 @@ void qmp_trace_event_set_state(const char *name, bool enable,
} }
/* Apply changes (all errors checked above) */ /* Apply changes (all errors checked above) */
trace_event_iter_init(&iter, name); trace_event_iter_init_pattern(&iter, name);
while ((ev = trace_event_iter_next(&iter)) != NULL) { while ((ev = trace_event_iter_next(&iter)) != NULL) {
if (!trace_event_get_state_static(ev) || if (!trace_event_get_state_static(ev) ||
(has_vcpu && !trace_event_is_vcpu(ev))) { (has_vcpu && !trace_event_is_vcpu(ev))) {

View File

@ -286,7 +286,7 @@ static int st_write_event_mapping(void)
TraceEventIter iter; TraceEventIter iter;
TraceEvent *ev; TraceEvent *ev;
trace_event_iter_init(&iter, NULL); trace_event_iter_init_all(&iter);
while ((ev = trace_event_iter_next(&iter)) != NULL) { while ((ev = trace_event_iter_next(&iter)) != NULL) {
uint64_t id = trace_event_get_id(ev); uint64_t id = trace_event_get_id(ev);
const char *name = trace_event_get_name(ev); const char *name = trace_event_get_name(ev);