PerfMeasurement.jsm 编辑

The PerfMeasurement.jsm JavaScript code module lets you take detailed performance measurements of your code.

Note: The PerfMeasurement.jsm JavaScript code module can only be used from chrome -- that is, from within the application itself or an add-on.

Before you can use this module, you need to import it into your scope:

Components.utils.import("resource://gre/modules/PerfMeasurement.jsm")

See Measuring performance using the PerfMeasurement.jsm code module for details on how to use this API.

Note: At present, PerfMeasurement.jsm is only functional on Linux, but it is planned to add support for Windows (bug 583322) and OSX (bug 583323) as well, and we welcome patches for other operating systems.

Method overview

static bool canMeasureSomething();
void reset();
void start();
void stop();

Member fields

Recorded data variables

These variables provide access to the recorded data. Any measurable event that was not being recorded has a value of -1 (that is, 0xFFFFFFFFFFFFFFFF).

Note: These values are all zeroed (or set to -1, for events not being measured) when you initialize the PerfMeasurement object, then they are not zeroed again unless you explicitly call the reset() method. This lets you accumulate measurements over multiple passes through code that you want to analyze.
VariableTypeDescription
cpu_cyclesuint64
The number of CPU cycles elapsed.
instructions
uint64
The number of instructions executed.
cache_references
uint64
The number of memory accesses that occurred.
cache_misses
uint64
The number of times memory accesses missed the cache.
branch_instructions
uint64
The number of branch instructions executed.
branch_misses
uint64
The number of times branch prediction guessed wrong.
bus_cycles
uint64
The number of memory bus cycles that elapsed.
page_faults
uint64
The number of page exceptions the OS handled.
major_page_faults
uint64
The number of times page faults required disk access.
context_switches
uint64
The number of context switches that occurred involving the thread being profiled.
cpu_migrations
uint64
The number of times the profiled thread migrated from one CPU core to another.

Event types measured constant

The eventsMeasured constant provides a mask indicating which event types were recorded.

VariableTypeDescription
eventsMeasuredEventMask
A bit mask of the event types recorded; this can differ from the events requested if the platform doesn't support all of the event types you specified when creating the PerfMeasurement object.

Constants

Event mask constants

These constants are used to construct the mask indicating which events you want to monitor.

ConstantValueDescription
CPU_CYCLES0x00000001Measure CPU cycles elapsed.
INSTRUCTIONS0x00000002Measure the number of instructions executed.
CACHE_REFERENCES0x00000004Measure the number of cache references.
CACHE_MISSES0x00000008Measure the number of cache misses.
BRANCH_INSTRUCTIONS0x00000010Measure the number of branch instructions executed.
BRANCH_MISSES0x00000020Measure the number of times branch prediction guesses wrong.
BUS_CYCLES0x00000040Measure the number of bus cycles elapsed.
PAGE_FAULTS0x00000080Measure the number of page faults that occurred.
MAJOR_PAGE_FAULTS0x00000100Measure the number of major page faults that occurred.
CONTEXT_SWITCHES0x00000200Measure the number of context switches that occurred.
CPU_MIGRATIONS0x00000400Measure the number of context switches that occurred.
ALL0x000007FFMeasure all available events.

Number of available event types

The NUM_MEASURABLE_EVENTS constant tells you how many types of events can be measured.

ConstantValueDescription
NUM_MEASURABLE_EVENTS11The number of types of events that can be measured.

Constructor

Creates a new PerfMeasurement object, configured to record the specified event types.

PerfMeasurement(
  EventMask toMeasure
);
Parameters
toMeasure
A mask of all of the event types you want to record; see Event mask constants for a list of values. OR together all the event types you want to record, and pass that value here. Pass PerfMeasurement.ALL to record all event types.
Return value

A new PerfMeasurement object configured to record the specified event types.

Methods

canMeasureSomething()

Indicates whether or not the platform on which your code is running supports this code module.

static bool canMeasureSomething();
Parameters

None.

Return value

If even one of the event types can be recorded, this will return true. Otherwise, it returns false.

reset()

Resets all the enabled counters to zero.

void reset();
Parameters

None.

start()

Starts measuring the performance indicators that were specified when the PerfMeasurement object was created.

void start();
Parameters

None.

stop()

Stops measuring performance data. For each enabled counter, the number of measured events of that type that occurred are added to the appropriate visible variable.

void stop();
Parameters

None.

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:76 次

字数:10971

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文