• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.modules.expresslog;
18 
19 import android.annotation.NonNull;
20 
21 import com.android.modules.expresslog.StatsExpressLog;
22 
23 /** Counter encapsulates StatsD write API calls */
24 public final class Counter {
25 
26     // Not instantiable.
Counter()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      */
logIncrement(@onNull String metricId)33     public static void logIncrement(@NonNull String metricId) {
34         logIncrement(metricId, 1);
35     }
36 
37     /**
38      * Increments Telemetry Express Counter metric by 1
39      * @param metricId to log, no-op if metricId is not defined in the TeX catalog
40      * @param uid used as a dimension for the count metric
41      */
logIncrementWithUid(@onNull String metricId, int uid)42     public static void logIncrementWithUid(@NonNull String metricId, int uid) {
43         logIncrementWithUid(metricId, uid, 1);
44     }
45 
46     /**
47      * Increments Telemetry Express Counter metric by arbitrary value
48      * @param metricId to log, no-op if metricId is not defined in the TeX catalog
49      * @param amount to increment counter
50      */
logIncrement(@onNull String metricId, long amount)51     public static void logIncrement(@NonNull String metricId, long amount) {
52         final long metricIdHash = Utils.hashString(metricId);
53         StatsExpressLog.write(StatsExpressLog.EXPRESS_EVENT_REPORTED, metricIdHash, amount);
54     }
55 
56     /**
57      * Increments Telemetry Express Counter metric by arbitrary value
58      * @param metricId to log, no-op if metricId is not defined in the TeX catalog
59      * @param uid used as a dimension for the count metric
60      * @param amount to increment counter
61      */
logIncrementWithUid(@onNull String metricId, int uid, long amount)62     public static void logIncrementWithUid(@NonNull String metricId, int uid, long amount) {
63         final long metricIdHash = Utils.hashString(metricId);
64         StatsExpressLog.write(
65             StatsExpressLog.EXPRESS_UID_EVENT_REPORTED, metricIdHash, amount, uid);
66     }
67 }
68