]> git.ozlabs.org Git - hiprofile/blobdiff - hiprofile.py
Include package & version info in report footers
[hiprofile] / hiprofile.py
index c1d1052e2f7513f3f153963c7857f9bff398c343..6f99d3c3e176338653b45736d4fc1be34d5a04f4 100644 (file)
@@ -11,6 +11,12 @@ from jinja2 import Environment, FileSystemLoader
 b_id = 0
 s_id = 0
 
+try:
+    __version__ = __import__('pkg_resources') \
+                    .get_distribution('hiprofile').version
+except Exception:
+    __version__ = 'unknown'
+
 def _get_count(node):
     """ Utility function: return the number in a 'count' element contained in
         the current node"""
@@ -319,14 +325,18 @@ def write_report(report, resourcedir, outdir):
         shutil.copy(os.path.join(resourcedir, file), outdir)
 
     reportfile = os.path.join(outdir, 'index.html')
-    templates['report'].stream(report = report).dump(reportfile)
+    templates['report'].stream(version = __version__,
+                               report = report).dump(reportfile)
 
     for binary in report.binaries:
         binaryfile = os.path.join(outdir, binary.filename())
-        templates['binary'].stream(report = report, binary = binary). \
-                            dump(binaryfile)
+        templates['binary'].stream(version = __version__,
+                                   report = report,
+                                   binary = binary) \
+                                    .dump(binaryfile)
 
         for symbol in binary.references:
             symbolfile = os.path.join(outdir, symbol.filename())
-            templates['symbol'].stream(report = report, binary = binary,
+            templates['symbol'].stream(version = __version__,
+                                       report = report, binary = binary,
                                        symbol = symbol).dump(symbolfile)