Bug 1892641 - include timestamps in BUILDSTATUS lines from gradle, r=glandium.

Differential Revision: https://phabricator.services.mozilla.com/D208531
This commit is contained in:
Florian Quèze 2024-04-30 08:17:13 +00:00
parent b0f26d11ff
commit 9118178e3b
3 changed files with 30 additions and 9 deletions

View file

@ -72,6 +72,11 @@ def getRustVersionFor(packageName) {
return version
}
def now() {
Instant now = Instant.now();
return now.getEpochSecond() + now.getNano() / 1_000_000_000L;
}
allprojects {
def shouldPrintBuildStatus =
System.getenv("MACH") && !System.getenv("NO_BUILDSTATUS_MESSAGES")
@ -80,23 +85,23 @@ allprojects {
// Adding new line before each line to make sure they're dumped as a separate line.
// Add profile marker to the start of the project evaluation
project.beforeEvaluate {
println "\nBUILDSTATUS START_gradle:evaluate-project ${project.name}"
println "\nBUILDSTATUS ${now()} START_gradle:evaluate-project ${project.name}"
}
// Add profile marker to the end of the project evaluation
project.afterEvaluate {
println "\nBUILDSTATUS END_gradle:evaluate-project ${project.name}"
println "\nBUILDSTATUS ${now()} END_gradle:evaluate-project ${project.name}"
}
tasks.configureEach { task ->
// Add profile marker to the start of the gradle task
task.doFirst {
println "\nBUILDSTATUS START_gradle:${project.name}-tasks ${task.name}"
println "\nBUILDSTATUS ${now()} START_gradle-task ${project.name}:${task.name}"
}
// Add profile marker to the end of the gradle task
task.doLast {
println "\nBUILDSTATUS END_gradle:${project.name}-tasks ${task.name}"
println "\nBUILDSTATUS ${now()} END_gradle-task ${project.name}:${task.name}"
}
}
}

View file

@ -263,6 +263,12 @@ class BuildMonitor(MozbuildObject):
_, _, disambiguator = args.pop(0).partition("@")
action = args.pop(0)
time = None
regexp = re.compile(r"\d{10}(\.\d{1,9})?$")
if regexp.match(action):
time = float(action)
action = args.pop(0)
update_needed = True
if action == "TIERS":
@ -280,12 +286,12 @@ class BuildMonitor(MozbuildObject):
update_needed = False
elif action.startswith("START_"):
self.resources.begin_marker(
action[len("START_") :], " ".join(args), disambiguator
action[len("START_") :], " ".join(args), disambiguator, time
)
update_needed = False
elif action.startswith("END_"):
self.resources.end_marker(
action[len("END_") :], " ".join(args), disambiguator
action[len("END_") :], " ".join(args), disambiguator, time
)
update_needed = False
elif action == "BUILD_VERBOSE":

View file

@ -314,6 +314,7 @@ class SystemResourceMonitor(object):
self._swap_type = type(swap)
self._swap_len = len(swap)
self.start_timestamp = time.time()
self.start_time = time.monotonic()
self._pipe, child_pipe = multiprocessing.Pipe(True)
@ -328,6 +329,9 @@ class SystemResourceMonitor(object):
self._pipe.send(("terminate",))
self._process.join()
def convert_to_monotonic_time(self, timestamp):
return timestamp - self.start_timestamp + self.start_time
# Methods to control monitoring.
def start(self):
@ -458,18 +462,24 @@ class SystemResourceMonitor(object):
SystemResourceMonitor.instance.markers.append((name, start, end, text))
@staticmethod
def begin_marker(name, text, disambiguator=None):
def begin_marker(name, text, disambiguator=None, timestamp=None):
if SystemResourceMonitor.instance:
id = name + ":" + text
if disambiguator:
id += ":" + disambiguator
SystemResourceMonitor.instance._active_markers[id] = time.monotonic()
SystemResourceMonitor.instance._active_markers[id] = (
SystemResourceMonitor.instance.convert_to_monotonic_time(timestamp)
if timestamp
else time.monotonic()
)
@staticmethod
def end_marker(name, text, disambiguator=None):
def end_marker(name, text, disambiguator=None, timestamp=None):
if not SystemResourceMonitor.instance:
return
end = time.monotonic()
if timestamp:
end = SystemResourceMonitor.instance.convert_to_monotonic_time(timestamp)
id = name + ":" + text
if disambiguator:
id += ":" + disambiguator