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