Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(947)

Side by Side Diff: content/common/android/trace_event_binding.cc

Issue 11090082: Move PerfTest TraceEvent to async (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix build break Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/common/android/trace_event_binding.h" 5 #include "content/common/android/trace_event_binding.h"
6 6
7 #include <jni.h> 7 #include <jni.h>
8 8
9 #include <set> 9 #include <set>
10 10
11 #include "base/debug/trace_event.h" 11 #include "base/debug/trace_event.h"
12 #include "base/lazy_instance.h" 12 #include "base/lazy_instance.h"
13 #include "jni/TraceEvent_jni.h" 13 #include "jni/TraceEvent_jni.h"
14 14
15 namespace { 15 namespace {
16 16
17 const char kJavaCategory[] = "Java"; 17 const char kJavaCategory[] = "Java";
18 18
19 // Boilerplate for safely converting Java data to TRACE_EVENT data. 19 // Boilerplate for safely converting Java data to TRACE_EVENT data.
20 class TraceEventDataConverter { 20 class TraceEventDataConverter {
21 public: 21 public:
22 TraceEventDataConverter(JNIEnv* env, 22 TraceEventDataConverter(JNIEnv* env,
23 jstring jname, 23 jstring jname,
24 jstring jarg) 24 jstring jarg)
25 : env_(env), 25 : env_(env),
26 jname_(jname), 26 jname_(jname),
27 jarg_(jarg), 27 jarg_(jarg),
28 name_(env->GetStringUTFChars(jname, NULL)), 28 name_(env->GetStringUTFChars(jname, NULL)),
29 arg_(jarg ? env->GetStringUTFChars(jarg, NULL) : NULL) { 29 arg_(jarg ? env->GetStringUTFChars(jarg, NULL) : NULL) {
30 } 30 }
31 ~TraceEventDataConverter() { 31 virtual ~TraceEventDataConverter() {
32 env_->ReleaseStringUTFChars(jname_, name_); 32 env_->ReleaseStringUTFChars(jname_, name_);
33 if (jarg_) 33 if (jarg_)
34 env_->ReleaseStringUTFChars(jarg_, arg_); 34 env_->ReleaseStringUTFChars(jarg_, arg_);
35 } 35 }
36 36
37 // Return saves values to pass to TRACE_EVENT macros. 37 // Return saves values to pass to TRACE_EVENT macros.
38 const char* name() { return name_; } 38 const char* name() { return name_; }
39 const char* arg_name() { return arg_ ? "arg" : NULL; } 39 const char* arg_name() { return arg_ ? "arg" : NULL; }
40 const char* arg() { return arg_; } 40 const char* arg() { return arg_; }
41 41
42 protected:
43 JNIEnv* env_;
44
42 private: 45 private:
43 JNIEnv* env_;
44 jstring jname_; 46 jstring jname_;
45 jstring jarg_; 47 jstring jarg_;
46 const char* name_; 48 const char* name_;
47 const char* arg_; 49 const char* arg_;
48 50
49 DISALLOW_COPY_AND_ASSIGN(TraceEventDataConverter); 51 DISALLOW_COPY_AND_ASSIGN(TraceEventDataConverter);
50 }; 52 };
51 53
54 class AsyncTraceEventDataConverter : public TraceEventDataConverter {
55 public:
56 AsyncTraceEventDataConverter(JNIEnv* env,
57 jstring jname,
58 jlong jid,
59 jstring jarg)
60 : TraceEventDataConverter(env, jname, jarg),
61 id_(jid) {
62 }
63
64 virtual ~AsyncTraceEventDataConverter() {
65 }
66
67 const long long id() { return id_; }
68
69 private:
70 long long id_;
71 };
72
52 } // namespace 73 } // namespace
53 74
54 static jboolean TraceEnabled(JNIEnv* env, jclass clazz) { 75 static jboolean TraceEnabled(JNIEnv* env, jclass clazz) {
55 return base::debug::TraceLog::GetInstance()->IsEnabled(); 76 return base::debug::TraceLog::GetInstance()->IsEnabled();
56 } 77 }
57 78
58 static void Instant(JNIEnv* env, jclass clazz, 79 static void Instant(JNIEnv* env, jclass clazz,
59 jstring jname, jstring jarg) { 80 jstring jname, jstring jarg) {
60 TraceEventDataConverter converter(env, jname, jarg); 81 TraceEventDataConverter converter(env, jname, jarg);
61 if (converter.arg()) { 82 if (converter.arg()) {
(...skipping 19 matching lines...) Expand all
81 jstring jname, jstring jarg) { 102 jstring jname, jstring jarg) {
82 TraceEventDataConverter converter(env, jname, jarg); 103 TraceEventDataConverter converter(env, jname, jarg);
83 if (converter.arg()) { 104 if (converter.arg()) {
84 TRACE_EVENT_COPY_END1(kJavaCategory, converter.name(), 105 TRACE_EVENT_COPY_END1(kJavaCategory, converter.name(),
85 converter.arg_name(), converter.arg()); 106 converter.arg_name(), converter.arg());
86 } else { 107 } else {
87 TRACE_EVENT_COPY_END0(kJavaCategory, converter.name()); 108 TRACE_EVENT_COPY_END0(kJavaCategory, converter.name());
88 } 109 }
89 } 110 }
90 111
112 static void StartAsync(JNIEnv* env, jclass clazz,
113 jstring jname, jlong jid, jstring jarg) {
114 AsyncTraceEventDataConverter converter(env, jname, jid, jarg);
115 if (converter.arg()) {
116 TRACE_EVENT_COPY_ASYNC_BEGIN1(kJavaCategory,
117 converter.name(),
118 converter.id(),
119 converter.arg_name(),
120 converter.arg());
121 } else {
122 TRACE_EVENT_COPY_ASYNC_BEGIN0(kJavaCategory,
123 converter.name(),
124 converter.id());
125 }
126 }
127
128 static void FinishAsync(JNIEnv* env, jclass clazz,
129 jstring jname, jlong jid, jstring jarg) {
130 AsyncTraceEventDataConverter converter(env, jname, jid, jarg);
131 if (converter.arg()) {
132 TRACE_EVENT_COPY_ASYNC_END1(kJavaCategory,
133 converter.name(),
134 converter.id(),
135 converter.arg_name(),
136 converter.arg());
137 } else {
138 TRACE_EVENT_COPY_ASYNC_END0(kJavaCategory,
139 converter.name(),
140 converter.id());
141 }
142 }
143
91 bool RegisterTraceEvent(JNIEnv* env) { 144 bool RegisterTraceEvent(JNIEnv* env) {
92 return RegisterNativesImpl(env); 145 return RegisterNativesImpl(env);
93 } 146 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698