Debian Codegraph @

core/java/com/android/internal/expresslog/Counter.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2023 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 com.android.internal.expresslog;
18
19 import android.annotation.NonNull;
20
21 import com.android.internal.util.FrameworkStatsLog;
22
23 /** Counter encapsulates StatsD write API calls */
24 public final class Counter {
25
26 // Not instantiable.
27 private Counter() {}
28
29 /**
30 * Increments Telemetry Express Counter metric by 1
31 * @param metricId to log, no-op if metricId is not defined in the TeX catalog
32 * @hide
33 */
34 public static void logIncrement(@NonNull String metricId) {
35 logIncrement(metricId, 1);
36 }
37
38 /**
39 * Increments Telemetry Express Counter metric by 1
40 * @param metricId to log, no-op if metricId is not defined in the TeX catalog
41 * @param uid used as a dimension for the count metric
42 * @hide
43 */
44 public static void logIncrementWithUid(@NonNull String metricId, int uid) {
45 logIncrementWithUid(metricId, uid, 1);
46 }
47
48 /**
49 * Increments Telemetry Express Counter metric by arbitrary value
50 * @param metricId to log, no-op if metricId is not defined in the TeX catalog
51 * @param amount to increment counter
52 * @hide
53 */
54 public static void logIncrement(@NonNull String metricId, long amount) {
55 final long metricIdHash = Utils.hashString(metricId);
56 FrameworkStatsLog.write(FrameworkStatsLog.EXPRESS_EVENT_REPORTED, metricIdHash, amount);
57 }
58
59 /**
60 * Increments Telemetry Express Counter metric by arbitrary value
61 * @param metricId to log, no-op if metricId is not defined in the TeX catalog
62 * @param uid used as a dimension for the count metric
63 * @param amount to increment counter
64 * @hide
65 */
66 public static void logIncrementWithUid(@NonNull String metricId, int uid, long amount) {
67 final long metricIdHash = Utils.hashString(metricId);
68 FrameworkStatsLog.write(
69 FrameworkStatsLog.EXPRESS_UID_EVENT_REPORTED, metricIdHash, amount, uid);
70 }
71 }