Ce contenu n'est pas disponible dans la langue sélectionnée.
5.4.2. Using Perf
Using the basic PCL infrastructure for collecting statistics or samples of program execution is relatively straightforward. This section provides simple examples of overall statistics and sampling.
To collect statistics on make and its children, use the following command:
perf stat -- make all
# perf stat -- make all
Copy to ClipboardCopied!Toggle word wrapToggle overflow
The perf command collects a number of different hardware and software counters. It then prints the following information:
Copy to ClipboardCopied!Toggle word wrapToggle overflow
The perf tool can also record samples. For example, to record data on the make command and its children, use:
perf record -- make all
# perf record -- make all
Copy to ClipboardCopied!Toggle word wrapToggle overflow
This prints out the file in which the samples are stored, along with the number of samples collected:
[ perf record: Woken up 42 times to write data ]
[ perf record: Captured and wrote 9.753 MB perf.data (~426109 samples) ]
[ perf record: Woken up 42 times to write data ]
[ perf record: Captured and wrote 9.753 MB perf.data (~426109 samples) ]
Copy to ClipboardCopied!Toggle word wrapToggle overflow
As of Red Hat Enterprise Linux 6.4, a new functionality to the {} group syntax has been added that allows the creation of event groups based on the way they are specified on the command line.
The current --group or -g options remain the same; if it is specified for record, stat, or top command, all the specified events become members of a single group with the first event as a group leader.
The new {} group syntax allows the creation of a group like:
perf record -e '{cycles, faults}' ls
# perf record -e '{cycles, faults}' ls# perf record -e '{cycles, faults}' ls# perf record -e '{cycles, faults}' ls
Copy to ClipboardCopied!Toggle word wrapToggle overflow
The above results in a single event group containing cycles and faults events, with the cycles event as the group leader.
All groups are created with regards to threads and CPUs. As such, recording an event group within two threads on a server with four CPUs will create eight separate groups.
It is possible to use a standard event modifier for a group. This spans over all events in the group and updates each event modifier settings.
perf record -r '{faults:k,cache-references}:p'
# perf record -r '{faults:k,cache-references}:p'# perf record -r '{faults:k,cache-references}:p'# perf record -r '{faults:k,cache-references}:p'
Copy to ClipboardCopied!Toggle word wrapToggle overflow
The above command results in the :kp modifier being used for faults, and the :p modifier being used for the cache-references event.
Performance Counters for Linux (PCL) Tools conflict with OProfile
Both OProfile and Performance Counters for Linux (PCL) use the same hardware Performance Monitoring Unit (PMU). If OProfile is currently running while attempting to use the PCL perf command, an error message like the following occurs when starting OProfile:
Error: open_counter returned with 16 (Device or resource busy). /bin/dmesg may provide additional information.
Fatal: Not all events could be opened.
Error: open_counter returned with 16 (Device or resource busy). /bin/dmesg may provide additional information.
Fatal: Not all events could be opened.
Copy to ClipboardCopied!Toggle word wrapToggle overflow
To use the perf command, first shut down OProfile:
opcontrol --deinit
# opcontrol --deinit
Copy to ClipboardCopied!Toggle word wrapToggle overflow
You can then analyze perf.data to determine the relative frequency of samples. The report output includes the command, object, and function for the samples. Use perf report to output an analysis of perf.data. For example, the following command produces a report of the executable that consumes the most time:
perf report --sort=comm
# perf report --sort=comm
Copy to ClipboardCopied!Toggle word wrapToggle overflow
Copy to ClipboardCopied!Toggle word wrapToggle overflow
The column on the left shows the relative frequency of the samples. This output shows that make spends most of this time in xsltproc and the pdfxmltex. To reduce the time for the make to complete, focus on xsltproc and pdfxmltex. To list the functions executed by xsltproc, run:
perf report -n --comm=xsltproc
# perf report -n --comm=xsltproc
Copy to ClipboardCopied!Toggle word wrapToggle overflow
Nous aidons les utilisateurs de Red Hat à innover et à atteindre leurs objectifs grâce à nos produits et services avec un contenu auquel ils peuvent faire confiance. Découvrez nos récentes mises à jour.
Rendre l’open source plus inclusif
Red Hat s'engage à remplacer le langage problématique dans notre code, notre documentation et nos propriétés Web. Pour plus de détails, consultez le Blog Red Hat.
À propos de Red Hat
Nous proposons des solutions renforcées qui facilitent le travail des entreprises sur plusieurs plates-formes et environnements, du centre de données central à la périphérie du réseau.