[autotest] Post processing script for suite time breakdown

This script measures nine stats for a suite run.
1. Net suite runtime.
2. Suite scheduling overhead.
3. Average scheduling overhead.
4. Average Queuing time.
5. Average Resetting time.
6. Average provisioning time.
7. Average Running time.
8. Average Parsing time.
9. Average Gathering time.

BUG=chromium:426118
TEST=run ./site_utils/collect_suite_time_stats.py on local machine

Change-Id: I8e4cd30cd0ce4fbb1801f277824a0c652f933f08
Reviewed-on: https://chromium-review.googlesource.com/227467
Reviewed-by: Fang Deng <fdeng@chromium.org>
Tested-by: Mungyung Ryu <mkryu@google.com>
Commit-Queue: Mungyung Ryu <mkryu@google.com>
diff --git a/server/site_utils.py b/server/site_utils.py
index 3c01d34..22479e9 100644
--- a/server/site_utils.py
+++ b/server/site_utils.py
@@ -351,3 +351,45 @@
     """
     dirname = os.path.dirname(sub.rstrip('/'))
     return os.path.join(base, dirname.strip('/'))
+
+
+def get_data_key(prefix, suite, build, board):
+    """
+    Constructs a key string from parameters.
+
+    @param prefix: Prefix for the generating key.
+    @param suite: a suite name. e.g., bvt-cq, bvt-inline, dummy
+    @param build: The build string. This string should have a consistent
+        format eg: x86-mario-release/R26-3570.0.0. If the format of this
+        string changes such that we can't determine build_type or branch
+        we give up and use the parametes we're sure of instead (suite,
+        board). eg:
+            1. build = x86-alex-pgo-release/R26-3570.0.0
+               branch = 26
+               build_type = pgo-release
+            2. build = lumpy-paladin/R28-3993.0.0-rc5
+               branch = 28
+               build_type = paladin
+    @param board: The board that this suite ran on.
+    @return: The key string used for a dictionary.
+    """
+    try:
+        _board, build_type, branch = ParseBuildName(build)[:3]
+    except ParseBuildNameException as e:
+        logging.error(str(e))
+        branch = 'Unknown'
+        build_type = 'Unknown'
+    else:
+        embedded_str = re.search(r'x86-\w+-(.*)', _board)
+        if embedded_str:
+            build_type = embedded_str.group(1) + '-' + build_type
+
+    data_key_dict = {
+        'prefix': prefix,
+        'board': board,
+        'branch': branch,
+        'build_type': build_type,
+        'suite': suite,
+    }
+    return ('%(prefix)s.%(board)s.%(build_type)s.%(branch)s.%(suite)s'
+            % data_key_dict)