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/ 25dump_dir=$out_dir/ravenwood-dump/ 26 27rm -fr $out_dir 28mkdir -p $out_dir 29mkdir -p $keep_all_dir 30mkdir -p $dump_dir 31 32 33stats_checker_module="ravenwood-stats-checker" 34minfo=$OUT/module-info.json 35 36timestamp="$(date --iso-8601=seconds)" 37 38# First, use jq to get the output files from the checker module. This will be something like this: 39# 40# --- 41# out/host/linux-x86/nativetest64/ravenwood-stats-checker/framework-configinfrastructure_apis.csv 42# out/host/linux-x86/nativetest64/ravenwood-stats-checker/framework-configinfrastructure_dump.txt 43# : 44# out/host/linux-x86/nativetest64/ravenwood-stats-checker/hoststubgen_services.core_stats.csv 45# out/host/linux-x86/nativetest64/ravenwood-stats-checker/ravenwood-stats-checker 46# --- 47# Then, use grep to find the script's path (the last line in the above examle) 48script_path="$( 49 jq -r ".\"$stats_checker_module\".installed | .[]" $minfo | 50 grep '/ravenwood-stats-checker$' 51)" 52 53if [[ "$script_path" == "" ]] ; then 54 echo "Error: $stats_checker_module script not found from $minfo" 55 exit 1 56fi 57 58# This is the directory where our input files are. 59script_dir="$ANDROID_BUILD_TOP/$(dirname "$script_path")" 60 61# Clear it before (re-)buildign the script, to make sure we won't have stale files. 62rm -fr "$script_dir" 63 64# Then build it, which will also collect the input files in the same dir. 65echo "Collecting the input files..." 66m "$stats_checker_module" 67 68# Start... 69 70echo "Files directory is: $script_dir" 71cd "$script_dir" 72 73dump() { 74 local jar=$1 75 local file=$2 76 77 # Remove the header row, and prepend the columns. 78 sed -e '1d' -e "s/^/$jar,$timestamp,/" $file 79} 80 81collect_stats() { 82 local out="$1" 83 local desc="$2" 84 { 85 # Copy the header, with the first column appended. 86 echo -n "Jar,Generated Date," 87 head -n 1 hoststubgen_framework-minus-apex_stats.csv 88 89 dump "framework-minus-apex" hoststubgen_framework-minus-apex_stats.csv 90 dump "service.core" hoststubgen_services.core_stats.csv 91 dump "framework-configinfrastructure" framework-configinfrastructure_stats.csv 92 dump "framework-statsd" framework-statsd_stats.csv 93 } > "$out" 94 95 echo "Stats CVS created at $out$desc" 96} 97 98collect_apis() { 99 local out="$1" 100 local desc="$2" 101 { 102 # Copy the header, with the first column appended. 103 echo -n "Jar,Generated Date," 104 head -n 1 hoststubgen_framework-minus-apex_apis.csv 105 106 dump "framework-minus-apex" hoststubgen_framework-minus-apex_apis.csv 107 dump "service.core" hoststubgen_services.core_apis.csv 108 dump "framework-configinfrastructure" framework-configinfrastructure_apis.csv 109 dump "framework-statsd" framework-statsd_apis.csv 110 } > "$out" 111 112 echo "API CVS created at $out$desc" 113} 114 115 116collect_stats $stats " (import it as 'ravenwood_stats')" 117collect_apis $apis " (import it as 'ravenwood_supported_apis2')" 118 119cp *keep_all.txt $keep_all_dir 120echo "Keep all files created at:" 121find $keep_all_dir -type f 122 123cp *dump.txt $dump_dir 124echo "Dump files created at:" 125find $dump_dir -type f 126