| # Copyright 2021 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 elog-related UMA statistics" |
| author "chromium-os-dev@chromium.org" |
| |
| # Because the elogtool leverages SPI driver, wait for ui.conf ready to |
| # ensure there is no race condition between ui and this script which |
| # might result in increasing the boot time. |
| start on started system-services and started ui |
| |
| # Killable for memory leaks. |
| oom score -100 |
| |
| script |
| get_elog_after_last_report() { |
| local elog="$(elogtool list)" |
| local filename="/var/lib/metrics/elog-last-line" |
| local filesize="$(stat -c%s "${filename}")" |
| |
| local elog_last_line |
| local elog_after_last_report="${elog}" |
| |
| # Try to get the last line of previous uploads. |
| # Since we cannot make assumptions about the content of this file |
| # which has a volatile path and could be corrupted or modified, |
| # we have to ensure the file size is not suspiciously large. |
| if [ "${filesize}" -lt 65536 ]; then |
| elog_last_line="$(cat "${filename}" 2> /dev/null)" |
| |
| # Cut out the elog events which are already uploaded. |
| if [ -n "${elog_last_line}" ]; then |
| elog_after_last_report="${elog##*"${elog_last_line}"}" |
| fi |
| fi |
| |
| # Update the elog-last-line. |
| echo "${elog_after_last_report}" | tail -1 > "${filename}" |
| |
| # Return the log string. |
| echo "${elog_after_last_report}" |
| } |
| |
| # MiniDiag (pre-boot diagnostics) related metrics. |
| # Report the MiniDiag launch count. |
| launch="$(get_elog_after_last_report | \ |
| grep -c "Launch Diagnostics")" || : |
| metrics_client Platform.MiniDiag.Launch -e "${launch}" 50 |
| |
| end script |