Blame 0003-New-argument-profile-self-for-profiling-performance.patch

Igor Gnatenko ef6081
From 12d988a668651e1cae570f1be83ae4f3bdb7120c Mon Sep 17 00:00:00 2001
Igor Gnatenko ef6081
From: Nirbheek Chauhan <nirbheek@centricular.com>
Igor Gnatenko ef6081
Date: Wed, 25 Apr 2018 00:02:44 +0530
Igor Gnatenko ef6081
Subject: [PATCH 03/16] New argument: --profile-self for profiling performance
Igor Gnatenko ef6081
Igor Gnatenko ef6081
Outputs two profile logs: one for the interpreter run and another for
Igor Gnatenko ef6081
the backend-specific build file generation. Both are stored in
Igor Gnatenko ef6081
meson-private in the build directory.
Igor Gnatenko ef6081
---
Igor Gnatenko ef6081
 mesonbuild/mesonmain.py | 19 ++++++++++++++++---
Igor Gnatenko ef6081
 1 file changed, 16 insertions(+), 3 deletions(-)
Igor Gnatenko ef6081
Igor Gnatenko ef6081
diff --git a/mesonbuild/mesonmain.py b/mesonbuild/mesonmain.py
Igor Gnatenko ef6081
index 613e953d..f4fec95a 100644
Igor Gnatenko ef6081
--- a/mesonbuild/mesonmain.py
Igor Gnatenko ef6081
+++ b/mesonbuild/mesonmain.py
Igor Gnatenko ef6081
@@ -15,10 +15,12 @@
Igor Gnatenko ef6081
 import sys, stat, traceback, argparse
Igor Gnatenko ef6081
 import datetime
Igor Gnatenko ef6081
 import os.path
Igor Gnatenko ef6081
+import platform
Igor Gnatenko ef6081
+import cProfile as profile
Igor Gnatenko ef6081
+
Igor Gnatenko ef6081
 from . import environment, interpreter, mesonlib
Igor Gnatenko ef6081
 from . import build
Igor Gnatenko ef6081
 from . import mconf, mintro, mtest, rewriter, minit
Igor Gnatenko ef6081
-import platform
Igor Gnatenko ef6081
 from . import mlog, coredata
Igor Gnatenko ef6081
 from .mesonlib import MesonException
Igor Gnatenko ef6081
 from .wrap import WrapMode, wraptool
Igor Gnatenko ef6081
@@ -38,6 +40,8 @@ def create_parser():
Igor Gnatenko ef6081
     p.add_argument('--wrap-mode', default=WrapMode.default,
Igor Gnatenko ef6081
                    type=wrapmodetype, choices=WrapMode,
Igor Gnatenko ef6081
                    help='Special wrap mode to use')
Igor Gnatenko ef6081
+    p.add_argument('--profile-self', action='store_true', dest='profile',
Igor Gnatenko ef6081
+                   help=argparse.SUPPRESS)
Igor Gnatenko ef6081
     p.add_argument('directories', nargs='*')
Igor Gnatenko ef6081
     return p
Igor Gnatenko ef6081
 
Igor Gnatenko ef6081
@@ -176,7 +180,11 @@ class MesonApp:
Igor Gnatenko ef6081
             mlog.log('Target machine cpu:', mlog.bold(intr.builtin['target_machine'].cpu_method([], {})))
Igor Gnatenko ef6081
         mlog.log('Build machine cpu family:', mlog.bold(intr.builtin['build_machine'].cpu_family_method([], {})))
Igor Gnatenko ef6081
         mlog.log('Build machine cpu:', mlog.bold(intr.builtin['build_machine'].cpu_method([], {})))
Igor Gnatenko ef6081
-        intr.run()
Igor Gnatenko ef6081
+        if self.options.profile:
Igor Gnatenko ef6081
+            fname = os.path.join(self.build_dir, 'meson-private', 'profile-interpreter.log')
Igor Gnatenko ef6081
+            profile.runctx('intr.run()', globals(), locals(), filename=fname)
Igor Gnatenko ef6081
+        else:
Igor Gnatenko ef6081
+            intr.run()
Igor Gnatenko ef6081
         try:
Igor Gnatenko ef6081
             dumpfile = os.path.join(env.get_scratch_dir(), 'build.dat')
Igor Gnatenko ef6081
             # We would like to write coredata as late as possible since we use the existence of
Igor Gnatenko ef6081
@@ -186,7 +194,12 @@ class MesonApp:
Igor Gnatenko ef6081
             # sync with the time that gets applied to any files. Thus, we dump this file as late as
Igor Gnatenko ef6081
             # possible, but before build files, and if any error occurs, delete it.
Igor Gnatenko ef6081
             cdf = env.dump_coredata()
Igor Gnatenko ef6081
-            g.generate(intr)
Igor Gnatenko ef6081
+            if self.options.profile:
Igor Gnatenko ef6081
+                fname = 'profile-{}-backend.log'.format(self.options.backend)
Igor Gnatenko ef6081
+                fname = os.path.join(self.build_dir, 'meson-private', fname)
Igor Gnatenko ef6081
+                profile.runctx('g.generate(intr)', globals(), locals(), filename=fname)
Igor Gnatenko ef6081
+            else:
Igor Gnatenko ef6081
+                g.generate(intr)
Igor Gnatenko ef6081
             build.save(b, dumpfile)
Igor Gnatenko ef6081
             # Post-conf scripts must be run after writing coredata or else introspection fails.
Igor Gnatenko ef6081
             g.run_postconf_scripts()
Igor Gnatenko ef6081
-- 
Igor Gnatenko ef6081
2.17.0
Igor Gnatenko ef6081