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

Unified Diff: sky/shell/org/domokit/sky/shell/TracingController.java

Issue 1027903002: Enable tracing in SkyShell (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sky/shell/org/domokit/sky/shell/SkyActivity.java ('k') | sky/shell/tracing_controller.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/shell/org/domokit/sky/shell/TracingController.java
diff --git a/sky/shell/org/domokit/sky/shell/TracingController.java b/sky/shell/org/domokit/sky/shell/TracingController.java
new file mode 100644
index 0000000000000000000000000000000000000000..716e0c007d833cdd46b65c79537436af446a9d53
--- /dev/null
+++ b/sky/shell/org/domokit/sky/shell/TracingController.java
@@ -0,0 +1,75 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.domokit.sky.shell;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.os.Environment;
+import android.util.Log;
+
+import java.io.File;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Locale;
+import java.util.TimeZone;
+
+import org.chromium.base.JNINamespace;
+
+/**
+ * A controller for the tracing system.
+ */
+@JNINamespace("sky::shell")
+class TracingController {
+ private static final String TAG = "TracingController";
+ private static final String TRACING_START = ".TRACING_START";
+ private static final String TRACING_STOP = ".TRACING_STOP";
+
+ private final Context mContext;
+ private final TracingBroadcastReceiver mBroadcastReceiver;
+ private final TracingIntentFilter mIntentFilter;
+
+ public TracingController(Context context) {
+ mContext = context;
+ mBroadcastReceiver = new TracingBroadcastReceiver();
+ mIntentFilter = new TracingIntentFilter(context);
+
+ mContext.registerReceiver(mBroadcastReceiver, mIntentFilter);
+ }
+
+ private String generateTracingFilePath() {
+ SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd-HHmmss", Locale.US);
+ formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
+ File dir = mContext.getCacheDir();
+ String date = formatter.format(new Date());
+ File file = new File(dir, "sky-trace-" + date + ".json");
+ return file.getPath();
+ }
+
+ class TracingIntentFilter extends IntentFilter {
+ TracingIntentFilter(Context context) {
+ Log.e(TAG, context.getPackageName() + TRACING_START);
+ addAction(context.getPackageName() + TRACING_START);
+ addAction(context.getPackageName() + TRACING_STOP);
+ }
+ }
+
+ class TracingBroadcastReceiver extends BroadcastReceiver {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ if (intent.getAction().endsWith(TRACING_START)) {
+ nativeStartTracing();
+ } else if (intent.getAction().endsWith(TRACING_STOP)) {
+ nativeStopTracing(generateTracingFilePath());
+ } else {
+ Log.e(TAG, "Unexpected intent: " + intent);
+ }
+ }
+ }
+
+ private static native void nativeStartTracing();
+ private static native void nativeStopTracing(String path);
+}
« no previous file with comments | « sky/shell/org/domokit/sky/shell/SkyActivity.java ('k') | sky/shell/tracing_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698