| 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 | |
| 43 | QT_BEGIN_NAMESPACE |
| 44 | |
| 45 | namespace QTest { |
| 46 | |
| 47 | struct QBenchmarkMetricKey { |
| 48 | int metric; |
| 49 | const char * name; |
| 50 | const char * unit; |
| 51 | }; |
| 52 | |
| 53 | static const QBenchmarkMetricKey entries[] = { |
| 54 | { .metric: FramesPerSecond, .name: "FramesPerSecond" , .unit: "fps" }, |
| 55 | { .metric: BitsPerSecond, .name: "BitsPerSecond" , .unit: "bits/s" }, |
| 56 | { .metric: BytesPerSecond, .name: "BytesPerSecond" , .unit: "bytes/s" }, |
| 57 | { .metric: WalltimeMilliseconds, .name: "WalltimeMilliseconds" , .unit: "msecs" }, |
| 58 | { .metric: CPUTicks, .name: "CPUTicks" , .unit: "CPU ticks" }, |
| 59 | { .metric: InstructionReads, .name: "InstructionReads" , .unit: "instruction reads" }, |
| 60 | { .metric: Events, .name: "Events" , .unit: "events" }, |
| 61 | { .metric: WalltimeNanoseconds, .name: "WalltimeNanoseconds" , .unit: "nsecs" }, |
| 62 | { .metric: BytesAllocated, .name: "BytesAllocated" , .unit: "bytes" }, |
| 63 | { .metric: CPUMigrations, .name: "CPUMigrations" , .unit: "CPU migrations" }, |
| 64 | { .metric: CPUCycles, .name: "CPUCycles" , .unit: "CPU cycles" }, |
| 65 | { .metric: BusCycles, .name: "BusCycles" , .unit: "bus cycles" }, |
| 66 | { .metric: StalledCycles, .name: "StalledCycles" , .unit: "stalled cycles" }, |
| 67 | { .metric: Instructions, .name: "Instructions" , .unit: "instructions" }, |
| 68 | { .metric: BranchInstructions, .name: "BranchInstructions" , .unit: "branch instructions" }, |
| 69 | { .metric: BranchMisses, .name: "BranchMisses" , .unit: "branch misses" }, |
| 70 | { .metric: CacheReferences, .name: "CacheReferences" , .unit: "cache references" }, |
| 71 | { .metric: CacheReads, .name: "CacheReads" , .unit: "cache loads" }, |
| 72 | { .metric: CacheWrites, .name: "CacheWrites" , .unit: "cache stores" }, |
| 73 | { .metric: CachePrefetches, .name: "CachePrefetches" , .unit: "cache prefetches" }, |
| 74 | { .metric: CacheMisses, .name: "CacheMisses" , .unit: "cache misses" }, |
| 75 | { .metric: CacheReadMisses, .name: "CacheReadMisses" , .unit: "cache load misses" }, |
| 76 | { .metric: CacheWriteMisses, .name: "CacheWriteMisses" , .unit: "cache store misses" }, |
| 77 | { .metric: CachePrefetchMisses, .name: "CachePrefetchMisses" , .unit: "cache prefetch misses" }, |
| 78 | { .metric: ContextSwitches, .name: "ContextSwitches" , .unit: "context switches" }, |
| 79 | { .metric: PageFaults, .name: "PageFaults" , .unit: "page faults" }, |
| 80 | { .metric: MinorPageFaults, .name: "MinorPageFaults" , .unit: "minor page faults" }, |
| 81 | { .metric: MajorPageFaults, .name: "MajorPageFaults" , .unit: "major page faults" }, |
| 82 | { .metric: AlignmentFaults, .name: "AlignmentFaults" , .unit: "alignment faults" }, |
| 83 | { .metric: EmulationFaults, .name: "EmulationFaults" , .unit: "emulation faults" }, |
| 84 | { .metric: RefCPUCycles, .name: "RefCPUCycles" , .unit: "Reference CPU cycles" }, |
| 85 | }; |
| 86 | static 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 | */ |
| 140 | const 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 | */ |
| 152 | const char * QTest::benchmarkMetricUnit(QBenchmarkMetric metric) |
| 153 | { |
| 154 | if (unsigned(metric) < unsigned(QTest::NumEntries)) |
| 155 | return entries[metric].unit; |
| 156 | |
| 157 | return "" ; |
| 158 | } |
| 159 | |
| 160 | QT_END_NAMESPACE |
| 161 | |