Using XPerf

From MozillaWiki
Jump to: navigation, search

Note: This page is not for general xperf use. It is specific to the ETW integrated into SpiderMonkey, and is currently a disorganized collection of notes while I figure out what all this crazy stuff is.

Oh, and it turns out there is already an xperf usage page on MDC: https://developer.mozilla.org/En/Profiling_with_Xperf

Random Notes

  • To use custom events like the MozillaSpiderMonkey provider ones, you will start a session using that provider, and then probably start an additional concurrent session for the kernel events of interest. You will merge the event logs together at the end before analyzing them.
  • xperf start command syntax: starts multiple sessions at once (but maybe at most one kernel?)
 xperf -on latency -start sess1 -on MozillaSpiderMonkey

will start a kernel session with the 'latency' group of events, and a user session 'sess1' with the MozillaSpiderMonkey provider's events.

Similarly:

 xperf -stop sess1 -stop

will stop both the kernel session and the user session 'sess1'.

  • Seeing what sessions are logging (?):
 xperf -Loggers | grep Name

will dump out all active loggers. There will be several that you didn't start.

Or, the nice way: run perfmon. Go to "Data Collector Sets"/"Event Trace Sessions". The names here even make sense!

  • when xperf stops a trace, it injects some custom information (string event names?) into the trace to allow cross-machine decoding (so a manifest is not needed), but only xperf knows how to read that data.


Installation Notes

logman, tracerpt, wevtutil, and mofcomp are all installed by default on Windows. (wevtutil only exists for Vista+.)

xperf and xperfview come with the SDK. You can also get a standalone installation from http://www.microsoft.com/whdc/system/sysperf/perftools.mspx


On a 64-bit system, to allow stack traces:

REG ADD "HKLM\System\CurrentControlSet\Control\Session Manager\Memory Management" -v DisablePagingExecutive -d 0x1 -t REG_DWORD -f

and reboot.


wevtutil im path/to/manifest.man -rf:c:/windows/path/to/firefox.exe

or perhaps path to ETWProvider.res. (asuth says: I think for the "rf" setting you want to point at your mozjs.dll (or whatever it has been lumped into) since that's what the manifest defines as the resourceFileName. At least, when I did this, it no longer gave an error message about resources not being accessible.)

Startup

xperf -start test1 -on MozillaSpiderMonkey
dist/bin/firefox.exe -no-remote -P Blank ...
xperf -stop test1


xperf -on PROC_THREAD+LOADER+DISK_IO+HARD_FAULTS+INTERRUPT+DPC+CSWITCH -maxbuffers 1024
(do stuff)
xperf -d foo.etl
xperfview foo.etl

http://blogs.msdn.com/b/pigscanfly/archive/2008/02/16/using-xperf-to-take-a-trace.aspx


http://blogs.msdn.com/b/pigscanfly/archive/2009/08/06/stack-walking-in-xperf.aspx

adapting:

 xperf -on Latency -stackwalk profile -start browse -on MozillaSpiderMonkey:::'stack'
 rem Your scenario goes here...
 xperf -stop browse -stop -d mytrace.etl


using logman:

 logman start mysession -p MozillaSpiderMonkey -o test1.etl -ets
 (dostuff)
 logman stop mysession -ets

Analysis

 tracerpt events.etl -import path/to/manifest.man

will generate dump files of the traces. Very useful for figuring out whether your data got logged. But it seems to mismatch the descriptive strings -- I am getting my provider message ("Event traces for Mozilla SpiderMonkey (Javascript engine)") in place of all event names. The OpCodes are fortunately getting the right names, which is really the most useful thing anyway.

You can't do much with custom events in the current xperfview: http://social.msdn.microsoft.com/Forums/en-US/wptk_v4/thread/2655db5f-6d9f-42db-898a-60c05feffc6b

More Links

This page covers XP and Windows 7 registration, and talks about logman and tracerpt, which are both nice and simple and just about all I can understand right now.

Description of profiling IE, including some IE ETW providers. (We might want to borrow their event sets...)