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#include "qemu/osdep.h"
26#include "monitor/hmp.h"
27#include "monitor/monitor.h"
28#include "qapi/error.h"
29#include "qapi/qapi-commands-trace.h"
30#include "qapi/qmp/qdict.h"
31#include "trace/control.h"
32#ifdef CONFIG_TRACE_SIMPLE
33#include "trace/simple.h"
34#endif
35
36void hmp_trace_event(Monitor *mon, const QDict *qdict)
37{
38 const char *tp_name = qdict_get_str(qdict, "name");
39 bool new_state = qdict_get_bool(qdict, "option");
40 Error *local_err = NULL;
41
42 qmp_trace_event_set_state(tp_name, new_state,
43 true, true, false, 0, &local_err);
44 if (local_err) {
45 error_report_err(local_err);
46 }
47}
48
49#ifdef CONFIG_TRACE_SIMPLE
50void hmp_trace_file(Monitor *mon, const QDict *qdict)
51{
52 const char *op = qdict_get_try_str(qdict, "op");
53 const char *arg = qdict_get_try_str(qdict, "arg");
54
55 if (!op) {
56 st_print_trace_file_status();
57 } else if (!strcmp(op, "on")) {
58 st_set_trace_file_enabled(true);
59 } else if (!strcmp(op, "off")) {
60 st_set_trace_file_enabled(false);
61 } else if (!strcmp(op, "flush")) {
62 st_flush_trace_buffer();
63 } else if (!strcmp(op, "set")) {
64 if (arg) {
65 st_set_trace_file(arg);
66 }
67 } else {
68 monitor_printf(mon, "unexpected argument \"%s\"\n", op);
69 hmp_help_cmd(mon, "trace-file");
70 }
71}
72#endif
73
74void hmp_info_trace_events(Monitor *mon, const QDict *qdict)
75{
76 const char *name = qdict_get_try_str(qdict, "name");
77 TraceEventInfoList *events;
78 TraceEventInfoList *elem;
79 Error *local_err = NULL;
80
81 if (name == NULL) {
82 name = "*";
83 }
84
85 events = qmp_trace_event_get_state(name, false, 0, &local_err);
86 if (local_err) {
87 error_report_err(local_err);
88 return;
89 }
90
91 for (elem = events; elem != NULL; elem = elem->next) {
92 monitor_printf(mon, "%s : state %u\n",
93 elem->value->name,
94 elem->value->state == TRACE_EVENT_STATE_ENABLED ? 1 : 0);
95 }
96 qapi_free_TraceEventInfoList(events);
97}
98
99void info_trace_events_completion(ReadLineState *rs, int nb_args, const char *str)
100{
101 size_t len;
102
103 len = strlen(str);
104 readline_set_completion_index(rs, len);
105 if (nb_args == 2) {
106 TraceEventIter iter;
107 TraceEvent *ev;
108 char *pattern = g_strdup_printf("%s*", str);
109 trace_event_iter_init_pattern(&iter, pattern);
110 while ((ev = trace_event_iter_next(&iter)) != NULL) {
111 readline_add_completion(rs, trace_event_get_name(ev));
112 }
113 g_free(pattern);
114 }
115}
116
117void trace_event_completion(ReadLineState *rs, int nb_args, const char *str)
118{
119 size_t len;
120
121 len = strlen(str);
122 readline_set_completion_index(rs, len);
123 if (nb_args == 2) {
124 TraceEventIter iter;
125 TraceEvent *ev;
126 char *pattern = g_strdup_printf("%s*", str);
127 trace_event_iter_init_pattern(&iter, pattern);
128 while ((ev = trace_event_iter_next(&iter)) != NULL) {
129 readline_add_completion(rs, trace_event_get_name(ev));
130 }
131 g_free(pattern);
132 } else if (nb_args == 3) {
133 readline_add_completion_of(rs, str, "on");
134 readline_add_completion_of(rs, str, "off");
135 }
136}
137