Merge "Read odsign metrics from a file and write to statsd." am: b754daeace am: 6ddee0b001

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2282795

Change-Id: I72f3887c8fd200949f039a93a294be374a61f27d
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Jiakai Zhang
2022-11-03 19:13:33 +00:00
committed by Automerger Merge Worker

View File

@@ -39,6 +39,7 @@ public class OdsignStatsLogger {
// These need to be kept in sync with system/security/ondevice-signing/StatsReporter.{h, cpp}. // These need to be kept in sync with system/security/ondevice-signing/StatsReporter.{h, cpp}.
private static final String METRICS_FILE = "/data/misc/odsign/metrics/odsign-metrics.txt"; private static final String METRICS_FILE = "/data/misc/odsign/metrics/odsign-metrics.txt";
private static final String COMPOS_METRIC_NAME = "comp_os_artifacts_check_record"; private static final String COMPOS_METRIC_NAME = "comp_os_artifacts_check_record";
private static final String ODSIGN_METRIC_NAME = "odsign_record";
/** /**
* Arrange for stats to be uploaded in the background. * Arrange for stats to be uploaded in the background.
@@ -64,18 +65,45 @@ public class OdsignStatsLogger {
for (String line : lines.split("\n")) { for (String line : lines.split("\n")) {
String[] metrics = line.split(" "); String[] metrics = line.split(" ");
if (metrics.length != 4 || !metrics[0].equals(COMPOS_METRIC_NAME)) { if (line.isEmpty() || metrics.length < 1) {
Slog.w(TAG, "Malformed metrics file"); Slog.w(TAG, "Empty metrics line");
break; continue;
} }
boolean currentArtifactsOk = metrics[1].equals("1"); switch (metrics[0]) {
boolean compOsPendingArtifactsExists = metrics[2].equals("1"); case COMPOS_METRIC_NAME: {
boolean useCompOsGeneratedArtifacts = metrics[3].equals("1"); if (metrics.length != 4) {
Slog.w(TAG, "Malformed CompOS metrics line '" + line + "'");
continue;
}
ArtStatsLog.write(ArtStatsLog.EARLY_BOOT_COMP_OS_ARTIFACTS_CHECK_REPORTED, boolean currentArtifactsOk = metrics[1].equals("1");
currentArtifactsOk, compOsPendingArtifactsExists, boolean compOsPendingArtifactsExists = metrics[2].equals("1");
useCompOsGeneratedArtifacts); boolean useCompOsGeneratedArtifacts = metrics[3].equals("1");
ArtStatsLog.write(ArtStatsLog.EARLY_BOOT_COMP_OS_ARTIFACTS_CHECK_REPORTED,
currentArtifactsOk, compOsPendingArtifactsExists,
useCompOsGeneratedArtifacts);
break;
}
case ODSIGN_METRIC_NAME: {
if (metrics.length != 2) {
Slog.w(TAG, "Malformed odsign metrics line '" + line + "'");
continue;
}
try {
int status = Integer.parseInt(metrics[1]);
ArtStatsLog.write(ArtStatsLog.ODSIGN_REPORTED, status);
} catch (NumberFormatException e) {
Slog.w(TAG, "Malformed odsign metrics line '" + line + "'");
}
break;
}
default:
Slog.w(TAG, "Malformed metrics line '" + line + "'");
}
} }
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
// This is normal and probably means no new metrics have been generated. // This is normal and probably means no new metrics have been generated.