Merge "Log pending odsign metrics on start"
This commit is contained in:
@@ -0,0 +1,86 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.server.pm.dex;
|
||||||
|
|
||||||
|
import android.util.Slog;
|
||||||
|
|
||||||
|
import com.android.internal.art.ArtStatsLog;
|
||||||
|
import com.android.internal.os.BackgroundThread;
|
||||||
|
|
||||||
|
import libcore.io.IoUtils;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class is responsible for reading metrics files generated by odsign and sending them to
|
||||||
|
* statsd. odsign can't send the stats directly to statsd, because statsd can't run until after
|
||||||
|
* odsign has completed. The code here is intended to run once per boot, since odsign runs at boot
|
||||||
|
* time.
|
||||||
|
*/
|
||||||
|
public class OdsignStatsLogger {
|
||||||
|
private static final String TAG = "OdsignStatsLogger";
|
||||||
|
|
||||||
|
// 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 COMPOS_METRIC_NAME = "comp_os_artifacts_check_record";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Arrange for stats to be uploaded in the background.
|
||||||
|
*/
|
||||||
|
public static void triggerStatsWrite() {
|
||||||
|
BackgroundThread.getExecutor().execute(OdsignStatsLogger::writeStats);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void writeStats() {
|
||||||
|
try {
|
||||||
|
String lines = IoUtils.readFileAsString(METRICS_FILE);
|
||||||
|
|
||||||
|
// Delete the file now so we don't upload it more than once, and don't keep trying
|
||||||
|
// to re-parse it if there is a problem.
|
||||||
|
if (!new File(METRICS_FILE).delete()) {
|
||||||
|
Slog.w(TAG, "Failed to delete metrics file");
|
||||||
|
}
|
||||||
|
|
||||||
|
// The format is simple - each line is a series of space separated tokens. The first is
|
||||||
|
// the metric name and subsequent ones are the metric values. The logic here must be
|
||||||
|
// kept in sync with system/security/ondevice-signing/StatsReporter.cpp.
|
||||||
|
|
||||||
|
for (String line : lines.split("\n")) {
|
||||||
|
String[] metrics = line.split(" ");
|
||||||
|
|
||||||
|
if (metrics.length != 4 || !metrics[0].equals(COMPOS_METRIC_NAME)) {
|
||||||
|
Slog.w(TAG, "Malformed metrics file");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean currentArtifactsOk = metrics[1].equals("1");
|
||||||
|
boolean compOsPendingArtifactsExists = metrics[2].equals("1");
|
||||||
|
boolean useCompOsGeneratedArtifacts = metrics[3].equals("1");
|
||||||
|
|
||||||
|
ArtStatsLog.write(ArtStatsLog.EARLY_BOOT_COMP_OS_ARTIFACTS_CHECK_REPORTED,
|
||||||
|
currentArtifactsOk, compOsPendingArtifactsExists,
|
||||||
|
useCompOsGeneratedArtifacts);
|
||||||
|
}
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
// This is normal and probably means no new metrics have been generated.
|
||||||
|
} catch (IOException e) {
|
||||||
|
Slog.w(TAG, "Reading metrics file failed", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -159,6 +159,7 @@ import com.android.server.pm.OtaDexoptService;
|
|||||||
import com.android.server.pm.PackageManagerService;
|
import com.android.server.pm.PackageManagerService;
|
||||||
import com.android.server.pm.ShortcutService;
|
import com.android.server.pm.ShortcutService;
|
||||||
import com.android.server.pm.UserManagerService;
|
import com.android.server.pm.UserManagerService;
|
||||||
|
import com.android.server.pm.dex.OdsignStatsLogger;
|
||||||
import com.android.server.pm.dex.SystemServerDexLoadReporter;
|
import com.android.server.pm.dex.SystemServerDexLoadReporter;
|
||||||
import com.android.server.pm.verify.domain.DomainVerificationService;
|
import com.android.server.pm.verify.domain.DomainVerificationService;
|
||||||
import com.android.server.policy.AppOpsPolicy;
|
import com.android.server.policy.AppOpsPolicy;
|
||||||
@@ -2887,6 +2888,14 @@ public final class SystemServer implements Dumpable {
|
|||||||
setIncrementalServiceSystemReady(mIncrementalServiceHandle);
|
setIncrementalServiceSystemReady(mIncrementalServiceHandle);
|
||||||
t.traceEnd();
|
t.traceEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
t.traceBegin("OdsignStatsLogger");
|
||||||
|
try {
|
||||||
|
OdsignStatsLogger.triggerStatsWrite();
|
||||||
|
} catch (Throwable e) {
|
||||||
|
reportWtf("Triggering OdsignStatsLogger", e);
|
||||||
|
}
|
||||||
|
t.traceEnd();
|
||||||
}, t);
|
}, t);
|
||||||
|
|
||||||
t.traceBegin("StartSystemUI");
|
t.traceBegin("StartSystemUI");
|
||||||
|
|||||||
Reference in New Issue
Block a user