Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Unified Diff: tools/lua/find_ngrams_on_ct

Issue 1216073007: Add wrapper script for computing n-grams from SKPs on Cluster Telemetry (Closed) Base URL: https://skia.googlesource.com/skia.git@lua
Patch Set: Fixes Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tools/lua/ngrams.lua » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/lua/find_ngrams_on_ct
diff --git a/tools/lua/find_ngrams_on_ct b/tools/lua/find_ngrams_on_ct
new file mode 100755
index 0000000000000000000000000000000000000000..be3e4c07f16ba4d19e2f7f065de1812ae44031eb
--- /dev/null
+++ b/tools/lua/find_ngrams_on_ct
@@ -0,0 +1,61 @@
+#!/usr/bin/env python
+
+
+"""Run Cluster Telemetry to compute n-grams from SKPs."""
+
+
+import argparse
+import os
+import re
+import subprocess
+import sys
+import tempfile
+
+
+NGRAMS_LUA_SUBSTITUTION_STR = '-- CHANGEME\nlocal n = \d+\n-- CHANGEME'
+SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
+
+
+def main():
+ # Parse arguments.
+ parser = argparse.ArgumentParser(
+ description='Run Cluster Telemetry to compute n-grams from SKPs.')
+ parser.add_argument('--n', help='Compute n-grams with this integer as N',
+ required=True)
+ args, extra_args = parser.parse_known_args()
+
+ # Read the n-gram Lua script.
+ script_path = os.path.join(SCRIPT_DIR, 'ngrams.lua')
+ with open(script_path) as f:
+ script_contents = f.read()
+
+ # Replace the default value of n with the value specified by the user.
+ new_contents, subd = re.subn(NGRAMS_LUA_SUBSTITUTION_STR,
+ 'local n = %s' % args.n, script_contents, 1)
+ if subd != 1:
+ raise Exception('Unable to replace N in %s; expected to find:\n%s' % (
+ script_path, sub))
+
+ # Write the new script contents to a temporary file.
+ tmp_script = tempfile.NamedTemporaryFile(delete=False)
+ try:
+ tmp_script.write(new_contents)
+ tmp_script.close()
rmistry 2015/06/30 17:05:12 Move the close into the finally?
borenet 2015/06/30 17:16:02 Doesn't matter for Unix, but on Windows we won't b
+
+ # Run trigger_ct_lua with the new script, forwarding the rest of the
+ # passed-in arguments to the script.
+ trigger_ct_lua = os.path.join(SCRIPT_DIR, 'trigger_ct_lua')
+ cmd = ['python', trigger_ct_lua,
+ '--script', tmp_script.name,
+ '--aggregator', os.path.join(SCRIPT_DIR, 'ngrams_aggregate.lua')]
+ cmd.extend(extra_args)
+ try:
+ subprocess.check_call(cmd)
+ except subprocess.CalledProcessError:
+ exit(1)
+ finally:
+ os.remove(tmp_script.name)
+
+
+if __name__ == '__main__':
+ main()
« no previous file with comments | « no previous file | tools/lua/ngrams.lua » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698