| #!/bin/sh | |
| # Copyright 2012 The ChromiumOS Authors | |
| # Use of this source code is governed by a BSD-style license that can be | |
| # found in the LICENSE file. | |
| if [ $# -ne 1 ]; then | |
| echo "usage: $(basename "$0") <archive-dir>" >&2 | |
| exit 1 | |
| fi | |
| ARCHIVE="${1%/}" | |
| mkdir -p "${ARCHIVE}" | |
| # Change the working directory since relative paths (without directories) allow | |
| # us to check for parent symlinks once without introducing a time-of-check | |
| # time-of-use race. | |
| if ! cd "${ARCHIVE}" || [ "$(readlink -f .)" != "${ARCHIVE}" ]; then | |
| echo "bootstat_archive requires a non-symlinked archive-dir" >&2 | |
| exit 1 | |
| fi | |
| # All uptime values are recorded as "time since boot". To | |
| # facilitate comparing archived times against other times measured | |
| # against a different boot time, we capture timestamps with both | |
| # `date` and `bootstat` so we can reconstruct times in UTC later. | |
| # Since the two gathered times will be slightly different, we run | |
| # `date` at both the start and end of the operation, so as to put a | |
| # bound on the measurement error. | |
| date '+%s.%N' >'./timestamp' | |
| bootstat archive | |
| # -Pp: don't follow source symlinks; preserve mode, owner and file times. | |
| cp --remove-destination -Pp /run/bootstat/uptime-* /run/bootstat/disk-* \ | |
| /run/bootstat/sync-rtc-* /proc/sys/kernel/random/boot_id \ | |
| . | |
| date '+%s.%N' >>'./timestamp' |