| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "sky/shell/android/tracing_controller.h" | 5 #include "sky/shell/android/tracing_controller.h" |
| 6 | 6 |
| 7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/trace_event/trace_config.h" |
| 11 #include "base/trace_event/trace_event.h" | 12 #include "base/trace_event/trace_event.h" |
| 12 #include "jni/TracingController_jni.h" | 13 #include "jni/TracingController_jni.h" |
| 13 | 14 |
| 14 namespace sky { | 15 namespace sky { |
| 15 namespace shell { | 16 namespace shell { |
| 16 namespace { | 17 namespace { |
| 17 | 18 |
| 18 const char kStart[] = "{\"traceEvents\":["; | 19 const char kStart[] = "{\"traceEvents\":["; |
| 19 const char kEnd[] = "]}"; | 20 const char kEnd[] = "]}"; |
| 20 | 21 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 38 LOG(INFO) << "Trace complete"; | 39 LOG(INFO) << "Trace complete"; |
| 39 } | 40 } |
| 40 } | 41 } |
| 41 | 42 |
| 42 } // namespace | 43 } // namespace |
| 43 | 44 |
| 44 static void StartTracing(JNIEnv* env, jclass clazz) { | 45 static void StartTracing(JNIEnv* env, jclass clazz) { |
| 45 LOG(INFO) << "Starting trace"; | 46 LOG(INFO) << "Starting trace"; |
| 46 | 47 |
| 47 base::trace_event::TraceLog::GetInstance()->SetEnabled( | 48 base::trace_event::TraceLog::GetInstance()->SetEnabled( |
| 48 base::trace_event::CategoryFilter("*"), | 49 base::trace_event::TraceConfig("*", base::trace_event::RECORD_UNTIL_FULL), |
| 49 base::trace_event::TraceLog::RECORDING_MODE, | 50 base::trace_event::TraceLog::RECORDING_MODE); |
| 50 base::trace_event::TraceOptions(base::trace_event::RECORD_UNTIL_FULL)); | |
| 51 } | 51 } |
| 52 | 52 |
| 53 static void StopTracing(JNIEnv* env, jclass clazz, jstring path) { | 53 static void StopTracing(JNIEnv* env, jclass clazz, jstring path) { |
| 54 base::trace_event::TraceLog::GetInstance()->SetDisabled(); | 54 base::trace_event::TraceLog::GetInstance()->SetDisabled(); |
| 55 | 55 |
| 56 base::FilePath file_path(base::android::ConvertJavaStringToUTF8(env, path)); | 56 base::FilePath file_path(base::android::ConvertJavaStringToUTF8(env, path)); |
| 57 g_file = base::OpenFile(file_path, "w"); | 57 g_file = base::OpenFile(file_path, "w"); |
| 58 CHECK(g_file) << "Failed to open file " << file_path.LossyDisplayName(); | 58 CHECK(g_file) << "Failed to open file " << file_path.LossyDisplayName(); |
| 59 | 59 |
| 60 LOG(INFO) << "Saving trace to " << file_path.LossyDisplayName(); | 60 LOG(INFO) << "Saving trace to " << file_path.LossyDisplayName(); |
| 61 Write(kStart); | 61 Write(kStart); |
| 62 base::trace_event::TraceLog::GetInstance()->Flush(base::Bind(&HandleChunk)); | 62 base::trace_event::TraceLog::GetInstance()->Flush(base::Bind(&HandleChunk)); |
| 63 } | 63 } |
| 64 | 64 |
| 65 bool RegisterTracingController(JNIEnv* env) { | 65 bool RegisterTracingController(JNIEnv* env) { |
| 66 return RegisterNativesImpl(env); | 66 return RegisterNativesImpl(env); |
| 67 } | 67 } |
| 68 | 68 |
| 69 } // namespace shell | 69 } // namespace shell |
| 70 } // namespace sky | 70 } // namespace sky |
| OLD | NEW |