Skip to content

Commit 29b62a1

Browse files
author
Markus Armbruster
committed
trace: Move HMP commands from monitor/ to trace/
This moves these commands from MAINTAINERS sections "Human Monitor (HMP)" and "QMP" to "Tracing". Signed-off-by: Markus Armbruster <[email protected]> Message-Id: <[email protected]> Reviewed-by: Philippe Mathieu-Daudé <[email protected]> Reviewed-by: Stefan Hajnoczi <[email protected]>
1 parent 5ec92f2 commit 29b62a1

File tree

4 files changed

+152
-119
lines changed

4 files changed

+152
-119
lines changed

include/monitor/hmp.h

+3
Original file line numberDiff line numberDiff line change
@@ -155,5 +155,8 @@ void hmp_pcie_aer_inject_error(Monitor *mon, const QDict *qdict);
155155
void hmp_info_capture(Monitor *mon, const QDict *qdict);
156156
void hmp_stopcapture(Monitor *mon, const QDict *qdict);
157157
void hmp_wavcapture(Monitor *mon, const QDict *qdict);
158+
void hmp_trace_event(Monitor *mon, const QDict *qdict);
159+
void hmp_trace_file(Monitor *mon, const QDict *qdict);
160+
void hmp_info_trace_events(Monitor *mon, const QDict *qdict);
158161

159162
#endif

monitor/misc.c

-119
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,8 @@
3939
#include "qapi/qmp/qdict.h"
4040
#include "qapi/qmp/qerror.h"
4141
#include "qom/object_interfaces.h"
42-
#include "trace/control.h"
4342
#include "monitor/hmp-target.h"
4443
#include "monitor/hmp.h"
45-
#ifdef CONFIG_TRACE_SIMPLE
46-
#include "trace/simple.h"
47-
#endif
4844
#include "exec/address-spaces.h"
4945
#include "exec/ioport.h"
5046
#include "block/qapi.h"
@@ -54,7 +50,6 @@
5450
#include "qapi/qapi-commands-misc.h"
5551
#include "qapi/qapi-commands-qom.h"
5652
#include "qapi/qapi-commands-run-state.h"
57-
#include "qapi/qapi-commands-trace.h"
5853
#include "qapi/qapi-commands-machine.h"
5954
#include "qapi/qapi-init-commands.h"
6055
#include "qapi/error.h"
@@ -156,50 +151,6 @@ static void do_help_cmd(Monitor *mon, const QDict *qdict)
156151
hmp_help_cmd(mon, qdict_get_try_str(qdict, "name"));
157152
}
158153

159-
static void hmp_trace_event(Monitor *mon, const QDict *qdict)
160-
{
161-
const char *tp_name = qdict_get_str(qdict, "name");
162-
bool new_state = qdict_get_bool(qdict, "option");
163-
bool has_vcpu = qdict_haskey(qdict, "vcpu");
164-
int vcpu = qdict_get_try_int(qdict, "vcpu", 0);
165-
Error *local_err = NULL;
166-
167-
if (vcpu < 0) {
168-
monitor_printf(mon, "argument vcpu must be positive");
169-
return;
170-
}
171-
172-
qmp_trace_event_set_state(tp_name, new_state, true, true, has_vcpu, vcpu, &local_err);
173-
if (local_err) {
174-
error_report_err(local_err);
175-
}
176-
}
177-
178-
#ifdef CONFIG_TRACE_SIMPLE
179-
static void hmp_trace_file(Monitor *mon, const QDict *qdict)
180-
{
181-
const char *op = qdict_get_try_str(qdict, "op");
182-
const char *arg = qdict_get_try_str(qdict, "arg");
183-
184-
if (!op) {
185-
st_print_trace_file_status();
186-
} else if (!strcmp(op, "on")) {
187-
st_set_trace_file_enabled(true);
188-
} else if (!strcmp(op, "off")) {
189-
st_set_trace_file_enabled(false);
190-
} else if (!strcmp(op, "flush")) {
191-
st_flush_trace_buffer();
192-
} else if (!strcmp(op, "set")) {
193-
if (arg) {
194-
st_set_trace_file(arg);
195-
}
196-
} else {
197-
monitor_printf(mon, "unexpected argument \"%s\"\n", op);
198-
hmp_help_cmd(mon, "trace-file");
199-
}
200-
}
201-
#endif
202-
203154
static void hmp_info_help(Monitor *mon, const QDict *qdict)
204155
{
205156
hmp_help_cmd(mon, "info");
@@ -344,37 +295,6 @@ static void hmp_info_history(Monitor *mon, const QDict *qdict)
344295
}
345296
}
346297

347-
static void hmp_info_trace_events(Monitor *mon, const QDict *qdict)
348-
{
349-
const char *name = qdict_get_try_str(qdict, "name");
350-
bool has_vcpu = qdict_haskey(qdict, "vcpu");
351-
int vcpu = qdict_get_try_int(qdict, "vcpu", 0);
352-
TraceEventInfoList *events;
353-
TraceEventInfoList *elem;
354-
Error *local_err = NULL;
355-
356-
if (name == NULL) {
357-
name = "*";
358-
}
359-
if (vcpu < 0) {
360-
monitor_printf(mon, "argument vcpu must be positive");
361-
return;
362-
}
363-
364-
events = qmp_trace_event_get_state(name, has_vcpu, vcpu, &local_err);
365-
if (local_err) {
366-
error_report_err(local_err);
367-
return;
368-
}
369-
370-
for (elem = events; elem != NULL; elem = elem->next) {
371-
monitor_printf(mon, "%s : state %u\n",
372-
elem->value->name,
373-
elem->value->state == TRACE_EVENT_STATE_ENABLED ? 1 : 0);
374-
}
375-
qapi_free_TraceEventInfoList(events);
376-
}
377-
378298
void qmp_client_migrate_info(const char *protocol, const char *hostname,
379299
bool has_port, int64_t port,
380300
bool has_tls_port, int64_t tls_port,
@@ -1535,45 +1455,6 @@ void netdev_del_completion(ReadLineState *rs, int nb_args, const char *str)
15351455
}
15361456
}
15371457

1538-
void info_trace_events_completion(ReadLineState *rs, int nb_args, const char *str)
1539-
{
1540-
size_t len;
1541-
1542-
len = strlen(str);
1543-
readline_set_completion_index(rs, len);
1544-
if (nb_args == 2) {
1545-
TraceEventIter iter;
1546-
TraceEvent *ev;
1547-
char *pattern = g_strdup_printf("%s*", str);
1548-
trace_event_iter_init_pattern(&iter, pattern);
1549-
while ((ev = trace_event_iter_next(&iter)) != NULL) {
1550-
readline_add_completion(rs, trace_event_get_name(ev));
1551-
}
1552-
g_free(pattern);
1553-
}
1554-
}
1555-
1556-
void trace_event_completion(ReadLineState *rs, int nb_args, const char *str)
1557-
{
1558-
size_t len;
1559-
1560-
len = strlen(str);
1561-
readline_set_completion_index(rs, len);
1562-
if (nb_args == 2) {
1563-
TraceEventIter iter;
1564-
TraceEvent *ev;
1565-
char *pattern = g_strdup_printf("%s*", str);
1566-
trace_event_iter_init_pattern(&iter, pattern);
1567-
while ((ev = trace_event_iter_next(&iter)) != NULL) {
1568-
readline_add_completion(rs, trace_event_get_name(ev));
1569-
}
1570-
g_free(pattern);
1571-
} else if (nb_args == 3) {
1572-
readline_add_completion_of(rs, str, "on");
1573-
readline_add_completion_of(rs, str, "off");
1574-
}
1575-
}
1576-
15771458
void watchdog_action_completion(ReadLineState *rs, int nb_args, const char *str)
15781459
{
15791460
int i;

trace/meson.build

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
softmmu_ss.add(files('trace-hmp-cmds.c'))
12

23
specific_ss.add(files('control-target.c'))
34

trace/trace-hmp-cmds.c

+148
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
/*
2+
* HMP commands related to tracing
3+
*
4+
* Copyright (c) 2003-2004 Fabrice Bellard
5+
*
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:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
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
22+
* THE SOFTWARE.
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+
36+
void 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+
bool has_vcpu = qdict_haskey(qdict, "vcpu");
41+
int vcpu = qdict_get_try_int(qdict, "vcpu", 0);
42+
Error *local_err = NULL;
43+
44+
if (vcpu < 0) {
45+
monitor_printf(mon, "argument vcpu must be positive");
46+
return;
47+
}
48+
49+
qmp_trace_event_set_state(tp_name, new_state, true, true, has_vcpu, vcpu, &local_err);
50+
if (local_err) {
51+
error_report_err(local_err);
52+
}
53+
}
54+
55+
#ifdef CONFIG_TRACE_SIMPLE
56+
void hmp_trace_file(Monitor *mon, const QDict *qdict)
57+
{
58+
const char *op = qdict_get_try_str(qdict, "op");
59+
const char *arg = qdict_get_try_str(qdict, "arg");
60+
61+
if (!op) {
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")) {
70+
if (arg) {
71+
st_set_trace_file(arg);
72+
}
73+
} else {
74+
monitor_printf(mon, "unexpected argument \"%s\"\n", op);
75+
hmp_help_cmd(mon, "trace-file");
76+
}
77+
}
78+
#endif
79+
80+
void hmp_info_trace_events(Monitor *mon, const QDict *qdict)
81+
{
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;
88+
89+
if (name == NULL) {
90+
name = "*";
91+
}
92+
if (vcpu < 0) {
93+
monitor_printf(mon, "argument vcpu must be positive");
94+
return;
95+
}
96+
97+
events = qmp_trace_event_get_state(name, has_vcpu, vcpu, &local_err);
98+
if (local_err) {
99+
error_report_err(local_err);
100+
return;
101+
}
102+
103+
for (elem = events; elem != NULL; elem = elem->next) {
104+
monitor_printf(mon, "%s : state %u\n",
105+
elem->value->name,
106+
elem->value->state == TRACE_EVENT_STATE_ENABLED ? 1 : 0);
107+
}
108+
qapi_free_TraceEventInfoList(events);
109+
}
110+
111+
void info_trace_events_completion(ReadLineState *rs, int nb_args, const char *str)
112+
{
113+
size_t len;
114+
115+
len = strlen(str);
116+
readline_set_completion_index(rs, len);
117+
if (nb_args == 2) {
118+
TraceEventIter iter;
119+
TraceEvent *ev;
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));
124+
}
125+
g_free(pattern);
126+
}
127+
}
128+
129+
void trace_event_completion(ReadLineState *rs, int nb_args, const char *str)
130+
{
131+
size_t len;
132+
133+
len = strlen(str);
134+
readline_set_completion_index(rs, len);
135+
if (nb_args == 2) {
136+
TraceEventIter iter;
137+
TraceEvent *ev;
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));
142+
}
143+
g_free(pattern);
144+
} else if (nb_args == 3) {
145+
readline_add_completion_of(rs, str, "on");
146+
readline_add_completion_of(rs, str, "off");
147+
}
148+
}

0 commit comments

Comments
 (0)