Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 1f656d5

Browse files
committed
Bug 1956843 - ./mach test <path to xpcshell test file> --profiler should work, r=jmaher.
Differential Revision: https://phabricator.services.mozilla.com/D243324
1 parent 3a67f5b commit 1f656d5

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

testing/xpcshell/runxpcshelltests.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030

3131
import mozdebug
3232
import six
33+
from mozgeckoprofiler import (
34+
symbolicate_profile_json,
35+
view_gecko_profile,
36+
)
3337
from mozserve import Http3Server
3438

3539
try:
@@ -224,6 +228,7 @@ def __init__(
224228
self.timeoutAsPass = kwargs.get("timeoutAsPass")
225229
self.crashAsPass = kwargs.get("crashAsPass")
226230
self.conditionedProfileDir = kwargs.get("conditionedProfileDir")
231+
self.profiler = kwargs.get("profiler")
227232
if self.runFailures:
228233
self.retry = False
229234

@@ -859,6 +864,18 @@ def run_test(self):
859864
if self.test_object.get("subprocess") == "true":
860865
self.env["PYTHON"] = sys.executable
861866

867+
if self.profiler:
868+
if not self.singleFile:
869+
self.log.error(
870+
"The --profiler flag is currently only supported when running a single test"
871+
)
872+
else:
873+
self.env["MOZ_PROFILER_STARTUP"] = "1"
874+
profile_path = os.path.join(
875+
self.profileDir, "profile_" + os.path.basename(name) + ".json"
876+
)
877+
self.env["MOZ_PROFILER_SHUTDOWN"] = profile_path
878+
862879
if (
863880
self.test_object.get("headless", "true" if self.headless else None)
864881
== "true"
@@ -1041,6 +1058,9 @@ def run_test(self):
10411058

10421059
finally:
10431060
self.postCheck(proc)
1061+
if self.profiler and self.singleFile:
1062+
symbolicate_profile_json(profile_path, self.symbolsPath)
1063+
view_gecko_profile(profile_path)
10441064
self.clean_temp_dirs(path)
10451065

10461066
if gotSIGINT:
@@ -1832,6 +1852,7 @@ def runTests(self, options, testClass=XPCShellTestThread, mobileArgs=None):
18321852
self.conditionedProfile = options.get("conditionedProfile")
18331853
self.repeat = options.get("repeat", 0)
18341854
self.variant = options.get("variant", "")
1855+
self.profiler = options.get("profiler")
18351856

18361857
if self.variant == "msix":
18371858
self.appPath = options.get("msixAppPath")
@@ -1999,6 +2020,7 @@ def runTests(self, options, testClass=XPCShellTestThread, mobileArgs=None):
19992020
"crashAsPass": self.crashAsPass,
20002021
"conditionedProfileDir": self.conditioned_profile_dir,
20012022
"repeat": self.repeat,
2023+
"profiler": self.profiler,
20022024
}
20032025

20042026
if self.sequential:

testing/xpcshell/xpcshellcommandline.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,15 @@ def add_common_arguments(parser):
366366
dest="repeat",
367367
help="repeat the test X times, default [0]",
368368
)
369+
parser.add_argument(
370+
"--profiler",
371+
action="store_true",
372+
default=False,
373+
dest="profiler",
374+
help="Run the Firefox Profiler and get a performance profile of the "
375+
"test. This is useful to find performance issues, and also "
376+
"to see what exactly the test is doing.",
377+
)
369378

370379

371380
def add_remote_arguments(parser):

0 commit comments

Comments
 (0)