Add util scripts to download profiles for given apps.
There are two scripts in total
*fetch_profile_info.sh: will get the info (pkg name, version, device, sdk, blob key and etc from the PROD database)
*fetch_blob_key.sh: will download the content of the profile based on the blob key.
Test: Run the scripts
Bug: 210107938
Change-Id: I406f08ba42f359853aee94648f22018765f17dfc
diff --git a/tools/cloud_profiles/fetch_blob_key.sh b/tools/cloud_profiles/fetch_blob_key.sh
new file mode 100644
index 0000000..b8dd024
--- /dev/null
+++ b/tools/cloud_profiles/fetch_blob_key.sh
@@ -0,0 +1,11 @@
+#!/bin/bash
+# Running this script requires "gcert" login.
+#
+# This script is used to fetch data from blob store based on the blob key.
+# For example, `bash fetch_blob_key.sh abcdefg output.profile`
+BLOB_KEY=$1
+OUTPUT=$2
+
+blob_id=$(echo "$BLOB_KEY" | base64 --decode | gqui from rawproto:- proto blobstore.BlobRef | grep "BlobID :" | awk -F' ' '{print $3}')
+blob_id=$(echo "$blob_id" | sed -e 's/^"//' -e 's/"$//')
+/google/bin/releases/blobstore2/tools/bs2/bs2 read "$blob_id" > "$OUTPUT"
diff --git a/tools/cloud_profiles/fetch_profile_info.sh b/tools/cloud_profiles/fetch_profile_info.sh
new file mode 100644
index 0000000..ab508cc
--- /dev/null
+++ b/tools/cloud_profiles/fetch_profile_info.sh
@@ -0,0 +1,25 @@
+#!/bin/bash
+# Running this script requires "gcert" login.
+#
+# This script is used to query the PROD database to fetch the info about the ART
+# cloud profiles for a given package name and version code (optional)
+# For example, `bash fetch_profile.sh com.abc`
+# or `bash fetch_profile com.abc 123`
+# The output if any will contain a "blob_key" for each profile info and
+# it could be used to download the content of the profile via
+# "fetch_blob_key.sh".
+if [[ "$#" == 1 ]];
+then
+ PKG=$1
+ echo "fetching for $PKG..."
+ span sql /span/global/play-gateway:art "select PackageName, VersionCode, DerivedId, SplitName, DeviceType, SdkVersion, ApkSignType, PlayArtProfilePublishStatus.profile_dex_metadata.blob_key FROM AggregatedPlayArtProfileV3 WHERE PlayArtProfilePublishStatus IS NOT NULL AND PackageName='$1';";
+ echo "$PKG"
+elif [[ "$#" == 2 ]];
+then
+ PKG=$1
+ VERSION=$2
+ echo "fetching for $PKG $VERSION..."
+ span sql /span/global/play-gateway:art "select PackageName, VersionCode, DerivedId, SplitName, DeviceType, SdkVersion, ApkSignType, PlayArtProfilePublishStatus.profile_dex_metadata.blob_key FROM AggregatedPlayArtProfileV3 WHERE PlayArtProfilePublishStatus IS NOT NULL AND PackageName='$1' and VersionCode=$2;";
+else
+ echo "Illegal number of parameters. It should be one or two."
+fi