Merge "[TeX] Introduced Telemetry Express Logging APIs" am: 42bf7a986d am: 05c391241f
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2272886 Change-Id: Ie1afd3d68f0768f77d15d4017ebf88a8534347c9 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
47
core/java/com/android/internal/expresslog/Counter.java
Normal file
47
core/java/com/android/internal/expresslog/Counter.java
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2022 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.internal.expresslog;
|
||||||
|
|
||||||
|
import android.annotation.NonNull;
|
||||||
|
|
||||||
|
import com.android.internal.util.FrameworkStatsLog;
|
||||||
|
|
||||||
|
/** Counter encapsulates StatsD write API calls */
|
||||||
|
public final class Counter {
|
||||||
|
|
||||||
|
// Not instantiable.
|
||||||
|
private Counter() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Increments Telemetry Express Counter metric by 1
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public static void logIncrement(@NonNull String metricId) {
|
||||||
|
logIncrement(metricId, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Increments Telemetry Express Counter metric by arbitrary value
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public static void logIncrement(@NonNull String metricId, long amount) {
|
||||||
|
final long metricIdHash = hashString(metricId);
|
||||||
|
FrameworkStatsLog.write(FrameworkStatsLog.EXPRESS_EVENT_REPORTED, metricIdHash, amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static native long hashString(String stringToHash);
|
||||||
|
}
|
||||||
@@ -34,6 +34,8 @@ cc_library_shared {
|
|||||||
"-Wno-error=deprecated-declarations",
|
"-Wno-error=deprecated-declarations",
|
||||||
"-Wunused",
|
"-Wunused",
|
||||||
"-Wunreachable-code",
|
"-Wunreachable-code",
|
||||||
|
|
||||||
|
"-DNAMESPACE_FOR_HASH_FUNCTIONS=farmhash",
|
||||||
],
|
],
|
||||||
|
|
||||||
cppflags: ["-Wno-conversion-null"],
|
cppflags: ["-Wno-conversion-null"],
|
||||||
@@ -211,6 +213,7 @@ cc_library_shared {
|
|||||||
"android_content_res_Configuration.cpp",
|
"android_content_res_Configuration.cpp",
|
||||||
"android_security_Scrypt.cpp",
|
"android_security_Scrypt.cpp",
|
||||||
"com_android_internal_content_om_OverlayConfig.cpp",
|
"com_android_internal_content_om_OverlayConfig.cpp",
|
||||||
|
"com_android_internal_expresslog_Counter.cpp",
|
||||||
"com_android_internal_net_NetworkUtilsInternal.cpp",
|
"com_android_internal_net_NetworkUtilsInternal.cpp",
|
||||||
"com_android_internal_os_ClassLoaderFactory.cpp",
|
"com_android_internal_os_ClassLoaderFactory.cpp",
|
||||||
"com_android_internal_os_FuseAppLoop.cpp",
|
"com_android_internal_os_FuseAppLoop.cpp",
|
||||||
@@ -244,6 +247,7 @@ cc_library_shared {
|
|||||||
"libscrypt_static",
|
"libscrypt_static",
|
||||||
"libstatssocket_lazy",
|
"libstatssocket_lazy",
|
||||||
"libskia",
|
"libskia",
|
||||||
|
"libtextclassifier_hash_static",
|
||||||
],
|
],
|
||||||
|
|
||||||
shared_libs: [
|
shared_libs: [
|
||||||
@@ -326,6 +330,7 @@ cc_library_shared {
|
|||||||
header_libs: [
|
header_libs: [
|
||||||
"bionic_libc_platform_headers",
|
"bionic_libc_platform_headers",
|
||||||
"dnsproxyd_protocol_headers",
|
"dnsproxyd_protocol_headers",
|
||||||
|
"libtextclassifier_hash_headers",
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
host: {
|
host: {
|
||||||
|
|||||||
@@ -193,6 +193,7 @@ extern int register_android_security_Scrypt(JNIEnv *env);
|
|||||||
extern int register_com_android_internal_content_F2fsUtils(JNIEnv* env);
|
extern int register_com_android_internal_content_F2fsUtils(JNIEnv* env);
|
||||||
extern int register_com_android_internal_content_NativeLibraryHelper(JNIEnv *env);
|
extern int register_com_android_internal_content_NativeLibraryHelper(JNIEnv *env);
|
||||||
extern int register_com_android_internal_content_om_OverlayConfig(JNIEnv *env);
|
extern int register_com_android_internal_content_om_OverlayConfig(JNIEnv *env);
|
||||||
|
extern int register_com_android_internal_expresslog_Counter(JNIEnv* env);
|
||||||
extern int register_com_android_internal_net_NetworkUtilsInternal(JNIEnv* env);
|
extern int register_com_android_internal_net_NetworkUtilsInternal(JNIEnv* env);
|
||||||
extern int register_com_android_internal_os_ClassLoaderFactory(JNIEnv* env);
|
extern int register_com_android_internal_os_ClassLoaderFactory(JNIEnv* env);
|
||||||
extern int register_com_android_internal_os_FuseAppLoop(JNIEnv* env);
|
extern int register_com_android_internal_os_FuseAppLoop(JNIEnv* env);
|
||||||
@@ -1584,6 +1585,7 @@ static const RegJNIRec gRegJNI[] = {
|
|||||||
REG_JNI(register_android_os_SharedMemory),
|
REG_JNI(register_android_os_SharedMemory),
|
||||||
REG_JNI(register_android_os_incremental_IncrementalManager),
|
REG_JNI(register_android_os_incremental_IncrementalManager),
|
||||||
REG_JNI(register_com_android_internal_content_om_OverlayConfig),
|
REG_JNI(register_com_android_internal_content_om_OverlayConfig),
|
||||||
|
REG_JNI(register_com_android_internal_expresslog_Counter),
|
||||||
REG_JNI(register_com_android_internal_net_NetworkUtilsInternal),
|
REG_JNI(register_com_android_internal_net_NetworkUtilsInternal),
|
||||||
REG_JNI(register_com_android_internal_os_ClassLoaderFactory),
|
REG_JNI(register_com_android_internal_os_ClassLoaderFactory),
|
||||||
REG_JNI(register_com_android_internal_os_LongArrayMultiStateCounter),
|
REG_JNI(register_com_android_internal_os_LongArrayMultiStateCounter),
|
||||||
|
|||||||
57
core/jni/com_android_internal_expresslog_Counter.cpp
Normal file
57
core/jni/com_android_internal_expresslog_Counter.cpp
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2022 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <nativehelper/JNIHelp.h>
|
||||||
|
#include <utils/hash/farmhash.h>
|
||||||
|
|
||||||
|
#include "core_jni_helpers.h"
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// JNI Glue
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
static jclass g_stringClass = nullptr;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class: com_android_internal_expresslog_Counter
|
||||||
|
* 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 g_methods[] = {
|
||||||
|
{"hashString", "(Ljava/lang/String;)J", (void*)hashString},
|
||||||
|
};
|
||||||
|
|
||||||
|
static const char* const kCounterPathName = "com/android/internal/expresslog/Counter";
|
||||||
|
|
||||||
|
namespace android {
|
||||||
|
|
||||||
|
int register_com_android_internal_expresslog_Counter(JNIEnv* env) {
|
||||||
|
jclass stringClass = FindClassOrDie(env, "java/lang/String");
|
||||||
|
g_stringClass = MakeGlobalRefOrDie(env, stringClass);
|
||||||
|
|
||||||
|
return RegisterMethodsOrDie(env, kCounterPathName, g_methods, NELEM(g_methods));
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace android
|
||||||
Reference in New Issue
Block a user