[英]What is the default behavior of perf record?
我很清楚perf
總是記錄一個或多個事件,並且采樣可以是基於計數器或基於時間的。 但是當沒有給出-e
和-F
開關時, perf record
的默認行為是什么? perf-record
的手冊頁沒有告訴您它在這種情況下的作用。
性能perf record
中的默認事件選擇是在用戶空間性能工具中完成的,該工具通常作為 linux kernel 的一部分分發。 With make perf-src-tar-gz
from linux kernel source dir we can make tar gz for quick rebuild or download such tar from https://mirrors.edge.kernel.org/pub/linux/kernel/tools/perf . linux kernel 源代碼也有幾個在線“LXR”交叉參考查看器,可以像 grep 一樣使用來了解性能內部結構。
性能記錄有 function 到 select 默認事件列表(evlist): __perf_evlist__add_default
of tools/perf/util/evlist.Z4A8A08F09D37B73795364903B 文件:
int __perf_evlist__add_default(struct evlist *evlist, bool precise)
{
struct evsel *evsel = perf_evsel__new_cycles(precise);
evlist__add(evlist, evsel);
return 0;
}
如果從選項解析的事件為零,則從 perf 記錄實現調用: tools/perf/builtin-record.c: int cmd_record()
rec->evlist->core.nr_entries == 0 &&
__perf_evlist__add_default(rec->evlist, !record.opts.no_samples)
並且perf_evsel__new_cycles
將詢問硬件事件周期(PERF_TYPE_HARDWARE + PERF_COUNT_HW_CPU_CYCLES),可選 kernel 采樣和最大精確度( 檢查 man perf-list 中的修飾符,它是使用 PEBS 或 IBS 的 EIP 采樣防滑解決方法):
struct evsel *perf_evsel__new_cycles(bool precise)
{
struct perf_event_attr attr = {
.type = PERF_TYPE_HARDWARE,
.config = PERF_COUNT_HW_CPU_CYCLES,
.exclude_kernel = !perf_event_can_profile_kernel(),
};
struct evsel *evsel;
/*
* Now let the usual logic to set up the perf_event_attr defaults
* to kick in when we return and before perf_evsel__open() is called.
*/
evsel = evsel__new(&attr);
evsel->precise_max = true;
/* use asprintf() because free(evsel) assumes name is allocated */
if (asprintf(&evsel->name, "cycles%s%s%.*s",
(attr.precise_ip || attr.exclude_kernel) ? ":" : "",
attr.exclude_kernel ? "u" : "",
attr.precise_ip ? attr.precise_ip + 1 : 0, "ppp") < 0)
return evsel;
}
如果 perf_event_open 失敗(無法訪問硬件周期采樣,例如在沒有虛擬化 PMU 的虛擬化環境中),則在tools/perf/builtin-record.c: int record__open()
中故障回復到軟件 cpu 時鍾采樣perf_evsel__fallback()
工具/perf/util/evsel.c :
bool perf_evsel__fallback(struct evsel *evsel, int err,
char *msg, size_t msgsize)
{
if ((err == ENOENT || err == ENXIO || err == ENODEV) &&
evsel->core.attr.type == PERF_TYPE_HARDWARE &&
evsel->core.attr.config == PERF_COUNT_HW_CPU_CYCLES) {
/*
* If it's cycles then fall back to hrtimer based
* cpu-clock-tick sw counter, which is always available even if
* no PMU support.
*/
scnprintf(msg, msgsize, "%s", "The cycles event is not supported, trying to fall back to cpu-clock-ticks");
evsel->core.attr.type = PERF_TYPE_SOFTWARE;
evsel->core.attr.config = PERF_COUNT_SW_CPU_CLOCK;
return true;
} ...
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.