Debian Codegraph @

core/java/android/util/SystemConfigFileCommitEventLogger.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2020 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
17 package android.util;
18
19 import android.annotation.NonNull;
20 import android.annotation.SystemApi;
21 import android.annotation.UptimeMillisLong;
22 import android.os.SystemClock;
23
24 /**
25 * Writes an EventLog event capturing the performance of system config file writes.
26 * The event log entry is formatted like this:
27 * <code>525000 commit_sys_config_file (name|3),(time|2|3)</code>, where <code>name</code> is
28 * a short unique name representing the type of configuration file and <code>time</code> is
29 * duration in the {@link SystemClock#uptimeMillis()} time base.
30 *
31 * @hide
32 */
33 @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
34 public class SystemConfigFileCommitEventLogger {
35 private final String mName;
36 private long mStartTime;
37
38 /**
39 * @param name The short name of the config file that is included in the event log event,
40 * e.g. "jobs", "appops", "uri-grants" etc.
41 */
42 public SystemConfigFileCommitEventLogger(@NonNull String name) {
43 mName = name;
44 }
45
46 /**
47 * Override the start timestamp. Use this method when it's desired to include the time
48 * taken by the preparation of the configuration data in the overall duration of the
49 * "commitSysConfigFile" event.
50 *
51 * @param startTime Overridden start time, in system uptime milliseconds
52 */
53 public void setStartTime(@UptimeMillisLong long startTime) {
54 mStartTime = startTime;
55 }
56
57 /**
58 * Invoked just before the configuration file writing begins.
59 */
60 void onStartWrite() {
61 if (mStartTime == 0) {
62 mStartTime = SystemClock.uptimeMillis();
63 }
64 }
65
66 /**
67 * Invoked just after the configuration file writing ends.
68 */
69 void onFinishWrite() {
70 com.android.internal.logging.EventLogTags.writeCommitSysConfigFile(mName,
71 SystemClock.uptimeMillis() - mStartTime);
72 }
73 }