diff options
author | Vova Sharaienko <sharaienko@google.com> | 2023-11-23 01:15:46 +0000 |
---|---|---|
committer | Vova Sharaienko <sharaienko@google.com> | 2023-12-12 19:07:08 +0000 |
commit | 7d21b70df8d4ee112323b2ceae487c657359e2e2 (patch) | |
tree | 431f35b9ba3f97fb1ae2cdbf108ef0b04bcbe048 /java/com | |
parent | 9f2e02b806b7b5cb8949a0dbbe9755662b09e995 (diff) | |
download | modules-utils-7d21b70df8d4ee112323b2ceae487c657359e2e2.tar.gz |
[TeX] Removed JNI dependency
-used code gen to precompute metric ids hash & type
Bug: 276463350
Test: atest android.cts.statsdatom.express.ExpresslogAtomsTests
Test: atest ExpressLogApisTests
Change-Id: I4126d111f0003cec94d1c232e276cbc1cab8755d
Merged-In: I4126d111f0003cec94d1c232e276cbc1cab8755d
Diffstat (limited to 'java/com')
-rw-r--r-- | java/com/android/modules/expresslog/Android.bp | 6 | ||||
-rw-r--r-- | java/com/android/modules/expresslog/Counter.java | 8 | ||||
-rw-r--r-- | java/com/android/modules/expresslog/Histogram.java | 21 | ||||
-rw-r--r-- | java/com/android/modules/expresslog/Utils.java | 21 |
4 files changed, 22 insertions, 34 deletions
diff --git a/java/com/android/modules/expresslog/Android.bp b/java/com/android/modules/expresslog/Android.bp index cacc7f8..59504bd 100644 --- a/java/com/android/modules/expresslog/Android.bp +++ b/java/com/android/modules/expresslog/Android.bp @@ -28,12 +28,16 @@ java_library { libs: [ "framework-statsd", ], + static_libs: [ + "expresslog-catalog", + ], } genrule { name: "statslog-expresslog-java-gen", tools: ["stats-log-api-gen"], cmd: "$(location stats-log-api-gen) --java $(out) --module expresslog" + - " --javaPackage com.android.modules.expresslog --javaClass StatsExpressLog", + " --javaPackage com.android.modules.expresslog" + + " --javaClass StatsExpressLog", out: ["com/android/modules/expresslog/StatsExpressLog.java"], } diff --git a/java/com/android/modules/expresslog/Counter.java b/java/com/android/modules/expresslog/Counter.java index b788c3f..bcacb8b 100644 --- a/java/com/android/modules/expresslog/Counter.java +++ b/java/com/android/modules/expresslog/Counter.java @@ -18,8 +18,6 @@ package com.android.modules.expresslog; import android.annotation.NonNull; -import com.android.modules.expresslog.StatsExpressLog; - /** Counter encapsulates StatsD write API calls */ public final class Counter { @@ -49,7 +47,8 @@ public final class Counter { * @param amount to increment counter */ public static void logIncrement(@NonNull String metricId, long amount) { - final long metricIdHash = Utils.hashString(metricId); + final long metricIdHash = + MetricIds.getMetricIdHash(metricId, MetricIds.METRIC_TYPE_COUNTER); StatsExpressLog.write(StatsExpressLog.EXPRESS_EVENT_REPORTED, metricIdHash, amount); } @@ -60,7 +59,8 @@ public final class Counter { * @param amount to increment counter */ public static void logIncrementWithUid(@NonNull String metricId, int uid, long amount) { - final long metricIdHash = Utils.hashString(metricId); + final long metricIdHash = + MetricIds.getMetricIdHash(metricId, MetricIds.METRIC_TYPE_COUNTER_WITH_UID); StatsExpressLog.write( StatsExpressLog.EXPRESS_UID_EVENT_REPORTED, metricIdHash, amount, uid); } diff --git a/java/com/android/modules/expresslog/Histogram.java b/java/com/android/modules/expresslog/Histogram.java index be300bf..4f61c85 100644 --- a/java/com/android/modules/expresslog/Histogram.java +++ b/java/com/android/modules/expresslog/Histogram.java @@ -20,14 +20,12 @@ import android.annotation.FloatRange; import android.annotation.IntRange; import android.annotation.NonNull; -import com.android.modules.expresslog.StatsExpressLog; - import java.util.Arrays; /** Histogram encapsulates StatsD write API calls */ public final class Histogram { - private final long mMetricIdHash; + private final String mMetricId; private final BinOptions mBinOptions; /** @@ -37,7 +35,7 @@ public final class Histogram { * @param binOptions to calculate bin index for samples */ public Histogram(@NonNull String metricId, @NonNull BinOptions binOptions) { - mMetricIdHash = Utils.hashString(metricId); + mMetricId = metricId; mBinOptions = binOptions; } @@ -47,9 +45,10 @@ public final class Histogram { * @param sample value */ public void logSample(float sample) { + final long hash = MetricIds.getMetricIdHash(mMetricId, MetricIds.METRIC_TYPE_HISTOGRAM); final int binIndex = mBinOptions.getBinForSample(sample); - StatsExpressLog.write(StatsExpressLog.EXPRESS_HISTOGRAM_SAMPLE_REPORTED, mMetricIdHash, - /*count*/ 1, binIndex); + StatsExpressLog.write( + StatsExpressLog.EXPRESS_HISTOGRAM_SAMPLE_REPORTED, hash, /*count*/ 1, binIndex); } /** @@ -59,9 +58,15 @@ public final class Histogram { * @param sample value */ public void logSampleWithUid(int uid, float sample) { + final long hash = + MetricIds.getMetricIdHash(mMetricId, MetricIds.METRIC_TYPE_HISTOGRAM_WITH_UID); final int binIndex = mBinOptions.getBinForSample(sample); - StatsExpressLog.write(StatsExpressLog.EXPRESS_UID_HISTOGRAM_SAMPLE_REPORTED, - mMetricIdHash, /*count*/ 1, binIndex, uid); + StatsExpressLog.write( + StatsExpressLog.EXPRESS_UID_HISTOGRAM_SAMPLE_REPORTED, + hash, /*count*/ + 1, + binIndex, + uid); } /** Used by Histogram to map data sample to corresponding bin */ diff --git a/java/com/android/modules/expresslog/Utils.java b/java/com/android/modules/expresslog/Utils.java deleted file mode 100644 index fde90fc..0000000 --- a/java/com/android/modules/expresslog/Utils.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (C) 2023 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.modules.expresslog; - -final class Utils { - static native long hashString(String stringToHash); -} |