xref: /aosp_15_r20/frameworks/base/ravenwood/scripts/ravenwood-stats-collector.sh (revision d57664e9bc4670b3ecf6748a746a57c557b6bc9e)
1*d57664e9SAndroid Build Coastguard Worker#!/bin/bash
2*d57664e9SAndroid Build Coastguard Worker# Copyright (C) 2024 The Android Open Source Project
3*d57664e9SAndroid Build Coastguard Worker#
4*d57664e9SAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License");
5*d57664e9SAndroid Build Coastguard Worker# you may not use this file except in compliance with the License.
6*d57664e9SAndroid Build Coastguard Worker# You may obtain a copy of the License at
7*d57664e9SAndroid Build Coastguard Worker#
8*d57664e9SAndroid Build Coastguard Worker#      http://www.apache.org/licenses/LICENSE-2.0
9*d57664e9SAndroid Build Coastguard Worker#
10*d57664e9SAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software
11*d57664e9SAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS,
12*d57664e9SAndroid Build Coastguard Worker# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*d57664e9SAndroid Build Coastguard Worker# See the License for the specific language governing permissions and
14*d57664e9SAndroid Build Coastguard Worker# limitations under the License.
15*d57664e9SAndroid Build Coastguard Worker
16*d57664e9SAndroid Build Coastguard Worker# Script to collect the ravenwood "stats" CVS files and create a single file.
17*d57664e9SAndroid Build Coastguard Worker
18*d57664e9SAndroid Build Coastguard Workerset -e
19*d57664e9SAndroid Build Coastguard Worker
20*d57664e9SAndroid Build Coastguard Worker# Output files
21*d57664e9SAndroid Build Coastguard Workerout_dir=/tmp/ravenwood
22*d57664e9SAndroid Build Coastguard Workerstats=$out_dir/ravenwood-stats-all.csv
23*d57664e9SAndroid Build Coastguard Workerapis=$out_dir/ravenwood-apis-all.csv
24*d57664e9SAndroid Build Coastguard Workerkeep_all_dir=$out_dir/ravenwood-keep-all/
25*d57664e9SAndroid Build Coastguard Workerdump_dir=$out_dir/ravenwood-dump/
26*d57664e9SAndroid Build Coastguard Worker
27*d57664e9SAndroid Build Coastguard Workerrm -fr $out_dir
28*d57664e9SAndroid Build Coastguard Workermkdir -p $out_dir
29*d57664e9SAndroid Build Coastguard Workermkdir -p $keep_all_dir
30*d57664e9SAndroid Build Coastguard Workermkdir -p $dump_dir
31*d57664e9SAndroid Build Coastguard Worker
32*d57664e9SAndroid Build Coastguard Worker# Where the input files are.
33*d57664e9SAndroid Build Coastguard Workerpath=$ANDROID_BUILD_TOP/out/host/linux-x86/testcases/ravenwood-stats-checker/x86_64/
34*d57664e9SAndroid Build Coastguard Worker
35*d57664e9SAndroid Build Coastguard Workertimestamp="$(date --iso-8601=seconds)"
36*d57664e9SAndroid Build Coastguard Worker
37*d57664e9SAndroid Build Coastguard Workerm() {
38*d57664e9SAndroid Build Coastguard Worker    ${ANDROID_BUILD_TOP}/build/soong/soong_ui.bash --make-mode "$@"
39*d57664e9SAndroid Build Coastguard Worker}
40*d57664e9SAndroid Build Coastguard Worker
41*d57664e9SAndroid Build Coastguard Worker# Building this will generate the files we need.
42*d57664e9SAndroid Build Coastguard Workerm ravenwood-stats-checker
43*d57664e9SAndroid Build Coastguard Worker
44*d57664e9SAndroid Build Coastguard Worker# Start...
45*d57664e9SAndroid Build Coastguard Worker
46*d57664e9SAndroid Build Coastguard Workercd $path
47*d57664e9SAndroid Build Coastguard Worker
48*d57664e9SAndroid Build Coastguard Workerdump() {
49*d57664e9SAndroid Build Coastguard Worker    local jar=$1
50*d57664e9SAndroid Build Coastguard Worker    local file=$2
51*d57664e9SAndroid Build Coastguard Worker
52*d57664e9SAndroid Build Coastguard Worker    # Remove the header row, and prepend the columns.
53*d57664e9SAndroid Build Coastguard Worker    sed -e '1d' -e "s/^/$jar,$timestamp,/" $file
54*d57664e9SAndroid Build Coastguard Worker}
55*d57664e9SAndroid Build Coastguard Worker
56*d57664e9SAndroid Build Coastguard Workercollect_stats() {
57*d57664e9SAndroid Build Coastguard Worker    local out="$1"
58*d57664e9SAndroid Build Coastguard Worker    {
59*d57664e9SAndroid Build Coastguard Worker        # Copy the header, with the first column appended.
60*d57664e9SAndroid Build Coastguard Worker        echo -n "Jar,Generated Date,"
61*d57664e9SAndroid Build Coastguard Worker        head -n 1 hoststubgen_framework-minus-apex_stats.csv
62*d57664e9SAndroid Build Coastguard Worker
63*d57664e9SAndroid Build Coastguard Worker        dump "framework-minus-apex" hoststubgen_framework-minus-apex_stats.csv
64*d57664e9SAndroid Build Coastguard Worker        dump "service.core"  hoststubgen_services.core_stats.csv
65*d57664e9SAndroid Build Coastguard Worker        dump "framework-configinfrastructure"  framework-configinfrastructure_stats.csv
66*d57664e9SAndroid Build Coastguard Worker        dump "framework-statsd"  framework-statsd_stats.csv
67*d57664e9SAndroid Build Coastguard Worker    } > "$out"
68*d57664e9SAndroid Build Coastguard Worker
69*d57664e9SAndroid Build Coastguard Worker    echo "Stats CVS created at $out"
70*d57664e9SAndroid Build Coastguard Worker}
71*d57664e9SAndroid Build Coastguard Worker
72*d57664e9SAndroid Build Coastguard Workercollect_apis() {
73*d57664e9SAndroid Build Coastguard Worker    local out="$1"
74*d57664e9SAndroid Build Coastguard Worker    {
75*d57664e9SAndroid Build Coastguard Worker        # Copy the header, with the first column appended.
76*d57664e9SAndroid Build Coastguard Worker        echo -n "Jar,Generated Date,"
77*d57664e9SAndroid Build Coastguard Worker        head -n 1 hoststubgen_framework-minus-apex_apis.csv
78*d57664e9SAndroid Build Coastguard Worker
79*d57664e9SAndroid Build Coastguard Worker        dump "framework-minus-apex"  hoststubgen_framework-minus-apex_apis.csv
80*d57664e9SAndroid Build Coastguard Worker        dump "service.core"  hoststubgen_services.core_apis.csv
81*d57664e9SAndroid Build Coastguard Worker        dump "framework-configinfrastructure"  framework-configinfrastructure_apis.csv
82*d57664e9SAndroid Build Coastguard Worker        dump "framework-statsd"  framework-statsd_apis.csv
83*d57664e9SAndroid Build Coastguard Worker    } > "$out"
84*d57664e9SAndroid Build Coastguard Worker
85*d57664e9SAndroid Build Coastguard Worker    echo "API CVS created at $out"
86*d57664e9SAndroid Build Coastguard Worker}
87*d57664e9SAndroid Build Coastguard Worker
88*d57664e9SAndroid Build Coastguard Worker
89*d57664e9SAndroid Build Coastguard Workercollect_stats $stats
90*d57664e9SAndroid Build Coastguard Workercollect_apis $apis
91*d57664e9SAndroid Build Coastguard Worker
92*d57664e9SAndroid Build Coastguard Workercp *keep_all.txt $keep_all_dir
93*d57664e9SAndroid Build Coastguard Workerecho "Keep all files created at:"
94*d57664e9SAndroid Build Coastguard Workerfind $keep_all_dir -type f
95*d57664e9SAndroid Build Coastguard Worker
96*d57664e9SAndroid Build Coastguard Workercp *dump.txt $dump_dir
97*d57664e9SAndroid Build Coastguard Workerecho "Dump files created at:"
98*d57664e9SAndroid Build Coastguard Workerfind $dump_dir -type f