user_activity: Added tools for the benchmark profile collection.

The scripts run the Telemetry benchmarks, collects their perf profiles, use
local_cwp to do the profile symbolization and collect the hot
functions and callchains with pprof.

BUG=None
TEST=None

Change-Id: I2170e53d95924f1a3ba134bd62b1eead9e7a3077
Reviewed-on: https://chrome-internal-review.googlesource.com/288517
Reviewed-by: Luis Lozano <llozano@chromium.org>
Reviewed-by: Evelina Dumitrescu <evelinad@google.com>
Commit-Queue: Evelina Dumitrescu <evelinad@google.com>
Tested-by: Evelina Dumitrescu <evelinad@google.com>
diff --git a/user_activity_benchmarks/collect_pprof_data.sh b/user_activity_benchmarks/collect_pprof_data.sh
new file mode 100755
index 0000000..5b89f18
--- /dev/null
+++ b/user_activity_benchmarks/collect_pprof_data.sh
@@ -0,0 +1,41 @@
+#!/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.
+# Collects the pprof tree and top outputs.
+# All the local_cwp symbolized profiles are taken from the
+# local_cwp_results_path.
+# The pprof top output is stored in the pprof_top_results_path and the pprof
+# tree output is stored in the pprof_tree_results_path.
+
+set -e
+
+if [ "$#" -ne 3 ]; then
+  echo "USAGE: collect_pprof_data.sh local_cwp_results_path " \
+    "pprof_top_results_path pprof_tree_results_path"
+  exit 1
+fi
+
+readonly LOCAL_CWP_RESULTS_PATH=$1
+readonly PPROF_TOP_RESULTS_PATH=$2
+readonly PPROF_TREE_RESULTS_PATH=$3
+readonly SYMBOLIZED_PROFILES=`ls $LOCAL_CWP_RESULTS_PATH`
+
+for symbolized_profile in "${SYMBOLIZED_PROFILES[@]}"
+do
+  pprof --top "$LOCAL_CWP_RESULTS_PATH/${symbolized_profile}" > \
+    "$PPROF_TOP_RESULTS_PATH/${symbolized_profile}.pprof"
+  if [ $? -ne 0 ]; then
+    echo "Failed to extract the pprof top output for the $symbolized_profile."
+    continue
+  fi
+
+  pprof --tree "$LOCAL_CWP_RESULTS_PATH/${symbolized_profile}" > \
+    "$PPROF_TREE_RESULTS_PATH/${symbolized_profile}.pprof"
+  if [ $? -ne 0 ]; then
+    echo "Failed to extract the pprof tree output for the " \
+      "$symbolized_profile."
+    continue
+  fi
+done
diff --git a/user_activity_benchmarks/collect_telemetry_profiles.sh b/user_activity_benchmarks/collect_telemetry_profiles.sh
new file mode 100755
index 0000000..0583adc
--- /dev/null
+++ b/user_activity_benchmarks/collect_telemetry_profiles.sh
@@ -0,0 +1,90 @@
+#!/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.
+# Runs the Telemetry benchmarks with AutoTest and collects their perf profiles.
+# Reads the benchmark names from the telemetry_benchmark_file. Each benchmark
+# should be placed on a separate line.
+# The profile results are placed in the results_path.
+
+set -e
+
+if [ "$#" -ne 5 ]; then
+  echo "USAGE: collect_telemetry_profiles.sh board chrome_root_path " \
+  "machine_ip results_path telemetry_benchmarks_file"
+  exit 1
+fi
+
+# CHROME_ROOT should contain the path with the source of Chrome. This is used by
+# AutoTest.
+export CHROME_ROOT=$2
+
+readonly BOARD=$1
+readonly IP=$3
+readonly RESULTS_PATH=$4
+readonly TELEMETRY_BENCHMARKS_FILE=$5
+
+# The following Telemetry benchmarks failed for the R52-8350.68.0 Chrome OS
+# version: page_cycler_v2.top_10_mobile,
+# page_cycler_v2.basic_oopif, smoothness.tough_filters_cases,
+# page_cycler_v2.intl_hi_ru,
+# image_decoding.image_decoding_measurement, system_health.memory_mobile,
+# memory.top_7_stress, smoothness.tough_path_rendering_cases,
+# page_cycler_v2.tough_layout_cases,
+# memory.long_running_idle_gmail_background_tbmv2, smoothness.tough_webgl_cases,
+# smoothness.tough_canvas_cases, smoothness.tough_texture_upload_cases,
+# top_10_mobile_memory_ignition, startup.large_profile.cold.blank_page,
+# page_cycler_v2.intl_ar_fa_he, start_with_ext.cold.blank_page,
+# start_with_ext.warm.blank_page, page_cycler_v2.intl_ko_th_vi,
+# smoothness.scrolling_tough_ad_case, page_cycler_v2_site_isolation.basic_oopif,
+# smoothness.tough_scrolling_cases, startup.large_profile.warm.blank_page,
+# page_cycler_v2.intl_es_fr_pt-BR, page_cycler_v2.intl_ja_zh,
+# memory.long_running_idle_gmail_tbmv2, smoothness.scrolling_tough_ad_cases,
+# page_cycler_v2.typical_25, smoothness.tough_webgl_ad_cases,
+# smoothness.tough_image_decode_cases.
+#
+# However, we did not manage to collect the profiles only from the following
+# benchmarks: smoothness.tough_filters_cases,
+# smoothness.tough_path_rendering_cases, page_cycler_v2.tough_layout_cases,
+# smoothness.tough_webgl_cases, smoothness.tough_canvas_cases,
+# smoothness.tough_texture_upload_cases, smoothness.tough_scrolling_cases,
+# smoothness.tough_webgl_ad_cases, smoothness.tough_image_decode_cases.
+#
+# Use ./run_benchmark --browser=cros-chrome --remote=$IP list to get the list of
+# Telemetry benchmarks.
+readonly LATEST_PERF_PROFILE=/tmp/test_that_latest/results-1-telemetry_Crosperf/telemetry_Crosperf/profiling/perf.data
+
+while read benchmark
+do
+  # TODO(evelinad): We should add -F 4000000 to the list of profiler_args
+  # arguments because we need to use the same sampling period as the one used
+  # to collect the CWP user data (4M number of cycles for cycles.callgraph).
+  test_that --debug  --board=${BOARD} --args=" profiler=custom_perf \
+    profiler_args='record -g -a -e cycles,instructions' \
+    run_local=False test=$benchmark " $IP telemetry_Crosperf
+  if [ $? -ne 0 ]; then
+    echo "Failed to run the $benchmark telemetry benchmark with Autotest."
+    continue
+  fi
+  echo "Warning: Sampling period is too high. It should be set to 4M samples."
+
+  cp "$LATEST_PERF_PROFILE" "$RESULTS_PATH/${benchmark}.data"
+  if [ $? -ne 0 ]; then
+    echo "Failed to move the perf profile file from $LATEST_PERF_PROFILE to " \
+      "$PERF_DATA_RESULTS_PATH/${benchmark}.data for the $benchmark " \
+      "telemetry benchmark."
+    continue
+  fi
+
+  # The ssh connection should be configured without password. We need to do
+  # this step because we might run out of disk space if we run multiple
+  # benchmarks.
+  ssh root@$IP "rm -rf /usr/local/profilers/*"
+  if [ $? -ne 0 ]; then
+    echo "Failed to remove the output files from /usr/local/profilers/ for " \
+      "the $benchmark telemetry benchmark."
+    continue
+  fi
+done < $TELEMETRY_BENCHMARKS_FILE
+
diff --git a/user_activity_benchmarks/symbolize_profiles.sh b/user_activity_benchmarks/symbolize_profiles.sh
new file mode 100755
index 0000000..904cc1b
--- /dev/null
+++ b/user_activity_benchmarks/symbolize_profiles.sh
@@ -0,0 +1,32 @@
+#!/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 local_cwp to do the profile symbolization.
+# The profiles that need to be symbolized are placed in the profiles_path.
+# The results are placed in the local_cwp_results_path.
+
+set -e
+
+if [ "$#" -ne 3 ]; then
+  echo "USAGE: symbolize_profiles.sh profiles_path local_cwp_binary_path " \
+    "local_cwp_results_path"
+  exit 1
+fi
+
+readonly PROFILES_PATH=$1
+readonly LOCAL_CWP_BINARY_PATH=$2
+readonly LOCAL_CWP_RESULTS_PATH=$3
+readonly PROFILES=$(ls $PROFILES_PATH)
+
+for profile in "${PROFILES[@]}"
+do
+  $LOCAL_CWP_BINARY_PATH --output="$LOCAL_CWP_RESULTS_PATH/${profile}.pb.gz" \
+    "$PROFILES_PATH/$profile"
+  if [ $? -ne 0 ]; then
+    echo "Failed to symbolize the perf profile output with local_cwp for " \
+      "$profile."
+    continue
+  fi
+done
diff --git a/user_activity_benchmarks/telemetry_benchmarks_R52_8350.68 b/user_activity_benchmarks/telemetry_benchmarks_R52_8350.68
new file mode 100644
index 0000000..0177dab
--- /dev/null
+++ b/user_activity_benchmarks/telemetry_benchmarks_R52_8350.68
@@ -0,0 +1,113 @@
+blink_perf.bindings
+blink_perf.canvas
+blink_perf.css
+blink_perf.dom
+blink_perf.events
+blink_perf.layout
+blink_perf.paint
+blink_perf.parser
+blink_perf.shadow_dom
+blink_perf.svg
+blink_style.top_25
+blob_storage.blob_storage
+dromaeo.cssqueryjquery
+dromaeo.domcoreattr
+dromaeo.domcoremodify
+dromaeo.domcorequery
+dromaeo.domcoretraverse
+dromaeo.jslibattrjquery
+dromaeo.jslibattrprototype
+dromaeo.jslibeventjquery
+dromaeo.jslibeventprototype
+dromaeo.jslibmodifyjquery
+dromaeo.jslibmodifyprototype
+dromaeo.jslibstylejquery
+dromaeo.jslibstyleprototype
+dromaeo.jslibtraversejquery
+dromaeo.jslibtraverseprototype
+dummy_benchmark.noisy_benchmark_1
+dummy_benchmark.stable_benchmark_1
+image_decoding.image_decoding_measurement
+indexeddb_perf
+jetstream
+jitter
+kraken
+media.chromeOS4kOnly.tough_video_cases
+media.chromeOS.tough_video_cases
+media.media_cns_cases
+media.mse_cases
+media.tough_video_cases_extra
+media.tough_video_cases
+memory.long_running_idle_gmail_background_tbmv2
+memory.long_running_idle_gmail_tbmv2
+memory.top_7_stress
+octane
+oilpan_gc_times.tough_animation_cases
+oortonline
+page_cycler.basic_oopif
+page_cycler.intl_hi_ru
+page_cycler.intl_ko_th_vi
+page_cycler_site_isolation.basic_oopif
+page_cycler.typical_25
+page_cycler_v2.basic_oopif
+page_cycler_v2.intl_ar_fa_he
+page_cycler_v2.intl_es_fr_pt-BR
+page_cycler_v2.intl_hi_ru
+page_cycler_v2.intl_ja_zh
+page_cycler_v2.intl_ko_th_vi
+page_cycler_v2_site_isolation.basic_oopif
+page_cycler_v2.top_10_mobile
+page_cycler_v2.typical_25
+rasterize_and_record_micro.key_mobile_sites_smooth
+rasterize_and_record_micro.key_silk_cases
+rasterize_and_record_micro.top_25_smooth
+robohornet_pro
+scheduler.tough_scheduling_cases
+service_worker.service_worker_micro_benchmark
+service_worker.service_worker
+smoothness.gpu_rasterization_and_decoding.image_decoding_cases
+smoothness.gpu_rasterization.tough_filters_cases
+smoothness.gpu_rasterization.tough_path_rendering_cases
+smoothness.image_decoding_cases
+smoothness.key_desktop_move_cases
+smoothness.scrolling_tough_ad_case
+smoothness.scrolling_tough_ad_cases
+smoothness.top_25_smooth
+smoothness.tough_ad_cases
+spaceport
+speedometer-ignition
+speedometer
+startup.cold.blank_page
+startup.large_profile.cold.blank_page
+startup.large_profile.warm.blank_page
+startup.large_profile.warm.blank
+startup.warm.blank_page
+start_with_ext.cold.blank_page
+start_with_ext.warm.blank_page
+storage.indexeddb_endure
+storage.indexeddb_endure_tracing
+sunspider
+system_health.memory_mobile
+tab_switching.five_blank_pages
+tab_switching.top_10
+tab_switching.tough_energy_cases
+tab_switching.tough_image_cases
+tab_switching.typical_25
+thread_times.tough_compositor_cases
+thread_times.tough_scrolling_cases
+top_10_mobile_memory_ignition
+top_10_mobile_memory
+tracing.tracing_with_background_memory_infra
+tracing.tracing_with_debug_overhead
+v8.browsing_mobile
+v8.detached_context_age_in_gc
+v8.google
+v8.infinite_scroll-ignition_tbmv2
+v8.infinite_scroll_tbmv2
+v8.todomvc-ignition
+v8.todomvc
+v8.top_25_smooth
+webrtc.datachannel
+webrtc.getusermedia
+webrtc.peerconnection
+webrtc.webrtc_smoothness