Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6fa4ac73 authored by Zimuzo Ezeozue's avatar Zimuzo Ezeozue Committed by Android (Google) Code Review
Browse files

Merge "Improve PerfettoTrace API" into main

parents b91a2206 ad0b0ed2
Loading
Loading
Loading
Loading
+44 −126
Original line number Original line Diff line number Diff line
@@ -22,7 +22,6 @@ import dalvik.annotation.optimization.FastNative;
import libcore.util.NativeAllocationRegistry;
import libcore.util.NativeAllocationRegistry;


import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;


/**
/**
 * Writes trace events to the perfetto trace buffer. These trace events can be
 * Writes trace events to the perfetto trace buffer. These trace events can be
@@ -72,7 +71,7 @@ public final class PerfettoTrace {
         * @param name The category name.
         * @param name The category name.
         */
         */
        public Category(String name) {
        public Category(String name) {
            this(name, null, null);
            this(name, "", "");
        }
        }


        /**
        /**
@@ -82,7 +81,7 @@ public final class PerfettoTrace {
         * @param tag An atrace tag name that this category maps to.
         * @param tag An atrace tag name that this category maps to.
         */
         */
        public Category(String name, String tag) {
        public Category(String name, String tag) {
            this(name, tag, null);
            this(name, tag, "");
        }
        }


        /**
        /**
@@ -155,9 +154,6 @@ public final class PerfettoTrace {
        }
        }
    }
    }


    @FastNative
    private static native void native_event(int type, long tag, String name, long ptr);

    @CriticalNative
    @CriticalNative
    private static native long native_get_process_track_uuid();
    private static native long native_get_process_track_uuid();


@@ -167,179 +163,101 @@ public final class PerfettoTrace {
    @FastNative
    @FastNative
    private static native void native_activate_trigger(String name, int ttlMs);
    private static native void native_activate_trigger(String name, int ttlMs);


    /**
     * Writes a trace message to indicate a given section of code was invoked.
     *
     * @param category The perfetto category pointer.
     * @param eventName The event name to appear in the trace.
     * @param extra The extra arguments.
     */
    public static void instant(Category category, String eventName, PerfettoTrackEventExtra extra) {
        if (!category.isEnabled()) {
            return;
        }

        native_event(PERFETTO_TE_TYPE_INSTANT, category.getPtr(), eventName, extra.getPtr());
        extra.reset();
    }

    /**
     * Writes a trace message to indicate a given section of code was invoked.
     *
     * @param category The perfetto category.
     * @param eventName The event name to appear in the trace.
     * @param extraConfig Consumer for the extra arguments.
     */
    public static void instant(Category category, String eventName,
            Consumer<PerfettoTrackEventExtra.Builder> extraConfig) {
        PerfettoTrackEventExtra.Builder extra = PerfettoTrackEventExtra.builder();
        extraConfig.accept(extra);
        instant(category, eventName, extra.build());
    }

    /**
    /**
     * Writes a trace message to indicate a given section of code was invoked.
     * Writes a trace message to indicate a given section of code was invoked.
     *
     *
     * @param category The perfetto category.
     * @param category The perfetto category.
     * @param eventName The event name to appear in the trace.
     * @param eventName The event name to appear in the trace.
     */
     */
    public static void instant(Category category, String eventName) {
    public static PerfettoTrackEventExtra.Builder instant(Category category, String eventName) {
        instant(category, eventName, PerfettoTrackEventExtra.builder().build());
    }

    /**
     * Writes a trace message to indicate the start of a given section of code.
     *
     * @param category The perfetto category pointer.
     * @param eventName The event name to appear in the trace.
     * @param extra The extra arguments.
     */
    public static void begin(Category category, String eventName, PerfettoTrackEventExtra extra) {
        if (!category.isEnabled()) {
        if (!category.isEnabled()) {
            return;
            return PerfettoTrackEventExtra.noOpBuilder();
        }

        native_event(PERFETTO_TE_TYPE_SLICE_BEGIN, category.getPtr(), eventName, extra.getPtr());
        extra.reset();
        }
        }


    /**
        return PerfettoTrackEventExtra.builder().init(PERFETTO_TE_TYPE_INSTANT, category)
     * Writes a trace message to indicate the start of a given section of code.
            .setEventName(eventName);
     *
     * @param category The perfetto category pointer.
     * @param eventName The event name to appear in the trace.
     * @param extraConfig Consumer for the extra arguments.
     */
    public static void begin(Category category, String eventName,
            Consumer<PerfettoTrackEventExtra.Builder> extraConfig) {
        PerfettoTrackEventExtra.Builder extra = PerfettoTrackEventExtra.builder();
        extraConfig.accept(extra);
        begin(category, eventName, extra.build());
    }
    }


    /**
    /**
     * Writes a trace message to indicate the start of a given section of code.
     * Writes a trace message to indicate the start of a given section of code.
     *
     *
     * @param category The perfetto category pointer.
     * @param category The perfetto category.
     * @param eventName The event name to appear in the trace.
     * @param eventName The event name to appear in the trace.
     */
     */
    public static void begin(Category category, String eventName) {
    public static PerfettoTrackEventExtra.Builder begin(Category category, String eventName) {
        begin(category, eventName, PerfettoTrackEventExtra.builder().build());
    }

    /**
     * Writes a trace message to indicate the end of a given section of code.
     *
     * @param category The perfetto category pointer.
     * @param extra The extra arguments.
     */
    public static void end(Category category, PerfettoTrackEventExtra extra) {
        if (!category.isEnabled()) {
        if (!category.isEnabled()) {
            return;
            return PerfettoTrackEventExtra.noOpBuilder();
        }
        }


        native_event(PERFETTO_TE_TYPE_SLICE_END, category.getPtr(), "", extra.getPtr());
        return PerfettoTrackEventExtra.builder().init(PERFETTO_TE_TYPE_SLICE_BEGIN, category)
        extra.reset();
            .setEventName(eventName);
    }
    }


    /**
    /**
     * Writes a trace message to indicate the end of a given section of code.
     * Writes a trace message to indicate the end of a given section of code.
     *
     *
     * @param category The perfetto category pointer.
     * @param category The perfetto category.
     * @param extraConfig Consumer for the extra arguments.
     */
     */
    public static void end(Category category,
    public static PerfettoTrackEventExtra.Builder end(Category category) {
            Consumer<PerfettoTrackEventExtra.Builder> extraConfig) {
        if (!category.isEnabled()) {
        PerfettoTrackEventExtra.Builder extra = PerfettoTrackEventExtra.builder();
            return PerfettoTrackEventExtra.noOpBuilder();
        extraConfig.accept(extra);
        end(category, extra.build());
        }
        }


    /**
        return PerfettoTrackEventExtra.builder().init(PERFETTO_TE_TYPE_SLICE_END, category);
     * Writes a trace message to indicate the end of a given section of code.
     *
     * @param category The perfetto category pointer.
     */
    public static void end(Category category) {
        end(category, PerfettoTrackEventExtra.builder().build());
    }
    }


    /**
    /**
     * Writes a trace message to indicate the value of a given section of code.
     * Writes a trace message to indicate the value of a given section of code.
     *
     *
     * @param category The perfetto category pointer.
     * @param category The perfetto category.
     * @param extra The extra arguments.
     * @param value The value of the counter.
     */
     */
    public static void counter(Category category, PerfettoTrackEventExtra extra) {
    public static PerfettoTrackEventExtra.Builder counter(Category category, long value) {
        if (!category.isEnabled()) {
        if (!category.isEnabled()) {
            return;
            return PerfettoTrackEventExtra.noOpBuilder();
        }
        }


        native_event(PERFETTO_TE_TYPE_COUNTER, category.getPtr(), "", extra.getPtr());
        return PerfettoTrackEventExtra.builder().init(PERFETTO_TE_TYPE_COUNTER, category)
        extra.reset();
            .setCounter(value);
    }
    }


    /**
    /**
     * Writes a trace message to indicate the value of a given section of code.
     * Writes a trace message to indicate the value of a given section of code.
     *
     *
     * @param category The perfetto category pointer.
     * @param category The perfetto category.
     * @param extraConfig Consumer for the extra arguments.
     * @param value The value of the counter.
     * @param trackName The trackName for the event.
     */
     */
    public static void counter(Category category,
    public static PerfettoTrackEventExtra.Builder counter(
            Consumer<PerfettoTrackEventExtra.Builder> extraConfig) {
            Category category, long value, String trackName) {
        PerfettoTrackEventExtra.Builder extra = PerfettoTrackEventExtra.builder();
        return counter(category, value).usingProcessCounterTrack(trackName);
        extraConfig.accept(extra);
        counter(category, extra.build());
    }
    }


    /**
    /**
     * Writes a trace message to indicate the value of a given section of code.
     * Writes a trace message to indicate the value of a given section of code.
     *
     *
     * @param category The perfetto category pointer.
     * @param category The perfetto category.
     * @param trackName The trackName for the event.
     * @param value The value of the counter.
     * @param value The value of the counter.
     */
     */
    public static void counter(Category category, String trackName, long value) {
    public static PerfettoTrackEventExtra.Builder counter(Category category, double value) {
        PerfettoTrackEventExtra extra = PerfettoTrackEventExtra.builder()
        if (!category.isEnabled()) {
                .usingCounterTrack(trackName, PerfettoTrace.getProcessTrackUuid())
            return PerfettoTrackEventExtra.noOpBuilder();
                .setCounter(value)
        }
                .build();

        counter(category, extra);
        return PerfettoTrackEventExtra.builder().init(PERFETTO_TE_TYPE_COUNTER, category)
            .setCounter(value);
    }
    }


    /**
    /**
     * Writes a trace message to indicate the value of a given section of code.
     * Writes a trace message to indicate the value of a given section of code.
     *
     *
     * @param category The perfetto category pointer.
     * @param category The perfetto category.
     * @param trackName The trackName for the event.
     * @param value The value of the counter.
     * @param value The value of the counter.
     * @param trackName The trackName for the event.
     */
     */
    public static void counter(Category category, String trackName, double value) {
    public static PerfettoTrackEventExtra.Builder counter(
        PerfettoTrackEventExtra extra = PerfettoTrackEventExtra.builder()
            Category category, double value, String trackName) {
                .usingCounterTrack(trackName, PerfettoTrace.getProcessTrackUuid())
        return counter(category, value).usingProcessCounterTrack(trackName);
                .setCounter(value)
                .build();
        counter(category, extra);
    }
    }


    /**
    /**
@@ -360,7 +278,7 @@ public final class PerfettoTrace {
     * Returns the process track uuid that can be used as a parent track uuid.
     * Returns the process track uuid that can be used as a parent track uuid.
     */
     */
    public static long getProcessTrackUuid() {
    public static long getProcessTrackUuid() {
        if (IS_FLAG_ENABLED) {
        if (!IS_FLAG_ENABLED) {
            return 0;
            return 0;
        }
        }
        return native_get_process_track_uuid();
        return native_get_process_track_uuid();
@@ -370,7 +288,7 @@ public final class PerfettoTrace {
     * Given a thread tid, returns the thread track uuid that can be used as a parent track uuid.
     * Given a thread tid, returns the thread track uuid that can be used as a parent track uuid.
     */
     */
    public static long getThreadTrackUuid(long tid) {
    public static long getThreadTrackUuid(long tid) {
        if (IS_FLAG_ENABLED) {
        if (!IS_FLAG_ENABLED) {
            return 0;
            return 0;
        }
        }
        return native_get_thread_track_uuid(tid);
        return native_get_thread_track_uuid(tid);
@@ -380,7 +298,7 @@ public final class PerfettoTrace {
     * Activates a trigger by name {@code triggerName} with expiry in {@code ttlMs}.
     * Activates a trigger by name {@code triggerName} with expiry in {@code ttlMs}.
     */
     */
    public static void activateTrigger(String triggerName, int ttlMs) {
    public static void activateTrigger(String triggerName, int ttlMs) {
        if (IS_FLAG_ENABLED) {
        if (!IS_FLAG_ENABLED) {
            return;
            return;
        }
        }
        native_activate_trigger(triggerName, ttlMs);
        native_activate_trigger(triggerName, ttlMs);
+377 −104

File changed.

Preview size limit exceeded, changes collapsed.

+12 −37
Original line number Original line Diff line number Diff line
@@ -23,6 +23,7 @@
#include <nativehelper/scoped_local_ref.h>
#include <nativehelper/scoped_local_ref.h>
#include <nativehelper/scoped_primitive_array.h>
#include <nativehelper/scoped_primitive_array.h>
#include <nativehelper/scoped_utf_chars.h>
#include <nativehelper/scoped_utf_chars.h>
#include <nativehelper/utils.h>
#include <tracing_sdk.h>
#include <tracing_sdk.h>


namespace android {
namespace android {
@@ -36,30 +37,6 @@ inline static jlong toJLong(T* ptr) {
    return static_cast<jlong>(reinterpret_cast<uintptr_t>(ptr));
    return static_cast<jlong>(reinterpret_cast<uintptr_t>(ptr));
}
}


static const char* fromJavaString(JNIEnv* env, jstring jstr) {
    if (!jstr) return "";
    ScopedUtfChars chars(env, jstr);

    if (!chars.c_str()) {
        ALOGE("Failed extracting string");
        return "";
    }

    return chars.c_str();
}

static void android_os_PerfettoTrace_event(JNIEnv* env, jclass, jint type, jlong cat_ptr,
                                           jstring name, jlong extra_ptr) {
    ScopedUtfChars name_utf(env, name);
    if (!name_utf.c_str()) {
        ALOGE("Failed extracting string");
    }

    tracing_perfetto::Category* category = toPointer<tracing_perfetto::Category>(cat_ptr);
    tracing_perfetto::trace_event(type, category->get(), name_utf.c_str(),
                                  toPointer<tracing_perfetto::Extra>(extra_ptr));
}

static jlong android_os_PerfettoTrace_get_process_track_uuid() {
static jlong android_os_PerfettoTrace_get_process_track_uuid() {
    return tracing_perfetto::get_process_track_uuid();
    return tracing_perfetto::get_process_track_uuid();
}
}
@@ -70,20 +47,18 @@ static jlong android_os_PerfettoTrace_get_thread_track_uuid(jlong tid) {


static void android_os_PerfettoTrace_activate_trigger(JNIEnv* env, jclass, jstring name,
static void android_os_PerfettoTrace_activate_trigger(JNIEnv* env, jclass, jstring name,
                                                      jint ttl_ms) {
                                                      jint ttl_ms) {
    ScopedUtfChars name_utf(env, name);
    ScopedUtfChars name_chars = GET_UTF_OR_RETURN_VOID(env, name);
    if (!name_utf.c_str()) {
    tracing_perfetto::activate_trigger(name_chars.c_str(), static_cast<uint32_t>(ttl_ms));
        ALOGE("Failed extracting string");
        return;
    }

    tracing_perfetto::activate_trigger(name_utf.c_str(), static_cast<uint32_t>(ttl_ms));
}
}


static jlong android_os_PerfettoTraceCategory_init(JNIEnv* env, jclass, jstring name, jstring tag,
static jlong android_os_PerfettoTraceCategory_init(JNIEnv* env, jclass, jstring name, jstring tag,
                                                   jstring severity) {
                                                   jstring severity) {
    return toJLong(new tracing_perfetto::Category(fromJavaString(env, name),
    ScopedUtfChars name_chars = GET_UTF_OR_RETURN(env, name);
                                                  fromJavaString(env, tag),
    ScopedUtfChars tag_chars = GET_UTF_OR_RETURN(env, tag);
                                                  fromJavaString(env, severity)));
    ScopedUtfChars severity_chars = GET_UTF_OR_RETURN(env, severity);

    return toJLong(new tracing_perfetto::Category(name_chars.c_str(), tag_chars.c_str(),
                                                  severity_chars.c_str()));
}
}


static jlong android_os_PerfettoTraceCategory_delete() {
static jlong android_os_PerfettoTraceCategory_delete() {
@@ -121,8 +96,7 @@ static const JNINativeMethod gCategoryMethods[] = {
};
};


static const JNINativeMethod gTraceMethods[] =
static const JNINativeMethod gTraceMethods[] =
        {{"native_event", "(IJLjava/lang/String;J)V", (void*)android_os_PerfettoTrace_event},
        {{"native_get_process_track_uuid", "()J",
         {"native_get_process_track_uuid", "()J",
          (void*)android_os_PerfettoTrace_get_process_track_uuid},
          (void*)android_os_PerfettoTrace_get_process_track_uuid},
         {"native_get_thread_track_uuid", "(J)J",
         {"native_get_thread_track_uuid", "(J)J",
          (void*)android_os_PerfettoTrace_get_thread_track_uuid},
          (void*)android_os_PerfettoTrace_get_thread_track_uuid},
@@ -132,10 +106,11 @@ static const JNINativeMethod gTraceMethods[] =
int register_android_os_PerfettoTrace(JNIEnv* env) {
int register_android_os_PerfettoTrace(JNIEnv* env) {
    int res = jniRegisterNativeMethods(env, "android/os/PerfettoTrace", gTraceMethods,
    int res = jniRegisterNativeMethods(env, "android/os/PerfettoTrace", gTraceMethods,
                                       NELEM(gTraceMethods));
                                       NELEM(gTraceMethods));
    LOG_ALWAYS_FATAL_IF(res < 0, "Unable to register perfetto native methods.");


    res = jniRegisterNativeMethods(env, "android/os/PerfettoTrace$Category", gCategoryMethods,
    res = jniRegisterNativeMethods(env, "android/os/PerfettoTrace$Category", gCategoryMethods,
                                   NELEM(gCategoryMethods));
                                   NELEM(gCategoryMethods));
    LOG_ALWAYS_FATAL_IF(res < 0, "Unable to register native methods.");
    LOG_ALWAYS_FATAL_IF(res < 0, "Unable to register category native methods.");


    return 0;
    return 0;
}
}
+32 −22
Original line number Original line Diff line number Diff line
@@ -20,6 +20,7 @@
#include <log/log.h>
#include <log/log.h>
#include <nativehelper/JNIHelp.h>
#include <nativehelper/JNIHelp.h>
#include <nativehelper/scoped_utf_chars.h>
#include <nativehelper/scoped_utf_chars.h>
#include <nativehelper/utils.h>
#include <tracing_sdk.h>
#include <tracing_sdk.h>


static constexpr ssize_t kMaxStrLen = 4096;
static constexpr ssize_t kMaxStrLen = 4096;
@@ -34,32 +35,24 @@ inline static jlong toJLong(T* ptr) {
    return static_cast<jlong>(reinterpret_cast<uintptr_t>(ptr));
    return static_cast<jlong>(reinterpret_cast<uintptr_t>(ptr));
}
}


static const char* fromJavaString(JNIEnv* env, jstring jstr) {
    if (!jstr) return "";
    ScopedUtfChars chars(env, jstr);

    if (!chars.c_str()) {
        ALOGE("Failed extracting string");
        return "";
    }

    return chars.c_str();
}

static jlong android_os_PerfettoTrackEventExtraArgInt64_init(JNIEnv* env, jclass, jstring name) {
static jlong android_os_PerfettoTrackEventExtraArgInt64_init(JNIEnv* env, jclass, jstring name) {
    return toJLong(new tracing_perfetto::DebugArg<int64_t>(fromJavaString(env, name)));
    ScopedUtfChars name_chars = GET_UTF_OR_RETURN(env, name);
    return toJLong(new tracing_perfetto::DebugArg<int64_t>(name_chars.c_str()));
}
}


static jlong android_os_PerfettoTrackEventExtraArgBool_init(JNIEnv* env, jclass, jstring name) {
static jlong android_os_PerfettoTrackEventExtraArgBool_init(JNIEnv* env, jclass, jstring name) {
    return toJLong(new tracing_perfetto::DebugArg<bool>(fromJavaString(env, name)));
    ScopedUtfChars name_chars = GET_UTF_OR_RETURN(env, name);
    return toJLong(new tracing_perfetto::DebugArg<bool>(name_chars.c_str()));
}
}


static jlong android_os_PerfettoTrackEventExtraArgDouble_init(JNIEnv* env, jclass, jstring name) {
static jlong android_os_PerfettoTrackEventExtraArgDouble_init(JNIEnv* env, jclass, jstring name) {
    return toJLong(new tracing_perfetto::DebugArg<double>(fromJavaString(env, name)));
    ScopedUtfChars name_chars = GET_UTF_OR_RETURN(env, name);
    return toJLong(new tracing_perfetto::DebugArg<double>(name_chars.c_str()));
}
}


static jlong android_os_PerfettoTrackEventExtraArgString_init(JNIEnv* env, jclass, jstring name) {
static jlong android_os_PerfettoTrackEventExtraArgString_init(JNIEnv* env, jclass, jstring name) {
    return toJLong(new tracing_perfetto::DebugArg<const char*>(fromJavaString(env, name)));
    ScopedUtfChars name_chars = GET_UTF_OR_RETURN(env, name);
    return toJLong(new tracing_perfetto::DebugArg<const char*>(name_chars.c_str()));
}
}


static jlong android_os_PerfettoTrackEventExtraArgInt64_delete() {
static jlong android_os_PerfettoTrackEventExtraArgInt64_delete() {
@@ -116,9 +109,11 @@ static void android_os_PerfettoTrackEventExtraArgDouble_set_value(jlong ptr, jdo


static void android_os_PerfettoTrackEventExtraArgString_set_value(JNIEnv* env, jclass, jlong ptr,
static void android_os_PerfettoTrackEventExtraArgString_set_value(JNIEnv* env, jclass, jlong ptr,
                                                                  jstring val) {
                                                                  jstring val) {
    ScopedUtfChars val_chars = GET_UTF_OR_RETURN_VOID(env, val);

    tracing_perfetto::DebugArg<const char*>* arg =
    tracing_perfetto::DebugArg<const char*>* arg =
            toPointer<tracing_perfetto::DebugArg<const char*>>(ptr);
            toPointer<tracing_perfetto::DebugArg<const char*>>(ptr);
    arg->set_value(strdup(fromJavaString(env, val)));
    arg->set_value(strdup(val_chars.c_str()));
}
}


static jlong android_os_PerfettoTrackEventExtraFieldInt64_init() {
static jlong android_os_PerfettoTrackEventExtraFieldInt64_init() {
@@ -191,9 +186,11 @@ static void android_os_PerfettoTrackEventExtraFieldDouble_set_value(jlong ptr, j


static void android_os_PerfettoTrackEventExtraFieldString_set_value(JNIEnv* env, jclass, jlong ptr,
static void android_os_PerfettoTrackEventExtraFieldString_set_value(JNIEnv* env, jclass, jlong ptr,
                                                                    jlong id, jstring val) {
                                                                    jlong id, jstring val) {
    ScopedUtfChars val_chars = GET_UTF_OR_RETURN_VOID(env, val);

    tracing_perfetto::ProtoField<const char*>* field =
    tracing_perfetto::ProtoField<const char*>* field =
            toPointer<tracing_perfetto::ProtoField<const char*>>(ptr);
            toPointer<tracing_perfetto::ProtoField<const char*>>(ptr);
    field->set_value(id, strdup(fromJavaString(env, val)));
    field->set_value(id, strdup(val_chars.c_str()));
}
}


static void android_os_PerfettoTrackEventExtraFieldNested_add_field(jlong field_ptr,
static void android_os_PerfettoTrackEventExtraFieldNested_add_field(jlong field_ptr,
@@ -234,7 +231,8 @@ static jlong android_os_PerfettoTrackEventExtraFlow_get_extra_ptr(jlong ptr) {


static jlong android_os_PerfettoTrackEventExtraNamedTrack_init(JNIEnv* env, jclass, jlong id,
static jlong android_os_PerfettoTrackEventExtraNamedTrack_init(JNIEnv* env, jclass, jlong id,
                                                               jstring name, jlong parent_uuid) {
                                                               jstring name, jlong parent_uuid) {
    return toJLong(new tracing_perfetto::NamedTrack(id, parent_uuid, fromJavaString(env, name)));
    ScopedUtfChars name_chars = GET_UTF_OR_RETURN(env, name);
    return toJLong(new tracing_perfetto::NamedTrack(id, parent_uuid, name_chars.c_str()));
}
}


static jlong android_os_PerfettoTrackEventExtraNamedTrack_delete() {
static jlong android_os_PerfettoTrackEventExtraNamedTrack_delete() {
@@ -248,8 +246,9 @@ static jlong android_os_PerfettoTrackEventExtraNamedTrack_get_extra_ptr(jlong pt


static jlong android_os_PerfettoTrackEventExtraCounterTrack_init(JNIEnv* env, jclass, jstring name,
static jlong android_os_PerfettoTrackEventExtraCounterTrack_init(JNIEnv* env, jclass, jstring name,
                                                                 jlong parent_uuid) {
                                                                 jlong parent_uuid) {
    return toJLong(
    ScopedUtfChars name_chars = GET_UTF_OR_RETURN(env, name);
            new tracing_perfetto::RegisteredTrack(1, parent_uuid, fromJavaString(env, name), true));

    return toJLong(new tracing_perfetto::RegisteredTrack(1, parent_uuid, name_chars.c_str(), true));
}
}


static jlong android_os_PerfettoTrackEventExtraCounterTrack_delete() {
static jlong android_os_PerfettoTrackEventExtraCounterTrack_delete() {
@@ -317,6 +316,15 @@ static void android_os_PerfettoTrackEventExtra_clear_args(jlong ptr) {
    extra->clear_extras();
    extra->clear_extras();
}
}


static void android_os_PerfettoTrackEventExtra_emit(JNIEnv* env, jclass, jint type, jlong cat_ptr,
                                                    jstring name, jlong extra_ptr) {
    ScopedUtfChars name_chars = GET_UTF_OR_RETURN_VOID(env, name);

    tracing_perfetto::Category* category = toPointer<tracing_perfetto::Category>(cat_ptr);
    tracing_perfetto::trace_event(type, category->get(), name_chars.c_str(),
                                  toPointer<tracing_perfetto::Extra>(extra_ptr));
}

static jlong android_os_PerfettoTrackEventExtraProto_init() {
static jlong android_os_PerfettoTrackEventExtraProto_init() {
    return toJLong(new tracing_perfetto::Proto());
    return toJLong(new tracing_perfetto::Proto());
}
}
@@ -344,7 +352,9 @@ static const JNINativeMethod gExtraMethods[] =
        {{"native_init", "()J", (void*)android_os_PerfettoTrackEventExtra_init},
        {{"native_init", "()J", (void*)android_os_PerfettoTrackEventExtra_init},
         {"native_delete", "()J", (void*)android_os_PerfettoTrackEventExtra_delete},
         {"native_delete", "()J", (void*)android_os_PerfettoTrackEventExtra_delete},
         {"native_add_arg", "(JJ)V", (void*)android_os_PerfettoTrackEventExtra_add_arg},
         {"native_add_arg", "(JJ)V", (void*)android_os_PerfettoTrackEventExtra_add_arg},
         {"native_clear_args", "(J)V", (void*)android_os_PerfettoTrackEventExtra_clear_args}};
         {"native_clear_args", "(J)V", (void*)android_os_PerfettoTrackEventExtra_clear_args},
         {"native_emit", "(IJLjava/lang/String;J)V",
          (void*)android_os_PerfettoTrackEventExtra_emit}};


static const JNINativeMethod gProtoMethods[] =
static const JNINativeMethod gProtoMethods[] =
        {{"native_init", "()J", (void*)android_os_PerfettoTrackEventExtraProto_init},
        {{"native_init", "()J", (void*)android_os_PerfettoTrackEventExtraProto_init},
+162 −64

File changed.

Preview size limit exceeded, changes collapsed.