2019-05-29 22:12:25 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2011-02-01 00:50:39 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2011, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com>
|
|
|
|
*
|
|
|
|
* Refactored from builtin-top.c, see that files for further copyright notes.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "cpumap.h"
|
|
|
|
#include "event.h"
|
|
|
|
#include "evlist.h"
|
|
|
|
#include "evsel.h"
|
|
|
|
#include "parse-events.h"
|
|
|
|
#include "symbol.h"
|
|
|
|
#include "top.h"
|
|
|
|
#include <inttypes.h>
|
|
|
|
|
2011-03-08 04:13:40 +08:00
|
|
|
#define SNPRINTF(buf, size, fmt, args...) \
|
|
|
|
({ \
|
|
|
|
size_t r = snprintf(buf, size, fmt, ## args); \
|
|
|
|
r > size ? size : r; \
|
|
|
|
})
|
|
|
|
|
2011-02-01 00:50:39 +08:00
|
|
|
size_t perf_top__header_snprintf(struct perf_top *top, char *bf, size_t size)
|
|
|
|
{
|
2013-05-14 10:09:00 +08:00
|
|
|
float samples_per_sec;
|
|
|
|
float ksamples_per_sec;
|
|
|
|
float esamples_percent;
|
2013-12-20 01:43:45 +08:00
|
|
|
struct record_opts *opts = &top->record_opts;
|
2013-11-13 03:46:16 +08:00
|
|
|
struct target *target = &opts->target;
|
2011-02-01 00:50:39 +08:00
|
|
|
size_t ret = 0;
|
|
|
|
|
2013-05-14 10:09:00 +08:00
|
|
|
if (top->samples) {
|
|
|
|
samples_per_sec = top->samples / top->delay_secs;
|
|
|
|
ksamples_per_sec = top->kernel_samples / top->delay_secs;
|
|
|
|
esamples_percent = (100.0 * top->exact_samples) / top->samples;
|
|
|
|
} else {
|
|
|
|
samples_per_sec = ksamples_per_sec = esamples_percent = 0.0;
|
|
|
|
}
|
|
|
|
|
2011-02-01 00:50:39 +08:00
|
|
|
if (!perf_guest) {
|
2013-05-14 10:09:00 +08:00
|
|
|
float ksamples_percent = 0.0;
|
|
|
|
|
|
|
|
if (samples_per_sec)
|
|
|
|
ksamples_percent = (100.0 * ksamples_per_sec) /
|
|
|
|
samples_per_sec;
|
2011-03-08 04:13:40 +08:00
|
|
|
ret = SNPRINTF(bf, size,
|
2011-02-01 00:50:39 +08:00
|
|
|
" PerfTop:%8.0f irqs/sec kernel:%4.1f%%"
|
2018-11-12 03:02:46 +08:00
|
|
|
" exact: %4.1f%% lost: %" PRIu64 "/%" PRIu64 " drop: %" PRIu64 "/%" PRIu64 " [",
|
|
|
|
samples_per_sec, ksamples_percent, esamples_percent,
|
|
|
|
top->lost, top->lost_total, top->drop, top->drop_total);
|
2011-02-01 00:50:39 +08:00
|
|
|
} else {
|
|
|
|
float us_samples_per_sec = top->us_samples / top->delay_secs;
|
|
|
|
float guest_kernel_samples_per_sec = top->guest_kernel_samples / top->delay_secs;
|
|
|
|
float guest_us_samples_per_sec = top->guest_us_samples / top->delay_secs;
|
|
|
|
|
2011-03-08 04:13:40 +08:00
|
|
|
ret = SNPRINTF(bf, size,
|
2011-02-01 00:50:39 +08:00
|
|
|
" PerfTop:%8.0f irqs/sec kernel:%4.1f%% us:%4.1f%%"
|
|
|
|
" guest kernel:%4.1f%% guest us:%4.1f%%"
|
|
|
|
" exact: %4.1f%% [", samples_per_sec,
|
|
|
|
100.0 - (100.0 * ((samples_per_sec - ksamples_per_sec) /
|
|
|
|
samples_per_sec)),
|
|
|
|
100.0 - (100.0 * ((samples_per_sec - us_samples_per_sec) /
|
|
|
|
samples_per_sec)),
|
|
|
|
100.0 - (100.0 * ((samples_per_sec -
|
|
|
|
guest_kernel_samples_per_sec) /
|
|
|
|
samples_per_sec)),
|
|
|
|
100.0 - (100.0 * ((samples_per_sec -
|
|
|
|
guest_us_samples_per_sec) /
|
|
|
|
samples_per_sec)),
|
|
|
|
esamples_percent);
|
|
|
|
}
|
|
|
|
|
2019-07-21 19:24:28 +08:00
|
|
|
if (top->evlist->core.nr_entries == 1) {
|
2019-07-21 19:23:51 +08:00
|
|
|
struct evsel *first = perf_evlist__first(top->evlist);
|
2011-03-08 04:13:40 +08:00
|
|
|
ret += SNPRINTF(bf + ret, size - ret, "%" PRIu64 "%s ",
|
2011-02-01 00:50:39 +08:00
|
|
|
(uint64_t)first->attr.sample_period,
|
2012-12-12 03:48:41 +08:00
|
|
|
opts->freq ? "Hz" : "");
|
2011-02-01 00:50:39 +08:00
|
|
|
}
|
|
|
|
|
2012-06-12 23:34:58 +08:00
|
|
|
ret += SNPRINTF(bf + ret, size - ret, "%s", perf_evsel__name(top->sym_evsel));
|
2011-02-01 00:50:39 +08:00
|
|
|
|
2011-03-08 04:13:40 +08:00
|
|
|
ret += SNPRINTF(bf + ret, size - ret, "], ");
|
2011-02-01 00:50:39 +08:00
|
|
|
|
2012-12-12 03:48:41 +08:00
|
|
|
if (target->pid)
|
2012-02-09 00:32:52 +08:00
|
|
|
ret += SNPRINTF(bf + ret, size - ret, " (target_pid: %s",
|
2012-12-12 03:48:41 +08:00
|
|
|
target->pid);
|
|
|
|
else if (target->tid)
|
2012-02-09 00:32:52 +08:00
|
|
|
ret += SNPRINTF(bf + ret, size - ret, " (target_tid: %s",
|
2012-12-12 03:48:41 +08:00
|
|
|
target->tid);
|
|
|
|
else if (target->uid_str != NULL)
|
2012-01-20 00:08:15 +08:00
|
|
|
ret += SNPRINTF(bf + ret, size - ret, " (uid: %s",
|
2012-12-12 03:48:41 +08:00
|
|
|
target->uid_str);
|
2011-02-01 00:50:39 +08:00
|
|
|
else
|
2011-03-08 04:13:40 +08:00
|
|
|
ret += SNPRINTF(bf + ret, size - ret, " (all");
|
2011-02-01 00:50:39 +08:00
|
|
|
|
2012-12-12 03:48:41 +08:00
|
|
|
if (target->cpu_list)
|
2011-03-08 04:13:40 +08:00
|
|
|
ret += SNPRINTF(bf + ret, size - ret, ", CPU%s: %s)",
|
2012-04-26 13:15:17 +08:00
|
|
|
top->evlist->cpus->nr > 1 ? "s" : "",
|
2012-12-12 03:48:41 +08:00
|
|
|
target->cpu_list);
|
2011-02-01 00:50:39 +08:00
|
|
|
else {
|
2012-12-12 03:48:41 +08:00
|
|
|
if (target->tid)
|
2011-03-08 04:13:40 +08:00
|
|
|
ret += SNPRINTF(bf + ret, size - ret, ")");
|
2011-02-01 00:50:39 +08:00
|
|
|
else
|
2011-03-08 04:13:40 +08:00
|
|
|
ret += SNPRINTF(bf + ret, size - ret, ", %d CPU%s)",
|
2011-02-01 00:50:39 +08:00
|
|
|
top->evlist->cpus->nr,
|
|
|
|
top->evlist->cpus->nr > 1 ? "s" : "");
|
|
|
|
}
|
|
|
|
|
2018-11-13 18:15:34 +08:00
|
|
|
perf_top__reset_sample_counters(top);
|
2011-02-01 00:50:39 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void perf_top__reset_sample_counters(struct perf_top *top)
|
|
|
|
{
|
|
|
|
top->samples = top->us_samples = top->kernel_samples =
|
|
|
|
top->exact_samples = top->guest_kernel_samples =
|
2018-11-12 03:02:46 +08:00
|
|
|
top->guest_us_samples = top->lost = top->drop = 0;
|
2011-02-01 00:50:39 +08:00
|
|
|
}
|