1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Copyright (C) 2016 Intel Corporation.
5** Contact: https://www.qt.io/licensing/
6**
7** This file is part of the QtTest module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial License Usage
11** Licensees holding valid commercial Qt licenses may use this file in
12** accordance with the commercial license agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and The Qt Company. For licensing terms
15** and conditions see https://www.qt.io/terms-conditions. For further
16** information use the contact form at https://www.qt.io/contact-us.
17**
18** GNU Lesser General Public License Usage
19** Alternatively, this file may be used under the terms of the GNU Lesser
20** General Public License version 3 as published by the Free Software
21** Foundation and appearing in the file LICENSE.LGPL3 included in the
22** packaging of this file. Please review the following information to
23** ensure the GNU Lesser General Public License version 3 requirements
24** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
25**
26** GNU General Public License Usage
27** Alternatively, this file may be used under the terms of the GNU
28** General Public License version 2.0 or (at your option) the GNU General
29** Public license version 3 or any later version approved by the KDE Free
30** Qt Foundation. The licenses are as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
32** included in the packaging of this file. Please review the following
33** information to ensure the GNU General Public License requirements will
34** be met: https://www.gnu.org/licenses/gpl-2.0.html and
35** https://www.gnu.org/licenses/gpl-3.0.html.
36**
37** $QT_END_LICENSE$
38**
39****************************************************************************/
40
41#include <QtTest/private/qbenchmarkmetric_p.h>
42
43QT_BEGIN_NAMESPACE
44
45namespace QTest {
46
47struct QBenchmarkMetricKey {
48 int metric;
49 const char * name;
50 const char * unit;
51};
52
53static const QBenchmarkMetricKey entries[] = {
54 { FramesPerSecond, "FramesPerSecond", "fps" },
55 { BitsPerSecond, "BitsPerSecond", "bits/s" },
56 { BytesPerSecond, "BytesPerSecond", "bytes/s" },
57 { WalltimeMilliseconds, "WalltimeMilliseconds", "msecs" },
58 { CPUTicks, "CPUTicks", "CPU ticks" },
59 { InstructionReads, "InstructionReads", "instruction reads" },
60 { Events, "Events", "events" },
61 { WalltimeNanoseconds, "WalltimeNanoseconds", "nsecs" },
62 { BytesAllocated, "BytesAllocated", "bytes" },
63 { CPUMigrations, "CPUMigrations", "CPU migrations" },
64 { CPUCycles, "CPUCycles", "CPU cycles" },
65 { BusCycles, "BusCycles", "bus cycles" },
66 { StalledCycles, "StalledCycles", "stalled cycles" },
67 { Instructions, "Instructions", "instructions" },
68 { BranchInstructions, "BranchInstructions", "branch instructions" },
69 { BranchMisses, "BranchMisses", "branch misses" },
70 { CacheReferences, "CacheReferences", "cache references" },
71 { CacheReads, "CacheReads", "cache loads" },
72 { CacheWrites, "CacheWrites", "cache stores" },
73 { CachePrefetches, "CachePrefetches", "cache prefetches" },
74 { CacheMisses, "CacheMisses", "cache misses" },
75 { CacheReadMisses, "CacheReadMisses", "cache load misses" },
76 { CacheWriteMisses, "CacheWriteMisses", "cache store misses" },
77 { CachePrefetchMisses, "CachePrefetchMisses", "cache prefetch misses" },
78 { ContextSwitches, "ContextSwitches", "context switches" },
79 { PageFaults, "PageFaults", "page faults" },
80 { MinorPageFaults, "MinorPageFaults", "minor page faults" },
81 { MajorPageFaults, "MajorPageFaults", "major page faults" },
82 { AlignmentFaults, "AlignmentFaults", "alignment faults" },
83 { EmulationFaults, "EmulationFaults", "emulation faults" },
84 { RefCPUCycles, "RefCPUCycles", "Reference CPU cycles" },
85};
86static const int NumEntries = sizeof(entries) / sizeof(entries[0]);
87
88}
89
90/*!
91 \enum QTest::QBenchmarkMetric
92 \since 4.7
93
94 This enum lists all the things that can be benchmarked.
95
96 \value FramesPerSecond Frames per second
97 \value BitsPerSecond Bits per second
98 \value BytesPerSecond Bytes per second
99 \value WalltimeMilliseconds Clock time in milliseconds
100 \value WalltimeNanoseconds Clock time in nanoseconds
101 \value BytesAllocated Memory usage in bytes
102 \value Events Event count
103 \value CPUTicks CPU time
104 \value CPUMigrations Process migrations between CPUs
105 \value CPUCycles CPU cycles
106 \value RefCPUCycles Reference CPU cycles
107 \value BusCycles Bus cycles
108 \value StalledCycles Cycles stalled
109 \value InstructionReads Instruction reads
110 \value Instructions Instructions executed
111 \value BranchInstructions Branch-type instructions
112 \value BranchMisses Branch instructions that were mispredicted
113 \value CacheReferences Cache accesses of any type
114 \value CacheMisses Cache misses of any type
115 \value CacheReads Cache reads / loads
116 \value CacheReadMisses Cache read / load misses
117 \value CacheWrites Cache writes / stores
118 \value CacheWriteMisses Cache write / store misses
119 \value CachePrefetches Cache prefetches
120 \value CachePrefetchMisses Cache prefetch misses
121 \value ContextSwitches Context switches
122 \value PageFaults Page faults of any type
123 \value MinorPageFaults Minor page faults
124 \value MajorPageFaults Major page faults
125 \value AlignmentFaults Faults caused due to misalignment
126 \value EmulationFaults Faults that needed software emulation
127
128 \sa QTest::benchmarkMetricName(), QTest::benchmarkMetricUnit()
129
130 Note that \c WalltimeNanoseconds and \c BytesAllocated are
131 only provided for use via \l setBenchmarkResult(), and results
132 in those metrics are not able to be provided automatically
133 by the QTest framework.
134 */
135
136/*!
137 \since 4.7
138 Returns the enum value \a metric as a character string.
139 */
140const char * QTest::benchmarkMetricName(QBenchmarkMetric metric)
141{
142 if (unsigned(metric) < unsigned(QTest::NumEntries))
143 return entries[metric].name;
144
145 return "";
146}
147
148/*!
149 \since 4.7
150 Retuns the units of measure for the specified \a metric.
151 */
152const char * QTest::benchmarkMetricUnit(QBenchmarkMetric metric)
153{
154 if (unsigned(metric) < unsigned(QTest::NumEntries))
155 return entries[metric].unit;
156
157 return "";
158}
159
160QT_END_NAMESPACE
161

source code of qtbase/src/testlib/qbenchmarkmetric.cpp