From e4417eb301bab96c343c5b95f074d1900706b667 Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Thu, 5 Jul 2018 23:23:49 +0530 Subject: [PATCH] mlog: Log timestamps in profile-self mode This makes it much clearer which statements are taking a long time, and helps in interpreting the outputted profile itself. --- mesonbuild/mesonmain.py | 3 +++ mesonbuild/mlog.py | 13 ++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/mesonbuild/mesonmain.py b/mesonbuild/mesonmain.py index 8a196313b..1aca9c61a 100644 --- a/mesonbuild/mesonmain.py +++ b/mesonbuild/mesonmain.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import time import sys, stat, traceback, argparse import datetime import os.path @@ -110,6 +111,8 @@ class MesonApp: def generate(self): env = environment.Environment(self.source_dir, self.build_dir, self.options) mlog.initialize(env.get_log_dir()) + if self.options.profile: + mlog.set_timestamp_start(time.monotonic()) with mesonlib.BuildDirLock(self.build_dir): self._generate(env) diff --git a/mesonbuild/mlog.py b/mesonbuild/mlog.py index 3baa07a00..b763e2000 100644 --- a/mesonbuild/mlog.py +++ b/mesonbuild/mlog.py @@ -12,7 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. -import sys, os, platform, io +import os +import io +import sys +import time +import platform from contextlib import contextmanager """This is (mostly) a standalone module used to write logging @@ -41,12 +45,17 @@ log_dir = None log_file = None log_fname = 'meson-log.txt' log_depth = 0 +log_timestamp_start = None def initialize(logdir): global log_dir, log_file log_dir = logdir log_file = open(os.path.join(logdir, log_fname), 'w', encoding='utf8') +def set_timestamp_start(start): + global log_timestamp_start + log_timestamp_start = start + def shutdown(): global log_file if log_file is not None: @@ -87,6 +96,8 @@ def cyan(text): def process_markup(args, keep): arr = [] + if log_timestamp_start is not None: + arr = ['[{:.3f}]'.format(time.monotonic() - log_timestamp_start)] for arg in args: if isinstance(arg, str): arr.append(arg)