aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUsta Shrestha <usta@google.com>2023-02-28 09:46:15 -0500
committerUsta Shrestha <usta@google.com>2023-03-02 18:25:39 -0500
commit72f90ca21d635165f4819a658a717390016755d3 (patch)
tree98d41e21c80ef84878bf8c06b333f9cf3bc3e644
parent1c7556010ce961d7cb9482df8c8b70cd7b5fcb5f (diff)
downloadbazel-72f90ca21d635165f4819a658a717390016755d3.tar.gz
format timestamp as hh:mm:ss.sss
Test: ./incremental_build.py -c 'no change' -- nothing Bug: NA Change-Id: I23d03d1d7938fbbb575945c36712cc9a411d8eb9
-rwxr-xr-xscripts/incremental_build/incremental_build.py2
-rwxr-xr-xscripts/incremental_build/perf_metrics.py6
-rw-r--r--scripts/incremental_build/util.py14
-rw-r--r--scripts/incremental_build/util_test.py12
4 files changed, 27 insertions, 7 deletions
diff --git a/scripts/incremental_build/incremental_build.py b/scripts/incremental_build/incremental_build.py
index 629cace2..983caade 100755
--- a/scripts/incremental_build/incremental_build.py
+++ b/scripts/incremental_build/incremental_build.py
@@ -139,7 +139,7 @@ def _build(build_type: ui.BuildType, logfile: Path) -> (int, BuildInfo):
'log': str(logfile.relative_to(ui.get_user_input().log_dir)),
'ninja_explains': util.count_explanations(logfile),
'actions': action_count_after - action_count_before,
- 'time': str(datetime.timedelta(microseconds=elapsed_ns / 1000))
+ 'time': util.hhmmss(datetime.timedelta(microseconds=elapsed_ns / 1000))
})
diff --git a/scripts/incremental_build/perf_metrics.py b/scripts/incremental_build/perf_metrics.py
index 0ee4b253..de1079f6 100755
--- a/scripts/incremental_build/perf_metrics.py
+++ b/scripts/incremental_build/perf_metrics.py
@@ -81,7 +81,7 @@ def archive_run(d: Path, build_info: dict[str, any]):
json.dump(build_info, f, indent=True)
-def read_pbs(d: Path) -> dict[str, datetime.timedelta]:
+def read_pbs(d: Path) -> dict[str, str]:
"""
Reads metrics data from pb files and archives the file by copying
them under the log_dir.
@@ -110,8 +110,8 @@ def read_pbs(d: Path) -> dict[str, datetime.timedelta]:
def normalize(desc: str) -> str:
return re.sub(r'^(?:soong_build|mixed_build)', '*', desc)
- return {f'{m.name}/{normalize(m.description)}': str(m.real_time) for m in
- events}
+ return {f'{m.name}/{normalize(m.description)}': util.hhmmss(m.real_time) for m
+ in events}
def _read_pb(
diff --git a/scripts/incremental_build/util.py b/scripts/incremental_build/util.py
index 28eafd8e..fdc28a14 100644
--- a/scripts/incremental_build/util.py
+++ b/scripts/incremental_build/util.py
@@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import csv
+import datetime
import functools
import glob
import logging
@@ -30,9 +31,9 @@ RUN_DIR_PREFIX: Final[str] = 'run'
BUILD_INFO_JSON: Final[str] = 'build_info.json'
_IMPORTANT_METRICS: set[str] = {r'soong/bootstrap', r'soong_build/\*\.bazel',
- r'ninja/ninja', r'bp2build/',
- r'symlink_forest/',
- r'.*write_files.*'}
+ r'ninja/ninja', r'bp2build/',
+ r'symlink_forest/',
+ r'.*write_files.*'}
@functools.cache
@@ -241,3 +242,10 @@ def any_match_under(root: Path, *patterns: str) -> (Path, list[str]):
children.sort()
bfs.extend(children)
raise RuntimeError(f'No suitable directory for {patterns}')
+
+
+def hhmmss(t: datetime.timedelta) -> str:
+ h, f = divmod(t.seconds, 60 * 60)
+ m, f = divmod(f, 60)
+ s = f + t.microseconds / 1000_000
+ return f'{h:02d}:{m:02d}:{s:06.3f}'
diff --git a/scripts/incremental_build/util_test.py b/scripts/incremental_build/util_test.py
index 204d99f5..0e68bc3a 100644
--- a/scripts/incremental_build/util_test.py
+++ b/scripts/incremental_build/util_test.py
@@ -11,12 +11,14 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
+import datetime
import os
import unittest
from util import _next_path_helper
from util import any_match
from util import get_top_dir
+from util import hhmmss
class UtilTest(unittest.TestCase):
@@ -73,3 +75,13 @@ class UtilTest(unittest.TestCase):
for _, dirs, files in os.walk(path):
self.assertFalse('BUILD' in dirs)
self.assertFalse('BUILD' in files)
+
+ def test_hhmmss(self):
+ examples = [
+ (datetime.timedelta(seconds=(2 * 60 + 5)), '00:02:05.000'),
+ (datetime.timedelta(seconds=(3600 + 23 * 60 + 45.897898)),
+ '01:23:45.898'),
+ ]
+ for (ts, expected) in examples:
+ self.subTest(ts=ts, expected=expected)
+ self.assertEqual(hhmmss(ts), expected)