aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVova Sharaienko <sharaienko@google.com>2023-12-13 19:52:10 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2023-12-13 19:52:10 +0000
commit8757209fa236dddeddbcbd27f139b3cad6c3ff73 (patch)
tree84f421f4b4695d671fe5998912b80dec077f31f3
parentaa3d103b484db6ca05b1a98b857a31cda890b8f9 (diff)
parent14e936072e159a809e5fb803dca2d6f214355187 (diff)
downloadmodules-utils-8757209fa236dddeddbcbd27f139b3cad6c3ff73.tar.gz
Merge "[TeX] Removed JNI dependency" into main am: 36c0b3e34f am: 14e936072e
Original change: https://android-review.googlesource.com/c/platform/frameworks/libs/modules-utils/+/2542071 Change-Id: I2b9d699e845e0035dcc10a6ebec9592c68753c1e Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--java/com/android/modules/expresslog/Android.bp6
-rw-r--r--java/com/android/modules/expresslog/Counter.java8
-rw-r--r--java/com/android/modules/expresslog/Histogram.java21
-rw-r--r--java/com/android/modules/expresslog/Utils.java21
-rw-r--r--javatests/com/android/modules/expresslog/Android.bp33
-rw-r--r--javatests/com/android/modules/expresslog/ScaledRangeOptionsTest.java4
-rw-r--r--javatests/com/android/modules/expresslog/UniformOptionsTest.java4
-rw-r--r--javatests/com/android/modules/expresslog/jni/.clang-format17
-rw-r--r--javatests/com/android/modules/expresslog/jni/onload.cpp40
-rw-r--r--jni/expresslog/.clang-format17
-rw-r--r--jni/expresslog/Android.bp53
-rw-r--r--jni/expresslog/com_android_modules_expresslog_Utils.cpp85
12 files changed, 22 insertions, 287 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);
-}
diff --git a/javatests/com/android/modules/expresslog/Android.bp b/javatests/com/android/modules/expresslog/Android.bp
index dd52750..9396e17 100644
--- a/javatests/com/android/modules/expresslog/Android.bp
+++ b/javatests/com/android/modules/expresslog/Android.bp
@@ -37,40 +37,7 @@ android_test {
"android.test.runner",
],
- jni_libs: [
- "libexpresslog_test_jni",
- ],
-
test_suites: [
"general-tests",
],
}
-
-cc_library_shared {
- name: "libexpresslog_test_jni",
-
- sdk_version: "current",
- min_sdk_version: "30",
-
- cflags: [
- "-Wall",
- "-Werror",
- "-Wextra",
-
- "-DNAMESPACE_FOR_HASH_FUNCTIONS=farmhash",
- ],
- srcs: [
- "jni/onload.cpp",
- ],
- header_libs: [
- "liblog_headers",
- "libnativehelper_header_only",
- ],
- shared_libs: [
- "liblog",
- ],
- static_libs: [
- "libexpresslog_jni",
- "libtextclassifier_hash_static",
- ],
-}
diff --git a/javatests/com/android/modules/expresslog/ScaledRangeOptionsTest.java b/javatests/com/android/modules/expresslog/ScaledRangeOptionsTest.java
index 8defce7..1c42788 100644
--- a/javatests/com/android/modules/expresslog/ScaledRangeOptionsTest.java
+++ b/javatests/com/android/modules/expresslog/ScaledRangeOptionsTest.java
@@ -27,10 +27,6 @@ import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
@SmallTest
public class ScaledRangeOptionsTest {
- static {
- System.loadLibrary("expresslog_test_jni");
- }
-
private static final String TAG = ScaledRangeOptionsTest.class.getSimpleName();
@Test
diff --git a/javatests/com/android/modules/expresslog/UniformOptionsTest.java b/javatests/com/android/modules/expresslog/UniformOptionsTest.java
index 3cc03ec..cad4c3f 100644
--- a/javatests/com/android/modules/expresslog/UniformOptionsTest.java
+++ b/javatests/com/android/modules/expresslog/UniformOptionsTest.java
@@ -26,10 +26,6 @@ import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
@SmallTest
public class UniformOptionsTest {
- static {
- System.loadLibrary("expresslog_test_jni");
- }
-
private static final String TAG = UniformOptionsTest.class.getSimpleName();
@Test
diff --git a/javatests/com/android/modules/expresslog/jni/.clang-format b/javatests/com/android/modules/expresslog/jni/.clang-format
deleted file mode 100644
index cead3a0..0000000
--- a/javatests/com/android/modules/expresslog/jni/.clang-format
+++ /dev/null
@@ -1,17 +0,0 @@
-BasedOnStyle: Google
-AllowShortIfStatementsOnASingleLine: true
-AllowShortFunctionsOnASingleLine: false
-AllowShortLoopsOnASingleLine: true
-BinPackArguments: true
-BinPackParameters: true
-ColumnLimit: 100
-CommentPragmas: NOLINT:.*
-ContinuationIndentWidth: 8
-DerivePointerAlignment: false
-IndentWidth: 4
-PointerAlignment: Left
-TabWidth: 4
-AccessModifierOffset: -4
-IncludeCategories:
- - Regex: '^"Log\.h"'
- Priority: -1
diff --git a/javatests/com/android/modules/expresslog/jni/onload.cpp b/javatests/com/android/modules/expresslog/jni/onload.cpp
deleted file mode 100644
index a112467..0000000
--- a/javatests/com/android/modules/expresslog/jni/onload.cpp
+++ /dev/null
@@ -1,40 +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.
- */
-
-#define LOG_TAG "TeX"
-
-#include <jni.h>
-#include <log/log.h>
-
-namespace android {
-extern int register_com_android_modules_expresslog_Utils(JNIEnv* env);
-} // namespace android
-
-using namespace android;
-
-extern "C" jint JNI_OnLoad(JavaVM* vm, void* /* reserved */) {
- JNIEnv* env = NULL;
- jint result = -1;
-
- if (vm->GetEnv((void**)&env, JNI_VERSION_1_4) != JNI_OK) {
- ALOGE("GetEnv failed!");
- return result;
- }
- ALOG_ASSERT(env, "Could not retrieve the env!");
-
- register_com_android_modules_expresslog_Utils(env);
- return JNI_VERSION_1_4;
-}
diff --git a/jni/expresslog/.clang-format b/jni/expresslog/.clang-format
deleted file mode 100644
index cead3a0..0000000
--- a/jni/expresslog/.clang-format
+++ /dev/null
@@ -1,17 +0,0 @@
-BasedOnStyle: Google
-AllowShortIfStatementsOnASingleLine: true
-AllowShortFunctionsOnASingleLine: false
-AllowShortLoopsOnASingleLine: true
-BinPackArguments: true
-BinPackParameters: true
-ColumnLimit: 100
-CommentPragmas: NOLINT:.*
-ContinuationIndentWidth: 8
-DerivePointerAlignment: false
-IndentWidth: 4
-PointerAlignment: Left
-TabWidth: 4
-AccessModifierOffset: -4
-IncludeCategories:
- - Regex: '^"Log\.h"'
- Priority: -1
diff --git a/jni/expresslog/Android.bp b/jni/expresslog/Android.bp
deleted file mode 100644
index 7bef576..0000000
--- a/jni/expresslog/Android.bp
+++ /dev/null
@@ -1,53 +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.
-
-// JNI library for Utils.hashString
-package {
- default_applicable_licenses: ["Android-Apache-2.0"],
-}
-
-cc_library_static {
- name: "libexpresslog_jni",
-
- sdk_version: "current",
- min_sdk_version: "30",
-
- cflags: [
- "-Wall",
- "-Werror",
- "-Wextra",
-
- "-DNAMESPACE_FOR_HASH_FUNCTIONS=farmhash",
- ],
- srcs: [
- "com_android_modules_expresslog_Utils.cpp",
- ],
- header_libs: [
- "liblog_headers",
- "libnativehelper_header_only",
- "libtextclassifier_hash_headers",
- ],
- shared_libs: [
- "liblog",
- ],
- static_libs: [
- "libtextclassifier_hash_static",
- ],
- visibility: ["//visibility:public"],
- apex_available: [
- "//apex_available:anyapex",
- "//apex_available:platform",
- ],
-}
diff --git a/jni/expresslog/com_android_modules_expresslog_Utils.cpp b/jni/expresslog/com_android_modules_expresslog_Utils.cpp
deleted file mode 100644
index ed4d0ed..0000000
--- a/jni/expresslog/com_android_modules_expresslog_Utils.cpp
+++ /dev/null
@@ -1,85 +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.
- */
-
-#define LOG_NAMESPACE "TeX.tag."
-#define LOG_TAG "TeX"
-
-#include <log/log.h>
-#include <nativehelper/scoped_local_ref.h>
-#include <nativehelper/scoped_utf_chars.h>
-#include <utils/hash/farmhash.h>
-
-// ----------------------------------------------------------------------------
-// JNI Glue
-// ----------------------------------------------------------------------------
-
-static jclass gStringClass = nullptr;
-
-/**
- * Class: com_android_modules_expresslog_Utils
- * Method: hashString
- * Signature: (Ljava/lang/String;)J
- */
-static jlong hashString(JNIEnv* env, jclass /*class*/, jstring metricNameObj) {
- ScopedUtfChars name(env, metricNameObj);
- if (name.c_str() == nullptr) {
- return 0;
- }
-
- return static_cast<jlong>(farmhash::Fingerprint64(name.c_str(), name.size()));
-}
-
-static const JNINativeMethod gMethods[] = {
- {"hashString", "(Ljava/lang/String;)J", (void*)hashString},
-};
-
-namespace android {
-
-int register_com_android_modules_expresslog_Utils(JNIEnv* env, const char* const utilsClassName) {
- static const char* const kStringClassName = "java/lang/String";
-
- ScopedLocalRef<jclass> utilsCls(env, env->FindClass(utilsClassName));
- if (utilsCls.get() == nullptr) {
- ALOGE("jni expresslog registration failure, class not found '%s'", utilsClassName);
- return JNI_ERR;
- }
-
- jclass stringClass = env->FindClass(kStringClassName);
- if (stringClass == nullptr) {
- ALOGE("jni expresslog registration failure, class not found '%s'", kStringClassName);
- return JNI_ERR;
- }
- gStringClass = static_cast<jclass>(env->NewGlobalRef(stringClass));
- if (gStringClass == nullptr) {
- ALOGE("jni expresslog Unable to create global reference '%s'", kStringClassName);
- return JNI_ERR;
- }
-
- const jint count = sizeof(gMethods) / sizeof(gMethods[0]);
- int status = env->RegisterNatives(utilsCls.get(), gMethods, count);
- if (status < 0) {
- ALOGE("jni expresslog registration failure, status: %d", status);
- return JNI_ERR;
- }
- return JNI_VERSION_1_4;
-}
-
-int register_com_android_modules_expresslog_Utils(JNIEnv* env) {
- static const char* const kUtilsClassName = "com/android/modules/expresslog/Utils";
- return register_com_android_modules_expresslog_Utils(env, kUtilsClassName);
-}
-
-} // namespace android