| # Copyright (c) 2013 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. |
| |
| description "Report once-per-boot UMA statistics" |
| author "chromium-os-dev@chromium.org" |
| |
| start on started system-services |
| |
| script |
| # Every time we shut down, we save a log of all the bootstat event |
| # files. To prevent unbounded growth, when we get back here, we |
| # remove the data for all but the 50 most recent boots. |
| BOOT_LOG_ROTATE_COUNT=50 |
| rm -rf $(ls -dt /var/log/metrics/shutdown.[0-9]* | |
| sed "1,$BOOT_LOG_ROTATE_COUNT d") |
| |
| GET_FIRMWARE_TIME=' |
| /Initial usec timer/ { |
| sub(".*Initial usec timer ", "") |
| initial_usec = $0 |
| exit |
| } |
| END { |
| printf "%.2f\n", initial_usec / 1000000 |
| } |
| ' |
| |
| FIRMWARE_TIME=$(dmesg | awk "$GET_FIRMWARE_TIME") |
| |
| # TODO(jrbarnette): The firmware-boot-time file is used by tests |
| # for two purposes: |
| # 1) by boot time tests, to estimate total boot time from power |
| # on (not just from kernel startup), and |
| # 2) by firmware tests, to estimate how long the dev mode warning |
| # screen is presented. |
| # |
| # Probably there should be another way for autotests to get boot |
| # time, so the code to create this file can be removed. |
| echo $FIRMWARE_TIME >/tmp/firmware-boot-time |
| |
| # usage: |
| # report_disk_metrics <read-sectors> <write-sectors> |
| report_disk_metrics() { |
| metrics_client Platform.BootSectorsRead $1 1 1000000 50 |
| metrics_client Platform.BootSectorsWritten $2 1 10000 50 |
| } |
| |
| report_disk_metrics $( |
| bootstat_get_last boot-complete read-sectors write-sectors) |
| |
| send_metrics_on_resume -b |
| |
| # Report disk health from SMART (S.M.A.R.T.) parameters. |
| # usage: |
| # report_smart_metrics <uncorrectable-errors> <transfer-errors> |
| report_smart_metrics() { |
| metrics_client Platform.SmartUncorrectableErrors $1 1 1000000 20 |
| metrics_client Platform.SmartTransferErrors $2 1 1000000 20 |
| } |
| |
| GET_SMART_ERRORS=' |
| BEGIN { uncorr = 0; txfer = 0 } |
| $2 == "Reported_Uncorrect" { uncorr = $10 } |
| $2 == "UDMA_CRC_Error_Count" { txfer = $10 } |
| END { print uncorr, txfer } |
| ' |
| report_smart_metrics $( |
| smartctl -A $(rootdev -s -d) | awk "$GET_SMART_ERRORS") |
| |
| # Check if the EC is in TPSRESET state and if so report it, but only once |
| # (by design, the EC stays in that state forever). |
| EC_RESET_FILE=/home/chronos/.ec.tpsreset |
| if ectool chipinfo | grep -q TPSRESET && |
| test ! -f $EC_RESET_FILE |
| then |
| metrics_client -v Ec.TpsReset |
| su chronos -c "touch $EC_RESET_FILE" |
| fi |
| |
| POWERWASH_COMPLETE="/mnt/stateful_partition/unencrypted/.powerwash_completed" |
| POWERWASH_COUNT="/mnt/stateful_partition/unencrypted/preserve/powerwash_count" |
| # Report powerwash stats if a powerwash recently occurred. |
| if [ -f $POWERWASH_COMPLETE -a -f /home/chronos/.oobe_completed ]; then |
| # Upload the fact powerwash occurred and the number of times this device |
| # has been powerwashed. |
| COUNT=$(head -1 $POWERWASH_COUNT | cut -c1-4) |
| if [ $(expr "$COUNT" : "^[0-9][0-9]*$") -ne 0 ]; then |
| metrics_client Installer.PowerwashCount $COUNT 1 1000 20 |
| fi |
| rm -f $POWERWASH_COMPLETE |
| fi |
| |
| CHROME_EXEC_TIME=$(bootstat_get_last chrome-exec time) |
| BOOT_COMPLETE_TIME=$(bootstat_get_last boot-complete time) |
| PRE_STARTUP_TIME=$(bootstat_get_last pre-startup time) |
| TOTAL_TIME=$(echo $FIRMWARE_TIME $BOOT_COMPLETE_TIME | awk '{print $1 + $2}') |
| SYSTEM_TIME=$(echo $CHROME_EXEC_TIME $PRE_STARTUP_TIME | |
| awk '{print $1 - $2}') |
| CHROME_TIME=$(echo $BOOT_COMPLETE_TIME $CHROME_EXEC_TIME | |
| awk '{print $1 - $2}') |
| metrics_client -t BootTime.Total $TOTAL_TIME 1 10000 50 |
| metrics_client -t BootTime.Firmware $FIRMWARE_TIME 1 10000 50 |
| metrics_client -t BootTime.Kernel $PRE_STARTUP_TIME 1 10000 50 |
| metrics_client -t BootTime.System $SYSTEM_TIME 1 10000 50 |
| metrics_client -t BootTime.Chrome $CHROME_TIME 1 10000 50 |
| end script |