diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /js/src/perf/jsperf.h | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | uxp-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz |
Add m-esr52 at 52.6.0
Diffstat (limited to 'js/src/perf/jsperf.h')
-rw-r--r-- | js/src/perf/jsperf.h | 133 |
1 files changed, 133 insertions, 0 deletions
diff --git a/js/src/perf/jsperf.h b/js/src/perf/jsperf.h new file mode 100644 index 0000000000..b8f2909ad2 --- /dev/null +++ b/js/src/perf/jsperf.h @@ -0,0 +1,133 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef perf_jsperf_h +#define perf_jsperf_h + +#include "jstypes.h" + +#include "js/TypeDecls.h" +#include "js/Utility.h" + +namespace JS { + +/* + * JS::PerfMeasurement is a generic way to access detailed performance + * measurement APIs provided by your operating system. The details of + * exactly how this works and what can be measured are highly + * system-specific, but this interface is (one hopes) implementable + * on top of all of them. + * + * To use this API, create a PerfMeasurement object, passing its + * constructor a bitmask indicating which events you are interested + * in. Thereafter, Start() zeroes all counters and starts timing; + * Stop() stops timing again; and the counters for the events you + * requested are available as data values after calling Stop(). The + * object may be reused for many measurements. + */ +class JS_FRIEND_API(PerfMeasurement) +{ + protected: + // Implementation-specific data, if any. + void* impl; + + public: + /* + * Events that may be measured. Taken directly from the list of + * "generalized hardware performance event types" in the Linux + * perf_event API, plus some of the "software events". + */ + enum EventMask { + CPU_CYCLES = 0x00000001, + INSTRUCTIONS = 0x00000002, + CACHE_REFERENCES = 0x00000004, + CACHE_MISSES = 0x00000008, + BRANCH_INSTRUCTIONS = 0x00000010, + BRANCH_MISSES = 0x00000020, + BUS_CYCLES = 0x00000040, + PAGE_FAULTS = 0x00000080, + MAJOR_PAGE_FAULTS = 0x00000100, + CONTEXT_SWITCHES = 0x00000200, + CPU_MIGRATIONS = 0x00000400, + + ALL = 0x000007ff, + NUM_MEASURABLE_EVENTS = 11 + }; + + /* + * Bitmask of events that will be measured when this object is + * active (between Start() and Stop()). This may differ from the + * bitmask passed to the constructor if the platform does not + * support measuring all of the requested events. + */ + const EventMask eventsMeasured; + + /* + * Counters for each measurable event. + * Immediately after one of these objects is created, all of the + * counters for enabled events will be zero, and all of the + * counters for disabled events will be uint64_t(-1). + */ + uint64_t cpu_cycles; + uint64_t instructions; + uint64_t cache_references; + uint64_t cache_misses; + uint64_t branch_instructions; + uint64_t branch_misses; + uint64_t bus_cycles; + uint64_t page_faults; + uint64_t major_page_faults; + uint64_t context_switches; + uint64_t cpu_migrations; + + /* + * Prepare to measure the indicated set of events. If not all of + * the requested events can be measured on the current platform, + * then the eventsMeasured bitmask will only include the subset of + * |toMeasure| corresponding to the events that can be measured. + */ + explicit PerfMeasurement(EventMask toMeasure); + + /* Done with this set of measurements, tear down OS-level state. */ + ~PerfMeasurement(); + + /* Start a measurement cycle. */ + void start(); + + /* + * End a measurement cycle, and for each enabled counter, add the + * number of measured events of that type to the appropriate + * visible variable. + */ + void stop(); + + /* Reset all enabled counters to zero. */ + void reset(); + + /* + * True if this platform supports measuring _something_, i.e. it's + * not using the stub implementation. + */ + static bool canMeasureSomething(); +}; + +/* Inject a Javascript wrapper around the above C++ class into the + * Javascript object passed as an argument (this will normally be a + * global object). The JS-visible API is identical to the C++ API. + */ +extern JS_FRIEND_API(JSObject*) + RegisterPerfMeasurement(JSContext* cx, JS::HandleObject global); + +/* + * Given a Value which contains an instance of the aforementioned + * wrapper class, extract the C++ object. Returns nullptr if the + * Value is not an instance of the wrapper. + */ +extern JS_FRIEND_API(PerfMeasurement*) + ExtractPerfMeasurement(const Value& wrapper); + +} // namespace JS + +#endif /* perf_jsperf_h */ |