[LNT] r263881 - [profile] Add a rule hook to update the profile statistics

James Molloy via llvm-commits llvm-commits at lists.llvm.org
Sat Mar 19 07:46:56 PDT 2016


Author: jamesm
Date: Sat Mar 19 09:46:56 2016
New Revision: 263881

URL: http://llvm.org/viewvc/llvm-project?rev=263881&view=rev
Log:
[profile] Add a rule hook to update the profile statistics

This rule runs after submission and inspects the profile directory, discovering
the total size of all profiles and the age distribution of the profiles. It stores
these in two JSON files that are read by /profile/admin

Added:
    lnt/trunk/lnt/server/db/rules/rule_update_profile_stats.py

Added: lnt/trunk/lnt/server/db/rules/rule_update_profile_stats.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/db/rules/rule_update_profile_stats.py?rev=263881&view=auto
==============================================================================
--- lnt/trunk/lnt/server/db/rules/rule_update_profile_stats.py (added)
+++ lnt/trunk/lnt/server/db/rules/rule_update_profile_stats.py Sat Mar 19 09:46:56 2016
@@ -0,0 +1,35 @@
+"""
+Post submission hook to write the current state of the profiles directory. This
+gets fed into the profile/admin page.
+"""
+import json, datetime, os, subprocess, glob, time
+
+def update_profile_stats(ts, run_id):
+    config = ts.v4db.config
+
+    history_path = os.path.join(config.profileDir, '_profile-history.json')
+    age_path = os.path.join(config.profileDir, '_profile-age.json')
+    profile_path = config.profileDir
+
+    try:
+        history = json.loads(open(history_path).read())
+    except:
+        history = []
+    age = []
+
+    dt = time.time()
+    blocks = subprocess.check_output("du -s -B 1024 %s" % profile_path,
+                                     shell=True).split('\t')[0]
+    kb = float(blocks) # 1024 byte blocks.
+
+    history.append((dt, kb))
+
+    for f in glob.glob('%s/*.lntprof' % profile_path):
+        mtime = os.stat(f).st_mtime
+        sz = os.stat(f).st_size / 1000
+        age.append([mtime, sz])
+    
+    open(history_path, 'w').write(json.dumps(history))
+    open(age_path, 'w').write(json.dumps(age))
+
+post_submission_hook = update_profile_stats




More information about the llvm-commits mailing list