[Performance Optimization Tool] Take you to understand Linux perf

This section mainly makes a brief introduction to Linux perf, from the perspective of what it is, what it can be used for, and the perspective of using it, as a wedge for the initial recognition of Linux perf.

@author: Mercury_Lc

Linux perf (performance profiler) is a powerful performance analysis tool used to help developers diagnose, tune and monitor performance problems of Linux systems and applications . It implements a variety of data collection methods based on hardware performance counters (hardware performance counters), trace points, and software measurements to analyze various phenomena in the system. The perf tool is integrated in the Linux kernel, mainly through the perf_event subsystem.

Performance counters are CPU hardware registers that count hardware events, such as instructions executed, cache misses, or mispredicted branches. They form the basis for analyzing applications to track dynamic control flow and identify hot spots. perf provides a rich general-purpose abstraction over hardware-specific functions.

In general, perf can analyze system performance at different levels, including resources such as CPU, memory, I/O, and locks. You can use perf for various tasks such as profiling applications, viewing hardware events (such as cache misses, branch mispredictions, etc.) and system calls, tracing kernel and user space events, and generating performance reports, etc.

perf provides a variety of sub-commands to meet different performance analysis needs, such as:

● perf stat: collect and display performance counter statistics during running.

● perf record: records event sample information.

● perf report: generate a performance report based on the data recorded in perf record.

● perf annotate: Annotate and analyze binary files.

● perf top: Real-time display of system activity and its performance counter data.

● perf trace: collect, parse, display or process trace performance data of kernel and user space.

● perf bench: run various built-in benchmarks.

The above can be obtained through perf -h after installing perf:

[root ~]# perf -h

 usage: perf [--version] [--help] [OPTIONS] COMMAND [ARGS]

 The most commonly used perf commands are:
   annotate        Read perf.data (created by perf record) and display annotated code
   archive         Create archive with object files with build-ids found in perf.data file
   bench           General framework for benchmark suites
   buildid-cache   Manage build-id cache.
   buildid-list    List the buildids in a perf.data file
   c2c             Shared Data C2C/HITM Analyzer.
   config          Get and set variables in a configuration file.
   data            Data file related processing
   diff            Read perf.data files and display the differential profile
   evlist          List the event names in a perf.data file
   ftrace          simple wrapper for kernel's ftrace functionality
   inject          Filter to augment the events stream with additional information
   kallsyms        Searches running kernel for symbols
   kmem            Tool to trace/measure kernel memory properties
   kvm             Tool to trace/measure kvm guest os
   list            List all symbolic event types
   lock            Analyze lock events
   mem             Profile memory accesses
   record          Run a command and record its profile into perf.data
   report          Read perf.data (created by perf record) and display the profile
   sched           Tool to trace/measure scheduler properties (latencies)
   script          Read perf.data (created by perf record) and display trace output
   stat            Run a command and gather performance counter statistics
   test            Runs sanity tests.
   timechart       Tool to visualize total system behavior during a workload
   top             System profiling tool.
   version         display the version of perf binary
   probe           Define new dynamic tracepoints
   trace           strace inspired tool

 See 'perf help COMMAND' for more information on a specific command.

It should be noted that before using perf, you should ensure that the system kernel supports the perf_event subsystem. When using the perf command, you usually need to have root authority or belong to a specific user group (such as: perf-users).

In short, Linux perf is a powerful performance analysis tool that can help developers locate performance problems, optimize system performance, and improve the operating efficiency of the system and applications.

Ref

https://perf.wiki.kernel.org/index.php/Main_Page

Guess you like

Origin blog.csdn.net/Mercury_Lc/article/details/131341695