2 * HMP commands related to tracing
4 * Copyright (c) 2003-2004 Fabrice Bellard
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
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"
36 void hmp_trace_event(Monitor
*mon
, const QDict
*qdict
)
38 const char *tp_name
= qdict_get_str(qdict
, "name");
39 bool new_state
= qdict_get_bool(qdict
, "option");
40 bool has_vcpu
= qdict_haskey(qdict
, "vcpu");
41 int vcpu
= qdict_get_try_int(qdict
, "vcpu", 0);
42 Error
*local_err
= NULL
;
45 monitor_printf(mon
, "argument vcpu must be positive");
49 qmp_trace_event_set_state(tp_name
, new_state
, true, true, has_vcpu
, vcpu
, &local_err
);
51 error_report_err(local_err
);
55 #ifdef CONFIG_TRACE_SIMPLE
56 void hmp_trace_file(Monitor
*mon
, const QDict
*qdict
)
58 const char *op
= qdict_get_try_str(qdict
, "op");
59 const char *arg
= qdict_get_try_str(qdict
, "arg");
62 st_print_trace_file_status();
63 } else if (!strcmp(op
, "on")) {
64 st_set_trace_file_enabled(true);
65 } else if (!strcmp(op
, "off")) {
66 st_set_trace_file_enabled(false);
67 } else if (!strcmp(op
, "flush")) {
68 st_flush_trace_buffer();
69 } else if (!strcmp(op
, "set")) {
71 st_set_trace_file(arg
);
74 monitor_printf(mon
, "unexpected argument \"%s\"\n", op
);
75 hmp_help_cmd(mon
, "trace-file");
80 void hmp_info_trace_events(Monitor
*mon
, const QDict
*qdict
)
82 const char *name
= qdict_get_try_str(qdict
, "name");
83 bool has_vcpu
= qdict_haskey(qdict
, "vcpu");
84 int vcpu
= qdict_get_try_int(qdict
, "vcpu", 0);
85 TraceEventInfoList
*events
;
86 TraceEventInfoList
*elem
;
87 Error
*local_err
= NULL
;
93 monitor_printf(mon
, "argument vcpu must be positive");
97 events
= qmp_trace_event_get_state(name
, has_vcpu
, vcpu
, &local_err
);
99 error_report_err(local_err
);
103 for (elem
= events
; elem
!= NULL
; elem
= elem
->next
) {
104 monitor_printf(mon
, "%s : state %u\n",
106 elem
->value
->state
== TRACE_EVENT_STATE_ENABLED
? 1 : 0);
108 qapi_free_TraceEventInfoList(events
);
111 void info_trace_events_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
116 readline_set_completion_index(rs
, len
);
120 char *pattern
= g_strdup_printf("%s*", str
);
121 trace_event_iter_init_pattern(&iter
, pattern
);
122 while ((ev
= trace_event_iter_next(&iter
)) != NULL
) {
123 readline_add_completion(rs
, trace_event_get_name(ev
));
129 void trace_event_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
134 readline_set_completion_index(rs
, len
);
138 char *pattern
= g_strdup_printf("%s*", str
);
139 trace_event_iter_init_pattern(&iter
, pattern
);
140 while ((ev
= trace_event_iter_next(&iter
)) != NULL
) {
141 readline_add_completion(rs
, trace_event_get_name(ev
));
144 } else if (nb_args
== 3) {
145 readline_add_completion_of(rs
, str
, "on");
146 readline_add_completion_of(rs
, str
, "off");