blob: e45ed677a71eed256f3f5ee615b643f1ccd2515d [file] [log] [blame]
# 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
GET_FIRMWARE_TIME_LEGACY='
/Initial usec timer/ {
sub(".*Initial usec timer ", "")
initial_usec = $0
exit
}
END {
printf "%.2f", initial_usec / 1000000
}
'
GET_FIRMWARE_TIME='
/Exiting depthcharge with code/ {
initial_usec = $8
printf "%.2f", initial_usec / 1000000
}
'
FIRMWARE_LOG="/sys/firmware/log"
get_firmware_time() {
local ftime
if [ -e "$FIRMWARE_LOG" ]; then
ftime="$(awk "$GET_FIRMWARE_TIME" "$FIRMWARE_LOG")"
fi
if [ -z "$ftime" ]; then
ftime="$(dmesg | awk "$GET_FIRMWARE_TIME_LEGACY")"
fi
echo "$ftime"
}
# 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.
FIRMWARE_TIME="$(get_firmware_time)"
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)
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