Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the use of perf in linux

2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly shows you "what is the use of perf in linux", the content is simple and clear, hoping to help you solve your doubts, the following let the editor lead you to study and learn "what is the use of perf in linux" this article.

Perf is a performance analysis tool provided in linux system. It is based on a kernel subsystem called "Performance counters". It supports both hardware (CPU, PMU (Performance Monitoring Unit)) and software (software counter, tracepoint) performance analysis.

Events in perf

Perf, like other performance tuning tools, samples the monitoring objects and infers the behavior of the whole program according to the distribution of sampling points. From the perf list command, we can see that perf supports many sampling events, such as branch-misses, cpu-clock, and so on. The predefined events in perf belong to different types, such as hardware-generated events (cache hit / branch miss) and software-generated events (context switch/page fault).

Tracepoint

Tracepoint are some of the hook defined in the linux kernel. If enabled, they will be triggered when specific logic is executed, making it convenient for other tools to obtain information such as the running status of the system. Perf uses tracepoint to record and count various events of tracepoint and generate analysis reports.

Mode of use

The specific usage of the perf tool is as follows:

Perf [--version] [--help] COMMAND [ARGS]

The COMMAND list can be viewed by executing perf-- help. Here are a few commonly used command.

Perf stat

The role of perf stat is to execute a command and collect data during its operation. It can provide an overall overview of how the program is running. For example:

User@localhost:~$ perf stat hostnamelocalhost Performance counter stats for 'hostname': 0.313464 task-clock (msec) # 0.481 CPUs utilized 2 context-switches # 0.006 M/sec 0 cpu-migrations # 0.000 K/sec 153 page-faults # 0.488 M/sec 896723 cycles # 2.861 GHz 620709 instructions # 0.69 insn per cycle 121143 branches # 386.465 M/sec 6247 branch-misses # 5.16% of all branches 0.000651441 seconds time elapsed

In the above example, the hostname command is run through perf stat, and some metrics during its operation are summarized, such as task-clock, context-switches and so on. By default, perf stat outputs statistics for several commonly used events, such as:

Task-clock-msecs:cpu usage context-switches: number of process switches page-faults: number of page faults cpu-migrations: indicates how many CPU migrations occurred during the process running, that is, the scheduler transferred from one CPU to another CPU to run cycles: processor clock, a machine instruction may require multiple cyclesinstructions: number of machine instructions branches: number of branch instructions encountered branch-misses is the number of branch instructions that predict the error

In addition, we can use the-e parameter to specify the events we are interested in, such as:

User@localhost:~$ perf stat-e cache-misses hostnamelocalhost Performance counter stats for 'hostname': 682 cache-misses 0.000646676 seconds time elapsed

Perf top

The function of perf top is to display the current performance statistics of the system in real time. The previous perf stat is used to analyze a particular program, and sometimes we may not know which program is affecting system performance, so we can use perf top to find suspicious programs. For example:

Samples: 775 of event 'cpu-clock', Event count (approx.): 92931021Overhead Shared Object Symbol 8.93% [kernel] [k] vsnprintf 7.73% perf [.] Rb_next 5.92% [kernel] [k] kallsyms_expand_symbol.clone.0 5.07% [kernel] [k] format_decode 4.59% [kernel] [k] number 3.40% perf [.] Symbols__insert 3.03% libslang.so.2.2.1 [.] SLtt_smart_puts

The above example shows that perf counts the data for cpu-clock events and sorts them proportionally. Like perf stat, we can use the-e parameter to specify the statistics of other events, such as perf top-e context-switches to view the top N processes with the most process switches.

Perf record & perf report

Perf record is similar to perf stat in that it runs a command and generates statistics, but instead of displaying the results, perf record outputs the results to a file. The files generated by perf record can be parsed with perf report.

Perf record can also generate calling graph during analysis with the-g parameter to help locate the logical distribution of the upper layers.

Other

Through the example, we can find that the Symbol column in the analysis result of perf shows the name of the function in c language. For java, the functions generated by jit compilation will be directly displayed in symbol instead of the function name of java, so it is not so easy to locate the problem. We need to use additional means to correspond the symbol tables of symbol and java programs, which will be discussed later.

The above is all the content of this article "what is the use of perf in linux?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report