[pitivi] pitivi: Add support for easy profiling the app



commit 9eb94e6bd3323f25fa256074ff536606c9bf2646
Author: Thibault Saunier <tsaunier gnome org>
Date:   Wed Aug 9 09:24:14 2017 -0400

    pitivi: Add support for easy profiling the app
    
    And document it.
    
    Reviewed-by: Alex Băluț <<alexandru balut gmail com>>
    Differential Revision: https://phabricator.freedesktop.org/D1822

 bin/pitivi.in   |   10 +++++++++-
 docs/HACKING.md |   26 ++++++++++++++++++++++++++
 2 files changed, 35 insertions(+), 1 deletions(-)
---
diff --git a/bin/pitivi.in b/bin/pitivi.in
index e8b35b7..3a2cf15 100755
--- a/bin/pitivi.in
+++ b/bin/pitivi.in
@@ -18,6 +18,7 @@
 # Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 # Boston, MA 02110-1301, USA.
 
+import cProfile
 import os
 import sys
 import signal
@@ -155,4 +156,11 @@ if __name__ == "__main__":
     # We do these checks on every startup (even outside the dev environment, for
     # soft deps); doing imports and gst registry checks has near-zero cost.
     _check_requirements()
-    _run_pitivi()
+    run_profile = os.environ.get("PITIVI_PROFILING", False)
+
+    if run_profile:
+        prof = cProfile.Profile()
+        res = prof.runcall(_run_pitivi)
+        prof.dump_stats("pitivi-runstats")
+    else:
+        _run_pitivi()
diff --git a/docs/HACKING.md b/docs/HACKING.md
index 64c70fc..42d90da 100644
--- a/docs/HACKING.md
+++ b/docs/HACKING.md
@@ -250,3 +250,29 @@ The name of a callback method should:
 You can guess the order of the imported modules by looking at some py files.
 The pre-commit hook has authority in this case as it will reorder the imports
 if the order is not good.
+
+## Profiling Pitivi
+
+To profile a pitivi run, simply set the PITIVI_PROFILING environment variable to 1, like so:
+
+```
+$ PITIVI_PROFILING=1 pitivi
+```
+
+A file named `pitivi-runstats` will be created in the current directory, a handy tool to examine it is 
`gprof2dot.py`, install it with:
+
+```
+$ pip install gprof2dot
+```
+
+Then run:
+
+```
+$ gprof2dot -f pstats pitivi-runstats | dot -Tsvg -o profile.svg
+```
+
+You can then inspect the call tree profile with your preferred image viewer:
+
+```
+$ xdg-open profile.svg
+```


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]