xref: /aosp_15_r20/external/autotest/autotest_lib/contrib/suite_times (revision 9c5db1993ded3edbeafc8092d69fe5de2ee02df7)
1*9c5db199SXin Li#!/bin/bash
2*9c5db199SXin Li#
3*9c5db199SXin Li# usage: suite_times [ status.log ]
4*9c5db199SXin Li#
5*9c5db199SXin Li# Parses a "status.log" file for a suite job, and for each test that
6*9c5db199SXin Li# ran, report these timeline data from the log:
7*9c5db199SXin Li#   1. hostname of the DUT that the test ran on
8*9c5db199SXin Li#   2. time_t value of the time that the test started running
9*9c5db199SXin Li#   3. total run time of the test on the DUT
10*9c5db199SXin Li#   4. number of seconds between this test's start time and the
11*9c5db199SXin Li#       start time of the last prior test on the same DUT
12*9c5db199SXin Li#   5. name of the test
13*9c5db199SXin Li#
14*9c5db199SXin Li# This script is meant as a simple building block.  Below are
15*9c5db199SXin Li# some sample uses.
16*9c5db199SXin Li#
17*9c5db199SXin Li# Print average inter-test time:
18*9c5db199SXin Li#   suite_times | awk '{if ($4) {sum += $4; cnt++}} END {print sum / cnt}'
19*9c5db199SXin Li#
20*9c5db199SXin Li# Print average test run time:
21*9c5db199SXin Li#   suite_times | awk '{sum += $3} END {print sum / NR}'
22*9c5db199SXin Li#
23*9c5db199SXin Li# Print time line for a host:
24*9c5db199SXin Li#   suite_times | grep $HOST
25*9c5db199SXin Li
26*9c5db199SXin Li
27*9c5db199SXin LiPROCESS_SUITE='
28*9c5db199SXin Li  $1 == "START" && $2 != "----" {
29*9c5db199SXin Li    host = gensub(".*/(.*)/.*", "\\1", 1, $2)
30*9c5db199SXin Li    test = $3
31*9c5db199SXin Li    start_ts = gensub(".*=", "", 1, $4)
32*9c5db199SXin Li    old_ts = hosttimes[host]
33*9c5db199SXin Li    if (!old_ts) { old_ts = start_ts }
34*9c5db199SXin Li    start_rel = start_ts - old_ts
35*9c5db199SXin Li    hosttimes[host] = start_ts
36*9c5db199SXin Li  }
37*9c5db199SXin Li
38*9c5db199SXin Li  $1 == "GOOD" {
39*9c5db199SXin Li    end_ts = gensub(".*=", "", 1, $4)
40*9c5db199SXin Li    runtime = end_ts - start_ts
41*9c5db199SXin Li    printf "%s %d %4d %4d %s\n", host, start_ts, runtime, start_rel, test
42*9c5db199SXin Li  }
43*9c5db199SXin Li'
44*9c5db199SXin Li
45*9c5db199SXin Liif [ $# -eq 0 ]; then
46*9c5db199SXin Li  STATUS_LOG=status.log
47*9c5db199SXin Lielif [ $# -eq 1 ]; then
48*9c5db199SXin Li  STATUS_LOG="$1"
49*9c5db199SXin Lielse
50*9c5db199SXin Li  echo "usage: $(basename $0) [ status.log ]" >&2
51*9c5db199SXin Li  exit 1
52*9c5db199SXin Lifi
53*9c5db199SXin Li
54*9c5db199SXin Liawk "$PROCESS_SUITE" "$STATUS_LOG"
55