user_activity: Added scripts for collecting the experiment data sets.

BUG=None
TEST=None

Change-Id: I7b00ce4359cb378e45bb673e023c12137d03e9b8
Reviewed-on: https://chrome-internal-review.googlesource.com/287959
Tested-by: Evelina Dumitrescu <evelinad@google.com>
Reviewed-by: George Burgess <gbiv@google.com>
Reviewed-by: Ting-Yuan Huang <laszio@google.com>
Reviewed-by: Evelina Dumitrescu <evelinad@google.com>
Reviewed-on: https://chromium-review.googlesource.com/435909
Commit-Ready: Luis Lozano <llozano@chromium.org>
Tested-by: Luis Lozano <llozano@chromium.org>
Reviewed-by: Luis Lozano <llozano@chromium.org>
diff --git a/user_activity_benchmarks/collect_experiment_data.sh b/user_activity_benchmarks/collect_experiment_data.sh
new file mode 100755
index 0000000..8ba0852
--- /dev/null
+++ b/user_activity_benchmarks/collect_experiment_data.sh
@@ -0,0 +1,88 @@
+#!/bin/bash
+
+# Copyright 2016 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+# Uses Dremel queries to collect the inclusive and pairwise inclusive
+# statistics.
+
+set -e
+
+if [ "$#" -ne 6 ]; then
+  echo "USAGE: collect_validation_data.sh cwp_table board board_arch " \
+  "Chrome_OS_release inclusive_output_file pairwise_inclusive_output_file"
+  exit 1
+fi
+
+readonly TABLE=$1
+readonly INCLUSIVE_OUTPUT_FILE=$5
+readonly PAIRWISE_INCLUSIVE_OUTPUT_FILE=$6
+readonly PERIODIC_COLLECTION=1
+readonly WHERE_CLAUSE_SPECIFICATIONS="meta.cros.board = '$2' AND " \
+    "meta.cros.cpu_architecture = '$3' AND meta.cros.chrome_version LIKE " \
+    "'%$4%' AND meta.cros.collection_info.trigger_event = $PERIODIC_COLLECTION"
+
+# Collects the function, with its file, the object and inclusive count
+# fraction out of the total amount of inclusive count values.
+echo "set sql_dialect GoogleSQL;
+
+SELECT
+  replace(frame.function_name, \", \", \"; \") AS function,
+  frame.filename AS file,
+  frame.load_module_path AS dso,
+  SUM(frame.inclusive_count)/ANY_VALUE(total.value) AS inclusive_count_fraction
+FROM
+  $TABLE table,
+  table.frame frame
+CROSS JOIN (
+  SELECT
+    SUM(count) AS value
+  FROM
+    $TABLE
+  WHERE
+    $WHERE_CLAUSE_SPECIFICATIONS
+) AS total
+WHERE
+  $WHERE_CLAUSE_SPECIFICATIONS
+GROUP BY
+  function,
+  file,
+  dso
+HAVING
+  inclusive_count_fraction > 0.0
+ORDER BY
+  inclusive_count_fraction DESC;
+" | dremel --output=csv > "$INCLUSIVE_OUTPUT_FILE"
+
+# Collects the pair of parent and child functions, with the file and object
+# where the child function is declared and the inclusive count fraction of the
+# pair out of the total amount of inclusive count values.
+echo "set sql_dialect GoogleSQL;
+
+SELECT
+  CONCAT(replace(frame.parent_function_name, \", \", \"; \"), \";;\",
+    replace(frame.function_name, \", \", \"; \")) AS parent_child_functions,
+  frame.filename AS child_function_file,
+  frame.load_module_path AS child_function_dso,
+  SUM(frame.inclusive_count)/ANY_VALUE(total.value) AS inclusive_count_fraction
+FROM
+  $TABLE table,
+  table.frame frame
+CROSS JOIN (
+  SELECT
+    SUM(count) AS value
+  FROM $TABLE
+  WHERE
+    $WHERE_CLAUSE_SPECIFICATIONS
+) AS total
+WHERE
+  $WHERE_CLAUSE_SPECIFICATIONS
+GROUP BY
+  parent_child_functions,
+  child_function_file,
+  child_function_dso
+HAVING
+  inclusive_count_fraction > 0.0
+ORDER BY
+  inclusive_count_fraction DESC;
+" | dremel --output=csv > "$PAIRWISE_INCLUSIVE_OUTPUT_FILE"
diff --git a/user_activity_benchmarks/collect_experiment_data_odd_even_session.sh b/user_activity_benchmarks/collect_experiment_data_odd_even_session.sh
new file mode 100755
index 0000000..9019f0d
--- /dev/null
+++ b/user_activity_benchmarks/collect_experiment_data_odd_even_session.sh
@@ -0,0 +1,92 @@
+#!/bin/bash
+
+# Copyright 2016 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+# Uses Dremel queries to collect the inclusive and pairwise inclusive statistics
+# for odd/even profile collection session ids.
+# The data is collected for an odd or even collection session id.
+
+set -e
+
+if [ $# -lt 7 ]; then
+  echo "Usage: collect_validation_data.sh cwp_table board board_arch " \
+  "Chrome_OS_release odd_even inclusive_output_file " \
+  "pairwise_inclusive_output_file"
+  exit 1
+fi
+
+readonly TABLE=$1
+readonly INCLUSIVE_OUTPUT_FILE=$6
+readonly PAIRWISE_INCLUSIVE_OUTPUT_FILE=$7
+readonly PERIODIC_COLLECTION=1
+readonly WHERE_CLAUSE_SPECIFICATIONS="meta.cros.board = '$2' AND " \
+    "meta.cros.cpu_architecture = '$3' AND " \
+    "meta.cros.chrome_version LIKE '%$4%' AND "\
+    "meta.cros.collection_info.trigger_event = $PERIODIC_COLLECTION AND " \
+    "MOD(session.id, 2) = $5"
+
+# Collects the function, with its file, the object and inclusive count
+# fraction out of the total amount of inclusive count values.
+echo "set sql_dialect GoogleSQL;
+
+SELECT
+  replace(frame.function_name, \", \", \"; \") AS function,
+  frame.filename AS file,
+  frame.load_module_path AS dso,
+  SUM(frame.inclusive_count)/ANY_VALUE(total.value) AS inclusive_count_fraction
+FROM
+  $TABLE table,
+  table.frame frame
+CROSS JOIN (
+  SELECT
+    SUM(count) AS value
+  FROM $TABLE
+  WHERE
+    $WHERE_CLAUSE_SPECIFICATIONS
+) AS total
+WHERE
+    $WHERE_CLAUSE_SPECIFICATIONS
+GROUP BY
+  function,
+  file,
+  dso
+HAVING
+  inclusive_count_fraction > 0.0
+ORDER BY
+  inclusive_count_fraction DESC;
+" | dremel --output=csv > "$INCLUSIVE_OUTPUT_FILE"
+
+# Collects the pair of parent and child functions, with the file and object
+# where the child function is declared and the inclusive count fraction of the
+# pair out of the total amount of inclusive count values.
+echo "set sql_dialect GoogleSQL;
+
+SELECT
+  CONCAT(replace(frame.parent_function_name, \", \", \"; \"), \";;\",
+    replace(frame.function_name, \", \", \"; \")) AS parent_child_functions,
+  frame.filename AS child_function_file,
+  frame.load_module_path AS child_function_dso,
+  SUM(frame.inclusive_count)/ANY_VALUE(total.value) AS inclusive_count_fraction
+FROM
+  $TABLE table,
+  table.frame frame
+CROSS JOIN (
+  SELECT
+    SUM(count) AS value
+  FROM
+    $TABLE
+  WHERE
+    $WHERE_CLAUSE_SPECIFICATIONS
+) AS total
+WHERE
+  $WHERE_CLAUSE_SPECIFICATIONS
+GROUP BY
+  parent_child_functions,
+  child_function_file,
+  child_function_dso
+HAVING
+  inclusive_count_fraction > 0.0
+ORDER BY
+  inclusive_count_fraction DESC;
+" | dremel --output=csv > "$PAIRWISE_INCLUSIVE_OUTPUT_FILE"