android_os_Trace.cpp revision 481c1570dc5cdf58265b53f657801709dd05d1df
1/*
2 * Copyright (C) 2012 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#define LOG_TAG "Trace"
18
19#include <JNIHelp.h>
20#include <ScopedUtfChars.h>
21
22#include <utils/Trace.h>
23#include <cutils/log.h>
24
25namespace android {
26
27static jlong android_os_Trace_nativeGetEnabledTags(JNIEnv* env, jclass clazz) {
28    return Tracer::getEnabledTags();
29}
30
31static void android_os_Trace_nativeTraceCounter(JNIEnv* env, jclass clazz,
32        jlong tag, jstring nameStr, jint value) {
33    ScopedUtfChars name(env, nameStr);
34    Tracer::traceCounter(tag, name.c_str(), value);
35}
36
37static void android_os_Trace_nativeTraceBegin(JNIEnv* env, jclass clazz,
38        jlong tag, jstring nameStr) {
39    ScopedUtfChars name(env, nameStr);
40    Tracer::traceBegin(tag, name.c_str());
41}
42
43static void android_os_Trace_nativeTraceEnd(JNIEnv* env, jclass clazz,
44        jlong tag) {
45    Tracer::traceEnd(tag);
46}
47
48static JNINativeMethod gTraceMethods[] = {
49    /* name, signature, funcPtr */
50    { "nativeGetEnabledTags",
51            "()J",
52            (void*)android_os_Trace_nativeGetEnabledTags },
53    { "nativeTraceCounter",
54            "(JLjava/lang/String;I)V",
55            (void*)android_os_Trace_nativeTraceCounter },
56    { "nativeTraceBegin",
57            "(JLjava/lang/String;)V",
58            (void*)android_os_Trace_nativeTraceBegin },
59    { "nativeTraceEnd",
60            "(J)V",
61            (void*)android_os_Trace_nativeTraceEnd },
62};
63
64int register_android_os_Trace(JNIEnv* env) {
65    int res = jniRegisterNativeMethods(env, "android/os/Trace",
66            gTraceMethods, NELEM(gTraceMethods));
67    LOG_FATAL_IF(res < 0, "Unable to register native methods.");
68
69    return 0;
70}
71
72} // namespace android
73