qbenchmarkperfevents.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/testlib/qbenchmarkperfevents.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2013 Intel Corporation.-
4** Contact: http://www.qt.io/licensing/-
5**-
6** This file is part of the QtCore module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL21$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see http://www.qt.io/terms-conditions. For further-
15** information use the contact form at http://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 2.1 or version 3 as published by the Free-
20** Software Foundation and appearing in the file LICENSE.LGPLv21 and-
21** LICENSE.LGPLv3 included in the packaging of this file. Please review the-
22** following information to ensure the GNU Lesser General Public License-
23** requirements will be met: https://www.gnu.org/licenses/lgpl.html and-
24** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.-
25**-
26** As a special exception, The Qt Company gives you certain additional-
27** rights. These rights are described in The Qt Company LGPL Exception-
28** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.-
29**-
30** $QT_END_LICENSE$-
31**-
32****************************************************************************/-
33-
34#include "qbenchmarkperfevents_p.h"-
35#include "qbenchmarkmetric.h"-
36#include "qbenchmark_p.h"-
37-
38#ifdef QTESTLIB_USE_PERF_EVENTS-
39-
40// include the qcore_unix_p.h without core-private-
41// we only use inline functions anyway-
42#include "../corelib/kernel/qcore_unix_p.h"-
43-
44#include <sys/types.h>-
45#include <errno.h>-
46#include <fcntl.h>-
47#include <string.h>-
48#include <stdio.h>-
49-
50#include <sys/syscall.h>-
51#include <sys/ioctl.h>-
52-
53#include "3rdparty/linux_perf_event_p.h"-
54-
55// for PERF_TYPE_HW_CACHE, the config is a bitmask-
56// lowest 8 bits: cache type-
57// bits 8 to 15: cache operation-
58// bits 16 to 23: cache result-
59#define CACHE_L1D_READ (PERF_COUNT_HW_CACHE_L1D | PERF_COUNT_HW_CACHE_OP_READ << 8 | PERF_COUNT_HW_CACHE_RESULT_ACCESS << 16)-
60#define CACHE_L1D_WRITE (PERF_COUNT_HW_CACHE_L1D | PERF_COUNT_HW_CACHE_OP_WRITE << 8 | PERF_COUNT_HW_CACHE_RESULT_ACCESS << 16)-
61#define CACHE_L1D_PREFETCH (PERF_COUNT_HW_CACHE_L1D | PERF_COUNT_HW_CACHE_OP_PREFETCH << 8 | PERF_COUNT_HW_CACHE_RESULT_ACCESS << 16)-
62#define CACHE_L1I_READ (PERF_COUNT_HW_CACHE_L1I | PERF_COUNT_HW_CACHE_OP_READ << 8 | PERF_COUNT_HW_CACHE_RESULT_ACCESS << 16)-
63#define CACHE_L1I_PREFETCH (PERF_COUNT_HW_CACHE_L1I | PERF_COUNT_HW_CACHE_OP_PREFETCH << 8 | PERF_COUNT_HW_CACHE_RESULT_ACCESS << 16)-
64#define CACHE_LLC_READ (PERF_COUNT_HW_CACHE_LL | PERF_COUNT_HW_CACHE_OP_READ << 8 | PERF_COUNT_HW_CACHE_RESULT_ACCESS << 16)-
65#define CACHE_LLC_WRITE (PERF_COUNT_HW_CACHE_LL | PERF_COUNT_HW_CACHE_OP_WRITE << 8| PERF_COUNT_HW_CACHE_RESULT_ACCESS << 16)-
66#define CACHE_LLC_PREFETCH (PERF_COUNT_HW_CACHE_LL | PERF_COUNT_HW_CACHE_OP_PREFETCH << 8 | PERF_COUNT_HW_CACHE_RESULT_ACCESS << 16)-
67#define CACHE_L1D_READ_MISS (PERF_COUNT_HW_CACHE_L1D | PERF_COUNT_HW_CACHE_OP_READ << 8 | PERF_COUNT_HW_CACHE_RESULT_MISS << 16)-
68#define CACHE_L1D_WRITE_MISS (PERF_COUNT_HW_CACHE_L1D | PERF_COUNT_HW_CACHE_OP_WRITE << 8 | PERF_COUNT_HW_CACHE_RESULT_MISS << 16)-
69#define CACHE_L1D_PREFETCH_MISS (PERF_COUNT_HW_CACHE_L1D | PERF_COUNT_HW_CACHE_OP_PREFETCH << 8 | PERF_COUNT_HW_CACHE_RESULT_MISS << 16)-
70#define CACHE_L1I_READ_MISS (PERF_COUNT_HW_CACHE_L1I | PERF_COUNT_HW_CACHE_OP_READ << 8 | PERF_COUNT_HW_CACHE_RESULT_MISS << 16)-
71#define CACHE_L1I_PREFETCH_MISS (PERF_COUNT_HW_CACHE_L1I | PERF_COUNT_HW_CACHE_OP_PREFETCH << 8 | PERF_COUNT_HW_CACHE_RESULT_MISS << 16)-
72#define CACHE_LLC_READ_MISS (PERF_COUNT_HW_CACHE_LL | PERF_COUNT_HW_CACHE_OP_READ << 8 | PERF_COUNT_HW_CACHE_RESULT_MISS << 16)-
73#define CACHE_LLC_WRITE_MISS (PERF_COUNT_HW_CACHE_LL | PERF_COUNT_HW_CACHE_OP_WRITE << 8 | PERF_COUNT_HW_CACHE_RESULT_MISS << 16)-
74#define CACHE_LLC_PREFETCH_MISS (PERF_COUNT_HW_CACHE_LL | PERF_COUNT_HW_CACHE_OP_PREFETCH << 8 | PERF_COUNT_HW_CACHE_RESULT_MISS << 16)-
75#define CACHE_BRANCH_READ (PERF_COUNT_HW_CACHE_BPU | PERF_COUNT_HW_CACHE_OP_READ << 8 | PERF_COUNT_HW_CACHE_RESULT_ACCESS << 16)-
76#define CACHE_BRANCH_READ_MISS (PERF_COUNT_HW_CACHE_BPU | PERF_COUNT_HW_CACHE_OP_READ << 8 | PERF_COUNT_HW_CACHE_RESULT_MISS << 16)-
77-
78QT_BEGIN_NAMESPACE-
79-
80static perf_event_attr attr;-
81-
82static void initPerf()-
83{-
84 static bool done;-
85 if (!done) {
!doneDescription
TRUEnever evaluated
FALSEnever evaluated
0
86 memset(&attr, 0, sizeof attr);-
87 attr.size = sizeof attr;-
88 attr.read_format = PERF_FORMAT_TOTAL_TIME_ENABLED | PERF_FORMAT_TOTAL_TIME_RUNNING;-
89 attr.disabled = true; // we'll enable later-
90 attr.inherit = true; // let children processes inherit the monitoring-
91 attr.pinned = true; // keep it running in the hardware-
92 attr.inherit_stat = true; // aggregate all the info from child processes-
93 attr.task = true; // trace fork/exits-
94-
95 // set a default performance counter: CPU cycles-
96 attr.type = PERF_TYPE_HARDWARE;-
97 attr.config = PERF_COUNT_HW_CPU_CYCLES; // default-
98-
99 done = true;-
100 }
never executed: end of block
0
101}
never executed: end of block
0
102-
103/*!-
104 \class QBenchmarkPerfEvents-
105 \brief The Linux perf events benchmark backend-
106-
107 This benchmark backend uses the Linux Performance Counters interface,-
108 introduced with the Linux kernel v2.6.31. The interface is done by one-
109 system call (perf_event_open) which takes an attribute structure and-
110 returns a file descriptor.-
111-
112 More information:-
113 \li design docs: tools/perf/design.txt <http://lxr.linux.no/linux/tools/perf/design.txt>-
114 \li sample tool: tools/perf/builtin-stat.c <http://lxr.linux.no/linux/tools/perf/builtin-stat.c>-
115 (note: as of v3.3.1, the documentation is out-of-date with the kernel-
116 interface, so reading the source code of existing tools is necessary)-
117-
118 This benchlib backend monitors the current process as well as child process-
119 launched. We do not try to benchmark in kernel or hypervisor mode, as that-
120 usually requires elevated privileges.-
121 */-
122-
123static int perf_event_open(perf_event_attr *attr, pid_t pid, int cpu, int group_fd, unsigned long flags)-
124{-
125#ifdef SYS_perf_event_open-
126 return syscall(SYS_perf_event_open, attr, pid, cpu, group_fd, flags);
never executed: return syscall(298, attr, pid, cpu, group_fd, flags);
0
127#else-
128 Q_UNUSED(attr);-
129 Q_UNUSED(pid);-
130 Q_UNUSED(cpu);-
131 Q_UNUSED(group_fd);-
132 Q_UNUSED(flags);-
133 errno = ENOSYS;-
134 return -1;-
135#endif-
136}-
137-
138bool QBenchmarkPerfEventsMeasurer::isAvailable()-
139{-
140 // this generates an EFAULT because attr == NULL if perf_event_open is available-
141 // if the kernel is too old, it generates ENOSYS-
142 return perf_event_open(0, 0, 0, 0, 0) == -1 && errno != ENOSYS;
never executed: return perf_event_open(0, 0, 0, 0, 0) == -1 && (*__errno_location ()) != 38;
perf_event_ope...0, 0, 0) == -1Description
TRUEnever evaluated
FALSEnever evaluated
(*__errno_location ()) != 38Description
TRUEnever evaluated
FALSEnever evaluated
0
143}-
144-
145/* Event list structure-
146 The following table provides the list of supported events-
147-
148 Event type Event counter Unit Name and aliases-
149 HARDWARE CPU_CYCLES CPUCycles cycles cpu-cycles-
150 HARDWARE INSTRUCTIONS Instructions instructions-
151 HARDWARE CACHE_REFERENCES CacheReferences cache-references-
152 HARDWARE CACHE_MISSES CacheMisses cache-misses-
153 HARDWARE BRANCH_INSTRUCTIONS BranchInstructions branch-instructions branches-
154 HARDWARE BRANCH_MISSES BranchMisses branch-misses-
155 HARDWARE BUS_CYCLES BusCycles bus-cycles-
156 HARDWARE STALLED_CYCLES_FRONTEND StalledCycles stalled-cycles-frontend idle-cycles-frontend-
157 HARDWARE STALLED_CYCLES_BACKEND StalledCycles stalled-cycles-backend idle-cycles-backend-
158 SOFTWARE CPU_CLOCK WalltimeMilliseconds cpu-clock-
159 SOFTWARE TASK_CLOCK WalltimeMilliseconds task-clock-
160 SOFTWARE PAGE_FAULTS PageFaults page-faults faults-
161 SOFTWARE PAGE_FAULTS_MAJ MajorPageFaults major-faults-
162 SOFTWARE PAGE_FAULTS_MIN MinorPageFaults minor-faults-
163 SOFTWARE CONTEXT_SWITCHES ContextSwitches context-switches cs-
164 SOFTWARE CPU_MIGRATIONS CPUMigrations cpu-migrations migrations-
165 SOFTWARE ALIGNMENT_FAULTS AlignmentFaults alignment-faults-
166 SOFTWARE EMULATION_FAULTS EmulationFaults emulation-faults-
167 HW_CACHE L1D_READ CacheReads l1d-cache-reads l1d-cache-loads l1d-reads l1d-loads-
168 HW_CACHE L1D_WRITE CacheWrites l1d-cache-writes l1d-cache-stores l1d-writes l1d-stores-
169 HW_CACHE L1D_PREFETCH CachePrefetches l1d-cache-prefetches l1d-prefetches-
170 HW_CACHE L1I_READ CacheReads l1i-cache-reads l1i-cache-loads l1i-reads l1i-loads-
171 HW_CACHE L1I_PREFETCH CachePrefetches l1i-cache-prefetches l1i-prefetches-
172 HW_CACHE LLC_READ CacheReads llc-cache-reads llc-cache-loads llc-loads llc-reads-
173 HW_CACHE LLC_WRITE CacheWrites llc-cache-writes llc-cache-stores llc-writes llc-stores-
174 HW_CACHE LLC_PREFETCH CachePrefetches llc-cache-prefetches llc-prefetches-
175 HW_CACHE L1D_READ_MISS CacheReads l1d-cache-read-misses l1d-cache-load-misses l1d-read-misses l1d-load-misses-
176 HW_CACHE L1D_WRITE_MISS CacheWrites l1d-cache-write-misses l1d-cache-store-misses l1d-write-misses l1d-store-misses-
177 HW_CACHE L1D_PREFETCH_MISS CachePrefetches l1d-cache-prefetch-misses l1d-prefetch-misses-
178 HW_CACHE L1I_READ_MISS CacheReads l1i-cache-read-misses l1i-cache-load-misses l1i-read-misses l1i-load-misses-
179 HW_CACHE L1I_PREFETCH_MISS CachePrefetches l1i-cache-prefetch-misses l1i-prefetch-misses-
180 HW_CACHE LLC_READ_MISS CacheReads llc-cache-read-misses llc-cache-load-misses llc-read-misses llc-load-misses-
181 HW_CACHE LLC_WRITE_MISS CacheWrites llc-cache-write-misses llc-cache-store-misses llc-write-misses llc-store-misses-
182 HW_CACHE LLC_PREFETCH_MISS CachePrefetches llc-cache-prefetch-misses llc-prefetch-misses-
183 HW_CACHE BRANCH_READ BranchInstructions branch-reads branch-loads branch-predicts-
184 HW_CACHE BRANCH_READ_MISS BranchMisses branch-mispredicts branch-read-misses branch-load-misses-
185-
186 Use the following Perl script to re-generate the list-
187=== cut perl ===-
188#!/usr/bin/env perl-
189# Load all entries into %map-
190while (<STDIN>) {-
191 m/^\s*(.*)\s*$/;-
192 @_ = split /\s+/, $1;-
193 $type = shift @_;-
194 $id = ($type eq "HARDWARE" ? "PERF_COUNT_HW_" :-
195 $type eq "SOFTWARE" ? "PERF_COUNT_SW_" :-
196 $type eq "HW_CACHE" ? "CACHE_" : "") . shift @_;-
197 $unit = shift @_;-
198-
199 for $string (@_) {-
200 die "$string was already seen!" if defined($map{$string});-
201 $map{$string} = [-1, $type, $id, $unit];-
202 push @strings, $string;-
203 }-
204}-
205-
206# sort the map and print the string list-
207@strings = sort @strings;-
208print "static const char eventlist_strings[] = \n";-
209$counter = 0;-
210for $entry (@strings) {-
211 print " \"$entry\\0\"\n";-
212 $map{$entry}[0] = $counter;-
213 $counter += 1 + length $entry;-
214}-
215-
216# print the table-
217print " \"\\0\";\n\nstatic const Events eventlist[] = {\n";-
218for $entry (sort @strings) {-
219 printf " { %3d, PERF_TYPE_%s, %s, QTest::%s },\n",-
220 $map{$entry}[0],-
221 $map{$entry}[1],-
222 $map{$entry}[2],-
223 $map{$entry}[3];-
224}-
225print " { 0, PERF_TYPE_MAX, 0, QTest::Events }\n};\n";-
226=== cut perl ===-
227*/-
228-
229struct Events {-
230 unsigned offset;-
231 quint32 type;-
232 quint64 event_id;-
233 QTest::QBenchmarkMetric metric;-
234};-
235-
236/* -- BEGIN GENERATED CODE -- */-
237static const char eventlist_strings[] =-
238 "alignment-faults\0"-
239 "branch-instructions\0"-
240 "branch-load-misses\0"-
241 "branch-loads\0"-
242 "branch-mispredicts\0"-
243 "branch-misses\0"-
244 "branch-predicts\0"-
245 "branch-read-misses\0"-
246 "branch-reads\0"-
247 "branches\0"-
248 "bus-cycles\0"-
249 "cache-misses\0"-
250 "cache-references\0"-
251 "context-switches\0"-
252 "cpu-clock\0"-
253 "cpu-cycles\0"-
254 "cpu-migrations\0"-
255 "cs\0"-
256 "cycles\0"-
257 "emulation-faults\0"-
258 "faults\0"-
259 "idle-cycles-backend\0"-
260 "idle-cycles-frontend\0"-
261 "instructions\0"-
262 "l1d-cache-load-misses\0"-
263 "l1d-cache-loads\0"-
264 "l1d-cache-prefetch-misses\0"-
265 "l1d-cache-prefetches\0"-
266 "l1d-cache-read-misses\0"-
267 "l1d-cache-reads\0"-
268 "l1d-cache-store-misses\0"-
269 "l1d-cache-stores\0"-
270 "l1d-cache-write-misses\0"-
271 "l1d-cache-writes\0"-
272 "l1d-load-misses\0"-
273 "l1d-loads\0"-
274 "l1d-prefetch-misses\0"-
275 "l1d-prefetches\0"-
276 "l1d-read-misses\0"-
277 "l1d-reads\0"-
278 "l1d-store-misses\0"-
279 "l1d-stores\0"-
280 "l1d-write-misses\0"-
281 "l1d-writes\0"-
282 "l1i-cache-load-misses\0"-
283 "l1i-cache-loads\0"-
284 "l1i-cache-prefetch-misses\0"-
285 "l1i-cache-prefetches\0"-
286 "l1i-cache-read-misses\0"-
287 "l1i-cache-reads\0"-
288 "l1i-load-misses\0"-
289 "l1i-loads\0"-
290 "l1i-prefetch-misses\0"-
291 "l1i-prefetches\0"-
292 "l1i-read-misses\0"-
293 "l1i-reads\0"-
294 "llc-cache-load-misses\0"-
295 "llc-cache-loads\0"-
296 "llc-cache-prefetch-misses\0"-
297 "llc-cache-prefetches\0"-
298 "llc-cache-read-misses\0"-
299 "llc-cache-reads\0"-
300 "llc-cache-store-misses\0"-
301 "llc-cache-stores\0"-
302 "llc-cache-write-misses\0"-
303 "llc-cache-writes\0"-
304 "llc-load-misses\0"-
305 "llc-loads\0"-
306 "llc-prefetch-misses\0"-
307 "llc-prefetches\0"-
308 "llc-read-misses\0"-
309 "llc-reads\0"-
310 "llc-store-misses\0"-
311 "llc-stores\0"-
312 "llc-write-misses\0"-
313 "llc-writes\0"-
314 "major-faults\0"-
315 "migrations\0"-
316 "minor-faults\0"-
317 "page-faults\0"-
318 "stalled-cycles-backend\0"-
319 "stalled-cycles-frontend\0"-
320 "task-clock\0"-
321 "\0";-
322-
323static const Events eventlist[] = {-
324 { 0, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_ALIGNMENT_FAULTS, QTest::AlignmentFaults },-
325 { 17, PERF_TYPE_HARDWARE, PERF_COUNT_HW_BRANCH_INSTRUCTIONS, QTest::BranchInstructions },-
326 { 37, PERF_TYPE_HW_CACHE, CACHE_BRANCH_READ_MISS, QTest::BranchMisses },-
327 { 56, PERF_TYPE_HW_CACHE, CACHE_BRANCH_READ, QTest::BranchInstructions },-
328 { 69, PERF_TYPE_HW_CACHE, CACHE_BRANCH_READ_MISS, QTest::BranchMisses },-
329 { 88, PERF_TYPE_HARDWARE, PERF_COUNT_HW_BRANCH_MISSES, QTest::BranchMisses },-
330 { 102, PERF_TYPE_HW_CACHE, CACHE_BRANCH_READ, QTest::BranchInstructions },-
331 { 118, PERF_TYPE_HW_CACHE, CACHE_BRANCH_READ_MISS, QTest::BranchMisses },-
332 { 137, PERF_TYPE_HW_CACHE, CACHE_BRANCH_READ, QTest::BranchInstructions },-
333 { 150, PERF_TYPE_HARDWARE, PERF_COUNT_HW_BRANCH_INSTRUCTIONS, QTest::BranchInstructions },-
334 { 159, PERF_TYPE_HARDWARE, PERF_COUNT_HW_BUS_CYCLES, QTest::BusCycles },-
335 { 170, PERF_TYPE_HARDWARE, PERF_COUNT_HW_CACHE_MISSES, QTest::CacheMisses },-
336 { 183, PERF_TYPE_HARDWARE, PERF_COUNT_HW_CACHE_REFERENCES, QTest::CacheReferences },-
337 { 200, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CONTEXT_SWITCHES, QTest::ContextSwitches },-
338 { 217, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CPU_CLOCK, QTest::WalltimeMilliseconds },-
339 { 227, PERF_TYPE_HARDWARE, PERF_COUNT_HW_CPU_CYCLES, QTest::CPUCycles },-
340 { 238, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CPU_MIGRATIONS, QTest::CPUMigrations },-
341 { 253, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CONTEXT_SWITCHES, QTest::ContextSwitches },-
342 { 256, PERF_TYPE_HARDWARE, PERF_COUNT_HW_CPU_CYCLES, QTest::CPUCycles },-
343 { 263, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_EMULATION_FAULTS, QTest::EmulationFaults },-
344 { 280, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_PAGE_FAULTS, QTest::PageFaults },-
345 { 287, PERF_TYPE_HARDWARE, PERF_COUNT_HW_STALLED_CYCLES_BACKEND, QTest::StalledCycles },-
346 { 307, PERF_TYPE_HARDWARE, PERF_COUNT_HW_STALLED_CYCLES_FRONTEND, QTest::StalledCycles },-
347 { 328, PERF_TYPE_HARDWARE, PERF_COUNT_HW_INSTRUCTIONS, QTest::Instructions },-
348 { 341, PERF_TYPE_HW_CACHE, CACHE_L1D_READ_MISS, QTest::CacheReads },-
349 { 363, PERF_TYPE_HW_CACHE, CACHE_L1D_READ, QTest::CacheReads },-
350 { 379, PERF_TYPE_HW_CACHE, CACHE_L1D_PREFETCH_MISS, QTest::CachePrefetches },-
351 { 405, PERF_TYPE_HW_CACHE, CACHE_L1D_PREFETCH, QTest::CachePrefetches },-
352 { 426, PERF_TYPE_HW_CACHE, CACHE_L1D_READ_MISS, QTest::CacheReads },-
353 { 448, PERF_TYPE_HW_CACHE, CACHE_L1D_READ, QTest::CacheReads },-
354 { 464, PERF_TYPE_HW_CACHE, CACHE_L1D_WRITE_MISS, QTest::CacheWrites },-
355 { 487, PERF_TYPE_HW_CACHE, CACHE_L1D_WRITE, QTest::CacheWrites },-
356 { 504, PERF_TYPE_HW_CACHE, CACHE_L1D_WRITE_MISS, QTest::CacheWrites },-
357 { 527, PERF_TYPE_HW_CACHE, CACHE_L1D_WRITE, QTest::CacheWrites },-
358 { 544, PERF_TYPE_HW_CACHE, CACHE_L1D_READ_MISS, QTest::CacheReads },-
359 { 560, PERF_TYPE_HW_CACHE, CACHE_L1D_READ, QTest::CacheReads },-
360 { 570, PERF_TYPE_HW_CACHE, CACHE_L1D_PREFETCH_MISS, QTest::CachePrefetches },-
361 { 590, PERF_TYPE_HW_CACHE, CACHE_L1D_PREFETCH, QTest::CachePrefetches },-
362 { 605, PERF_TYPE_HW_CACHE, CACHE_L1D_READ_MISS, QTest::CacheReads },-
363 { 621, PERF_TYPE_HW_CACHE, CACHE_L1D_READ, QTest::CacheReads },-
364 { 631, PERF_TYPE_HW_CACHE, CACHE_L1D_WRITE_MISS, QTest::CacheWrites },-
365 { 648, PERF_TYPE_HW_CACHE, CACHE_L1D_WRITE, QTest::CacheWrites },-
366 { 659, PERF_TYPE_HW_CACHE, CACHE_L1D_WRITE_MISS, QTest::CacheWrites },-
367 { 676, PERF_TYPE_HW_CACHE, CACHE_L1D_WRITE, QTest::CacheWrites },-
368 { 687, PERF_TYPE_HW_CACHE, CACHE_L1I_READ_MISS, QTest::CacheReads },-
369 { 709, PERF_TYPE_HW_CACHE, CACHE_L1I_READ, QTest::CacheReads },-
370 { 725, PERF_TYPE_HW_CACHE, CACHE_L1I_PREFETCH_MISS, QTest::CachePrefetches },-
371 { 751, PERF_TYPE_HW_CACHE, CACHE_L1I_PREFETCH, QTest::CachePrefetches },-
372 { 772, PERF_TYPE_HW_CACHE, CACHE_L1I_READ_MISS, QTest::CacheReads },-
373 { 794, PERF_TYPE_HW_CACHE, CACHE_L1I_READ, QTest::CacheReads },-
374 { 810, PERF_TYPE_HW_CACHE, CACHE_L1I_READ_MISS, QTest::CacheReads },-
375 { 826, PERF_TYPE_HW_CACHE, CACHE_L1I_READ, QTest::CacheReads },-
376 { 836, PERF_TYPE_HW_CACHE, CACHE_L1I_PREFETCH_MISS, QTest::CachePrefetches },-
377 { 856, PERF_TYPE_HW_CACHE, CACHE_L1I_PREFETCH, QTest::CachePrefetches },-
378 { 871, PERF_TYPE_HW_CACHE, CACHE_L1I_READ_MISS, QTest::CacheReads },-
379 { 887, PERF_TYPE_HW_CACHE, CACHE_L1I_READ, QTest::CacheReads },-
380 { 897, PERF_TYPE_HW_CACHE, CACHE_LLC_READ_MISS, QTest::CacheReads },-
381 { 919, PERF_TYPE_HW_CACHE, CACHE_LLC_READ, QTest::CacheReads },-
382 { 935, PERF_TYPE_HW_CACHE, CACHE_LLC_PREFETCH_MISS, QTest::CachePrefetches },-
383 { 961, PERF_TYPE_HW_CACHE, CACHE_LLC_PREFETCH, QTest::CachePrefetches },-
384 { 982, PERF_TYPE_HW_CACHE, CACHE_LLC_READ_MISS, QTest::CacheReads },-
385 { 1004, PERF_TYPE_HW_CACHE, CACHE_LLC_READ, QTest::CacheReads },-
386 { 1020, PERF_TYPE_HW_CACHE, CACHE_LLC_WRITE_MISS, QTest::CacheWrites },-
387 { 1043, PERF_TYPE_HW_CACHE, CACHE_LLC_WRITE, QTest::CacheWrites },-
388 { 1060, PERF_TYPE_HW_CACHE, CACHE_LLC_WRITE_MISS, QTest::CacheWrites },-
389 { 1083, PERF_TYPE_HW_CACHE, CACHE_LLC_WRITE, QTest::CacheWrites },-
390 { 1100, PERF_TYPE_HW_CACHE, CACHE_LLC_READ_MISS, QTest::CacheReads },-
391 { 1116, PERF_TYPE_HW_CACHE, CACHE_LLC_READ, QTest::CacheReads },-
392 { 1126, PERF_TYPE_HW_CACHE, CACHE_LLC_PREFETCH_MISS, QTest::CachePrefetches },-
393 { 1146, PERF_TYPE_HW_CACHE, CACHE_LLC_PREFETCH, QTest::CachePrefetches },-
394 { 1161, PERF_TYPE_HW_CACHE, CACHE_LLC_READ_MISS, QTest::CacheReads },-
395 { 1177, PERF_TYPE_HW_CACHE, CACHE_LLC_READ, QTest::CacheReads },-
396 { 1187, PERF_TYPE_HW_CACHE, CACHE_LLC_WRITE_MISS, QTest::CacheWrites },-
397 { 1204, PERF_TYPE_HW_CACHE, CACHE_LLC_WRITE, QTest::CacheWrites },-
398 { 1215, PERF_TYPE_HW_CACHE, CACHE_LLC_WRITE_MISS, QTest::CacheWrites },-
399 { 1232, PERF_TYPE_HW_CACHE, CACHE_LLC_WRITE, QTest::CacheWrites },-
400 { 1243, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_PAGE_FAULTS_MAJ, QTest::MajorPageFaults },-
401 { 1256, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CPU_MIGRATIONS, QTest::CPUMigrations },-
402 { 1267, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_PAGE_FAULTS_MIN, QTest::MinorPageFaults },-
403 { 1280, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_PAGE_FAULTS, QTest::PageFaults },-
404 { 1292, PERF_TYPE_HARDWARE, PERF_COUNT_HW_STALLED_CYCLES_BACKEND, QTest::StalledCycles },-
405 { 1315, PERF_TYPE_HARDWARE, PERF_COUNT_HW_STALLED_CYCLES_FRONTEND, QTest::StalledCycles },-
406 { 1339, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_TASK_CLOCK, QTest::WalltimeMilliseconds },-
407 { 0, PERF_TYPE_MAX, 0, QTest::Events }-
408};-
409/* -- END GENERATED CODE -- */-
410-
411QTest::QBenchmarkMetric QBenchmarkPerfEventsMeasurer::metricForEvent(quint32 type, quint64 event_id)-
412{-
413 const Events *ptr = eventlist;-
414 for ( ; ptr->type != PERF_TYPE_MAX; ++ptr) {
ptr->type != PERF_TYPE_MAXDescription
TRUEnever evaluated
FALSEnever evaluated
0
415 if (ptr->type == type && ptr->event_id == event_id)
ptr->type == typeDescription
TRUEnever evaluated
FALSEnever evaluated
ptr->event_id == event_idDescription
TRUEnever evaluated
FALSEnever evaluated
0
416 return ptr->metric;
never executed: return ptr->metric;
0
417 }
never executed: end of block
0
418 return QTest::Events;
never executed: return QTest::Events;
0
419}-
420-
421void QBenchmarkPerfEventsMeasurer::setCounter(const char *name)-
422{-
423 initPerf();-
424 const char *colon = strchr(name, ':');-
425 int n = colon ? colon - name : strlen(name);
colonDescription
TRUEnever evaluated
FALSEnever evaluated
0
426 const Events *ptr = eventlist;-
427 for ( ; ptr->type != PERF_TYPE_MAX; ++ptr) {
ptr->type != PERF_TYPE_MAXDescription
TRUEnever evaluated
FALSEnever evaluated
0
428 int c = strncmp(name, eventlist_strings + ptr->offset, n);-
429 if (c == 0)
c == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
430 break;
never executed: break;
0
431 if (c < 0) {
c < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
432 fprintf(stderr, "ERROR: Performance counter type '%s' is unknown\n", name);-
433 exit(1);
never executed: exit(1);
0
434 }-
435 }
never executed: end of block
0
436-
437 attr.type = ptr->type;-
438 attr.config = ptr->event_id;-
439-
440 // now parse the attributes-
441 if (!colon)
!colonDescription
TRUEnever evaluated
FALSEnever evaluated
0
442 return;
never executed: return;
0
443 while (*++colon) {
*++colonDescription
TRUEnever evaluated
FALSEnever evaluated
0
444 switch (*colon) {-
445 case 'u':
never executed: case 'u':
0
446 attr.exclude_user = true;-
447 break;
never executed: break;
0
448 case 'k':
never executed: case 'k':
0
449 attr.exclude_kernel = true;-
450 break;
never executed: break;
0
451 case 'h':
never executed: case 'h':
0
452 attr.exclude_hv = true;-
453 break;
never executed: break;
0
454 case 'G':
never executed: case 'G':
0
455 attr.exclude_guest = true;-
456 break;
never executed: break;
0
457 case 'H':
never executed: case 'H':
0
458 attr.exclude_host = true;-
459 break;
never executed: break;
0
460 default:
never executed: default:
0
461 fprintf(stderr, "ERROR: Unknown attribute '%c'\n", *colon);-
462 exit(1);
never executed: exit(1);
0
463 }-
464 }-
465}
never executed: end of block
0
466-
467void QBenchmarkPerfEventsMeasurer::listCounters()-
468{-
469 if (!isAvailable()) {
!isAvailable()Description
TRUEnever evaluated
FALSEnever evaluated
0
470 printf("Performance counters are not available on this system\n");-
471 return;
never executed: return;
0
472 }-
473-
474 printf("The following performance counters are available:\n");-
475 const Events *ptr = eventlist;-
476 for ( ; ptr->type != PERF_TYPE_MAX; ++ptr) {
ptr->type != PERF_TYPE_MAXDescription
TRUEnever evaluated
FALSEnever evaluated
0
477 printf(" %-30s [%s]\n", eventlist_strings + ptr->offset,-
478 ptr->type == PERF_TYPE_HARDWARE ? "hardware" :-
479 ptr->type == PERF_TYPE_SOFTWARE ? "software" :-
480 ptr->type == PERF_TYPE_HW_CACHE ? "cache" : "other");-
481 }
never executed: end of block
0
482-
483 printf("\nAttributes can be specified by adding a colon and the following:\n"-
484 " u - exclude measuring in the userspace\n"-
485 " k - exclude measuring in kernel mode\n"-
486 " h - exclude measuring in the hypervisor\n"-
487 " G - exclude measuring when running virtualized (guest VM)\n"-
488 " H - exclude measuring when running non-virtualized (host system)\n"-
489 "Attributes can be combined, for example: -perfcounter branch-mispredicts:kh\n");-
490}
never executed: end of block
0
491-
492QBenchmarkPerfEventsMeasurer::QBenchmarkPerfEventsMeasurer()-
493 : fd(-1)-
494{-
495}
never executed: end of block
0
496-
497QBenchmarkPerfEventsMeasurer::~QBenchmarkPerfEventsMeasurer()-
498{-
499 qt_safe_close(fd);-
500}
never executed: end of block
0
501-
502void QBenchmarkPerfEventsMeasurer::init()-
503{-
504}-
505-
506void QBenchmarkPerfEventsMeasurer::start()-
507{-
508-
509 initPerf();-
510 if (fd == -1) {
fd == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
511 // pid == 0 -> attach to the current process-
512 // cpu == -1 -> monitor on all CPUs-
513 // group_fd == -1 -> this is the group leader-
514 // flags == 0 -> reserved, must be zero-
515 fd = perf_event_open(&attr, 0, -1, -1, 0);-
516 if (fd == -1) {
fd == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
517 perror("QBenchmarkPerfEventsMeasurer::start: perf_event_open");-
518 exit(1);
never executed: exit(1);
0
519 } else {-
520 ::fcntl(fd, F_SETFD, FD_CLOEXEC);-
521 }
never executed: end of block
0
522 }-
523-
524 // enable the counter-
525 ::ioctl(fd, PERF_EVENT_IOC_RESET);-
526 ::ioctl(fd, PERF_EVENT_IOC_ENABLE);-
527}
never executed: end of block
0
528-
529qint64 QBenchmarkPerfEventsMeasurer::checkpoint()-
530{-
531 ::ioctl(fd, PERF_EVENT_IOC_DISABLE);-
532 qint64 value = readValue();-
533 ::ioctl(fd, PERF_EVENT_IOC_ENABLE);-
534 return value;
never executed: return value;
0
535}-
536-
537qint64 QBenchmarkPerfEventsMeasurer::stop()-
538{-
539 // disable the counter-
540 ::ioctl(fd, PERF_EVENT_IOC_DISABLE);-
541 return readValue();
never executed: return readValue();
0
542}-
543-
544bool QBenchmarkPerfEventsMeasurer::isMeasurementAccepted(qint64)-
545{-
546 return true;
never executed: return true;
0
547}-
548-
549int QBenchmarkPerfEventsMeasurer::adjustIterationCount(int)-
550{-
551 return 1;
never executed: return 1;
0
552}-
553-
554int QBenchmarkPerfEventsMeasurer::adjustMedianCount(int)-
555{-
556 return 1;
never executed: return 1;
0
557}-
558-
559QTest::QBenchmarkMetric QBenchmarkPerfEventsMeasurer::metricType()-
560{-
561 return metricForEvent(attr.type, attr.config);
never executed: return metricForEvent(attr.type, attr.config);
0
562}-
563-
564static quint64 rawReadValue(int fd)-
565{-
566 /* from the kernel docs:-
567 * struct read_format {-
568 * { u64 value;-
569 * { u64 time_enabled; } && PERF_FORMAT_TOTAL_TIME_ENABLED-
570 * { u64 time_running; } && PERF_FORMAT_TOTAL_TIME_RUNNING-
571 * { u64 id; } && PERF_FORMAT_ID-
572 * } && !PERF_FORMAT_GROUP-
573 */-
574-
575 struct read_format {-
576 quint64 value;-
577 quint64 time_enabled;-
578 quint64 time_running;-
579 } results;-
580-
581 size_t nread = 0;-
582 while (nread < sizeof results) {
nread < sizeof resultsDescription
TRUEnever evaluated
FALSEnever evaluated
0
583 char *ptr = reinterpret_cast<char *>(&results);-
584 qint64 r = qt_safe_read(fd, ptr + nread, sizeof results - nread);-
585 if (r == -1) {
r == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
586 perror("QBenchmarkPerfEventsMeasurer::readValue: reading the results");-
587 exit(1);
never executed: exit(1);
0
588 }-
589 nread += quint64(r);-
590 }
never executed: end of block
0
591-
592 if (results.time_running == results.time_enabled)
results.time_r...s.time_enabledDescription
TRUEnever evaluated
FALSEnever evaluated
0
593 return results.value;
never executed: return results.value;
0
594-
595 // scale the results, though this shouldn't happen!-
596 return results.value * (double(results.time_running) / double(results.time_enabled));
never executed: return results.value * (double(results.time_running) / double(results.time_enabled));
0
597}-
598-
599qint64 QBenchmarkPerfEventsMeasurer::readValue()-
600{-
601 quint64 raw = rawReadValue(fd);-
602 if (metricType() == QTest::WalltimeMilliseconds) {
metricType() =...meMillisecondsDescription
TRUEnever evaluated
FALSEnever evaluated
0
603 // perf returns nanoseconds-
604 return raw / 1000000;
never executed: return raw / 1000000;
0
605 }-
606 return raw;
never executed: return raw;
0
607}-
608-
609QT_END_NAMESPACE-
610-
611#endif-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9