Skip to content

Commit 6a5fcf6

Browse files
author
Markus Armbruster
committed
stats: Move HMP commands from monitor/ to stats/
This moves these commands from MAINTAINERS section "Human Monitor (HMP)" to section "Stats". Signed-off-by: Markus Armbruster <[email protected]> Message-Id: <[email protected]>
1 parent aa09b3d commit 6a5fcf6

File tree

3 files changed

+248
-235
lines changed

3 files changed

+248
-235
lines changed

monitor/hmp-cmds.c

-234
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,9 @@
2020
#include "qapi/error.h"
2121
#include "qapi/qapi-commands-control.h"
2222
#include "qapi/qapi-commands-misc.h"
23-
#include "qapi/qapi-commands-stats.h"
2423
#include "qapi/qmp/qdict.h"
2524
#include "qapi/qmp/qerror.h"
2625
#include "qemu/cutils.h"
27-
#include "hw/core/cpu.h"
2826
#include "hw/intc/intc.h"
2927

3028
bool hmp_handle_error(Monitor *mon, Error *err)
@@ -226,235 +224,3 @@ void hmp_info_iothreads(Monitor *mon, const QDict *qdict)
226224

227225
qapi_free_IOThreadInfoList(info_list);
228226
}
229-
230-
static void print_stats_schema_value(Monitor *mon, StatsSchemaValue *value)
231-
{
232-
const char *unit = NULL;
233-
monitor_printf(mon, " %s (%s%s", value->name, StatsType_str(value->type),
234-
value->has_unit || value->exponent ? ", " : "");
235-
236-
if (value->has_unit) {
237-
if (value->unit == STATS_UNIT_SECONDS) {
238-
unit = "s";
239-
} else if (value->unit == STATS_UNIT_BYTES) {
240-
unit = "B";
241-
}
242-
}
243-
244-
if (unit && value->base == 10 &&
245-
value->exponent >= -18 && value->exponent <= 18 &&
246-
value->exponent % 3 == 0) {
247-
monitor_puts(mon, si_prefix(value->exponent));
248-
} else if (unit && value->base == 2 &&
249-
value->exponent >= 0 && value->exponent <= 60 &&
250-
value->exponent % 10 == 0) {
251-
252-
monitor_puts(mon, iec_binary_prefix(value->exponent));
253-
} else if (value->exponent) {
254-
/* Use exponential notation and write the unit's English name */
255-
monitor_printf(mon, "* %d^%d%s",
256-
value->base, value->exponent,
257-
value->has_unit ? " " : "");
258-
unit = NULL;
259-
}
260-
261-
if (value->has_unit) {
262-
monitor_puts(mon, unit ? unit : StatsUnit_str(value->unit));
263-
}
264-
265-
/* Print bucket size for linear histograms */
266-
if (value->type == STATS_TYPE_LINEAR_HISTOGRAM && value->has_bucket_size) {
267-
monitor_printf(mon, ", bucket size=%d", value->bucket_size);
268-
}
269-
monitor_printf(mon, ")");
270-
}
271-
272-
static StatsSchemaValueList *find_schema_value_list(
273-
StatsSchemaList *list, StatsProvider provider,
274-
StatsTarget target)
275-
{
276-
StatsSchemaList *node;
277-
278-
for (node = list; node; node = node->next) {
279-
if (node->value->provider == provider &&
280-
node->value->target == target) {
281-
return node->value->stats;
282-
}
283-
}
284-
return NULL;
285-
}
286-
287-
static void print_stats_results(Monitor *mon, StatsTarget target,
288-
bool show_provider,
289-
StatsResult *result,
290-
StatsSchemaList *schema)
291-
{
292-
/* Find provider schema */
293-
StatsSchemaValueList *schema_value_list =
294-
find_schema_value_list(schema, result->provider, target);
295-
StatsList *stats_list;
296-
297-
if (!schema_value_list) {
298-
monitor_printf(mon, "failed to find schema list for %s\n",
299-
StatsProvider_str(result->provider));
300-
return;
301-
}
302-
303-
if (show_provider) {
304-
monitor_printf(mon, "provider: %s\n",
305-
StatsProvider_str(result->provider));
306-
}
307-
308-
for (stats_list = result->stats; stats_list;
309-
stats_list = stats_list->next,
310-
schema_value_list = schema_value_list->next) {
311-
312-
Stats *stats = stats_list->value;
313-
StatsValue *stats_value = stats->value;
314-
StatsSchemaValue *schema_value = schema_value_list->value;
315-
316-
/* Find schema entry */
317-
while (!g_str_equal(stats->name, schema_value->name)) {
318-
if (!schema_value_list->next) {
319-
monitor_printf(mon, "failed to find schema entry for %s\n",
320-
stats->name);
321-
return;
322-
}
323-
schema_value_list = schema_value_list->next;
324-
schema_value = schema_value_list->value;
325-
}
326-
327-
print_stats_schema_value(mon, schema_value);
328-
329-
if (stats_value->type == QTYPE_QNUM) {
330-
monitor_printf(mon, ": %" PRId64 "\n", stats_value->u.scalar);
331-
} else if (stats_value->type == QTYPE_QBOOL) {
332-
monitor_printf(mon, ": %s\n", stats_value->u.boolean ? "yes" : "no");
333-
} else if (stats_value->type == QTYPE_QLIST) {
334-
uint64List *list;
335-
int i;
336-
337-
monitor_printf(mon, ": ");
338-
for (list = stats_value->u.list, i = 1;
339-
list;
340-
list = list->next, i++) {
341-
monitor_printf(mon, "[%d]=%" PRId64 " ", i, list->value);
342-
}
343-
monitor_printf(mon, "\n");
344-
}
345-
}
346-
}
347-
348-
/* Create the StatsFilter that is needed for an "info stats" invocation. */
349-
static StatsFilter *stats_filter(StatsTarget target, const char *names,
350-
int cpu_index, StatsProvider provider)
351-
{
352-
StatsFilter *filter = g_malloc0(sizeof(*filter));
353-
StatsProvider provider_idx;
354-
StatsRequestList *request_list = NULL;
355-
356-
filter->target = target;
357-
switch (target) {
358-
case STATS_TARGET_VM:
359-
break;
360-
case STATS_TARGET_VCPU:
361-
{
362-
strList *vcpu_list = NULL;
363-
CPUState *cpu = qemu_get_cpu(cpu_index);
364-
char *canonical_path = object_get_canonical_path(OBJECT(cpu));
365-
366-
QAPI_LIST_PREPEND(vcpu_list, canonical_path);
367-
filter->u.vcpu.has_vcpus = true;
368-
filter->u.vcpu.vcpus = vcpu_list;
369-
break;
370-
}
371-
default:
372-
break;
373-
}
374-
375-
if (!names && provider == STATS_PROVIDER__MAX) {
376-
return filter;
377-
}
378-
379-
/*
380-
* "info stats" can only query either one or all the providers. Querying
381-
* by name, but not by provider, requires the creation of one filter per
382-
* provider.
383-
*/
384-
for (provider_idx = 0; provider_idx < STATS_PROVIDER__MAX; provider_idx++) {
385-
if (provider == STATS_PROVIDER__MAX || provider == provider_idx) {
386-
StatsRequest *request = g_new0(StatsRequest, 1);
387-
request->provider = provider_idx;
388-
if (names && !g_str_equal(names, "*")) {
389-
request->has_names = true;
390-
request->names = hmp_split_at_comma(names);
391-
}
392-
QAPI_LIST_PREPEND(request_list, request);
393-
}
394-
}
395-
396-
filter->has_providers = true;
397-
filter->providers = request_list;
398-
return filter;
399-
}
400-
401-
void hmp_info_stats(Monitor *mon, const QDict *qdict)
402-
{
403-
const char *target_str = qdict_get_str(qdict, "target");
404-
const char *provider_str = qdict_get_try_str(qdict, "provider");
405-
const char *names = qdict_get_try_str(qdict, "names");
406-
407-
StatsProvider provider = STATS_PROVIDER__MAX;
408-
StatsTarget target;
409-
Error *err = NULL;
410-
g_autoptr(StatsSchemaList) schema = NULL;
411-
g_autoptr(StatsResultList) stats = NULL;
412-
g_autoptr(StatsFilter) filter = NULL;
413-
StatsResultList *entry;
414-
415-
target = qapi_enum_parse(&StatsTarget_lookup, target_str, -1, &err);
416-
if (err) {
417-
monitor_printf(mon, "invalid stats target %s\n", target_str);
418-
goto exit_no_print;
419-
}
420-
if (provider_str) {
421-
provider = qapi_enum_parse(&StatsProvider_lookup, provider_str, -1, &err);
422-
if (err) {
423-
monitor_printf(mon, "invalid stats provider %s\n", provider_str);
424-
goto exit_no_print;
425-
}
426-
}
427-
428-
schema = qmp_query_stats_schemas(provider_str ? true : false,
429-
provider, &err);
430-
if (err) {
431-
goto exit;
432-
}
433-
434-
switch (target) {
435-
case STATS_TARGET_VM:
436-
filter = stats_filter(target, names, -1, provider);
437-
break;
438-
case STATS_TARGET_VCPU: {}
439-
int cpu_index = monitor_get_cpu_index(mon);
440-
filter = stats_filter(target, names, cpu_index, provider);
441-
break;
442-
default:
443-
abort();
444-
}
445-
446-
stats = qmp_query_stats(filter, &err);
447-
if (err) {
448-
goto exit;
449-
}
450-
for (entry = stats; entry; entry = entry->next) {
451-
print_stats_results(mon, target, provider_str == NULL, entry->value, schema);
452-
}
453-
454-
exit:
455-
if (err) {
456-
monitor_printf(mon, "%s\n", error_get_pretty(err));
457-
}
458-
exit_no_print:
459-
error_free(err);
460-
}

stats/meson.build

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
softmmu_ss.add(files('stats-qmp-cmds.c'))
1+
softmmu_ss.add(files('stats-hmp-cmds.c', 'stats-qmp-cmds.c'))

0 commit comments

Comments
 (0)