Fix Centurion name.
[0ad.git] / libraries / source / spidermonkey / include-win32-debug / jsperf.h
blob6eece5f3f450a01c6de310ca99a45b3367292245
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef perf_jsperf_h
7 #define perf_jsperf_h
9 #include "jstypes.h"
11 #include "js/TypeDecls.h"
12 #include "js/Utility.h"
14 namespace JS {
17 * JS::PerfMeasurement is a generic way to access detailed performance
18 * measurement APIs provided by your operating system. The details of
19 * exactly how this works and what can be measured are highly
20 * system-specific, but this interface is (one hopes) implementable
21 * on top of all of them.
23 * To use this API, create a PerfMeasurement object, passing its
24 * constructor a bitmask indicating which events you are interested
25 * in. Thereafter, Start() zeroes all counters and starts timing;
26 * Stop() stops timing again; and the counters for the events you
27 * requested are available as data values after calling Stop(). The
28 * object may be reused for many measurements.
30 class JS_FRIEND_API PerfMeasurement {
31 protected:
32 // Implementation-specific data, if any.
33 void* impl;
35 public:
37 * Events that may be measured. Taken directly from the list of
38 * "generalized hardware performance event types" in the Linux
39 * perf_event API, plus some of the "software events".
41 enum EventMask {
42 CPU_CYCLES = 0x00000001,
43 INSTRUCTIONS = 0x00000002,
44 CACHE_REFERENCES = 0x00000004,
45 CACHE_MISSES = 0x00000008,
46 BRANCH_INSTRUCTIONS = 0x00000010,
47 BRANCH_MISSES = 0x00000020,
48 BUS_CYCLES = 0x00000040,
49 PAGE_FAULTS = 0x00000080,
50 MAJOR_PAGE_FAULTS = 0x00000100,
51 CONTEXT_SWITCHES = 0x00000200,
52 CPU_MIGRATIONS = 0x00000400,
54 ALL = 0x000007ff,
55 NUM_MEASURABLE_EVENTS = 11
59 * Bitmask of events that will be measured when this object is
60 * active (between Start() and Stop()). This may differ from the
61 * bitmask passed to the constructor if the platform does not
62 * support measuring all of the requested events.
64 const EventMask eventsMeasured;
67 * Counters for each measurable event.
68 * Immediately after one of these objects is created, all of the
69 * counters for enabled events will be zero, and all of the
70 * counters for disabled events will be uint64_t(-1).
72 uint64_t cpu_cycles;
73 uint64_t instructions;
74 uint64_t cache_references;
75 uint64_t cache_misses;
76 uint64_t branch_instructions;
77 uint64_t branch_misses;
78 uint64_t bus_cycles;
79 uint64_t page_faults;
80 uint64_t major_page_faults;
81 uint64_t context_switches;
82 uint64_t cpu_migrations;
85 * Prepare to measure the indicated set of events. If not all of
86 * the requested events can be measured on the current platform,
87 * then the eventsMeasured bitmask will only include the subset of
88 * |toMeasure| corresponding to the events that can be measured.
90 explicit PerfMeasurement(EventMask toMeasure);
92 /* Done with this set of measurements, tear down OS-level state. */
93 ~PerfMeasurement();
95 /* Start a measurement cycle. */
96 void start();
99 * End a measurement cycle, and for each enabled counter, add the
100 * number of measured events of that type to the appropriate
101 * visible variable.
103 void stop();
105 /* Reset all enabled counters to zero. */
106 void reset();
109 * True if this platform supports measuring _something_, i.e. it's
110 * not using the stub implementation.
112 static bool canMeasureSomething();
115 /* Inject a Javascript wrapper around the above C++ class into the
116 * Javascript object passed as an argument (this will normally be a
117 * global object). The JS-visible API is identical to the C++ API.
119 extern JS_FRIEND_API JSObject* RegisterPerfMeasurement(JSContext* cx,
120 JS::HandleObject global);
123 * Given a Value which contains an instance of the aforementioned
124 * wrapper class, extract the C++ object. Returns nullptr if the
125 * Value is not an instance of the wrapper.
127 extern JS_FRIEND_API PerfMeasurement* ExtractPerfMeasurement(
128 const Value& wrapper);
130 } // namespace JS
132 #endif /* perf_jsperf_h */