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

Side by Side Diff: content/public/android/java/src/org/chromium/content/common/TraceEvent.java

Issue 15927042: Small improvements to Looper Idle tracing (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 package org.chromium.content.common; 5 package org.chromium.content.common;
6 6
7 import android.os.Build; 7 import android.os.Build;
8 import android.os.Looper; 8 import android.os.Looper;
9 import android.os.MessageQueue; 9 import android.os.MessageQueue;
10 import android.os.SystemClock; 10 import android.os.SystemClock;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 private int mNumTasksSeen = 0; 68 private int mNumTasksSeen = 0;
69 private int mNumIdlesSeen = 0; 69 private int mNumIdlesSeen = 0;
70 private int mNumTasksSinceLastIdle = 0; 70 private int mNumTasksSinceLastIdle = 0;
71 71
72 // State 72 // State
73 private boolean mIdleMonitorAttached = false; 73 private boolean mIdleMonitorAttached = false;
74 74
75 @Override 75 @Override
76 public void println(final String line) { 76 public void println(final String line) {
77 if (line.startsWith(">")) { 77 if (line.startsWith(">")) {
78 TraceEvent.begin(DISPATCH_EVENT_NAME, line);
79 begin(line); 78 begin(line);
80 } else { 79 } else {
81 assert line.startsWith("<"); 80 assert line.startsWith("<");
82 TraceEvent.end(DISPATCH_EVENT_NAME);
83 end(line); 81 end(line);
84 } 82 }
85 } 83 }
86 84
87 // Called from within the begin/end methods only. 85 // Called from within the begin/end methods only.
88 // This method can only execute on the looper thread, because that is 86 // This method can only execute on the looper thread, because that is
89 // the only thread that is permitted to call Looper.myqueue(). 87 // the only thread that is permitted to call Looper.myqueue().
90 private final void syncIdleMonitoring() { 88 private final void syncIdleMonitoring() {
91 if (sEnabled && !mIdleMonitorAttached) { 89 if (sEnabled && !mIdleMonitorAttached) {
92 // approximate start time for computational purposes 90 // approximate start time for computational purposes
93 mLastIdleStartedAt = SystemClock.elapsedRealtime(); 91 mLastIdleStartedAt = SystemClock.elapsedRealtime();
94 Looper.myQueue().addIdleHandler( 92 Looper.myQueue().addIdleHandler(
95 LooperMonitor.getInstance()); 93 LooperMonitor.getInstance());
96 mIdleMonitorAttached = true; 94 mIdleMonitorAttached = true;
97 Log.v(TAG, "attached idle handler"); 95 Log.v(TAG, "attached idle handler");
98 } else if (mIdleMonitorAttached && !sEnabled) { 96 } else if (mIdleMonitorAttached && !sEnabled) {
99 Looper.myQueue().removeIdleHandler( 97 Looper.myQueue().removeIdleHandler(
100 LooperMonitor.getInstance()); 98 LooperMonitor.getInstance());
101 mIdleMonitorAttached = false; 99 mIdleMonitorAttached = false;
102 Log.v(TAG, "detached idle handler"); 100 Log.v(TAG, "detached idle handler");
103 } 101 }
104 } 102 }
105 103
106 private final void begin(final String line) { 104 private final void begin(final String line) {
105 // Close-out any prior 'idle' period before starting new task.
107 if (mNumTasksSinceLastIdle == 0) { 106 if (mNumTasksSinceLastIdle == 0) {
108 TraceEvent.end(IDLE_EVENT_NAME); 107 TraceEvent.end(IDLE_EVENT_NAME);
109 } 108 }
109 TraceEvent.begin(DISPATCH_EVENT_NAME, line);
110 mLastWorkStartedAt = SystemClock.elapsedRealtime(); 110 mLastWorkStartedAt = SystemClock.elapsedRealtime();
111 syncIdleMonitoring(); 111 syncIdleMonitoring();
112 } 112 }
113 113
114 private final void end(final String line) { 114 private final void end(final String line) {
115 final long elapsed = SystemClock.elapsedRealtime() 115 final long elapsed = SystemClock.elapsedRealtime()
116 - mLastWorkStartedAt; 116 - mLastWorkStartedAt;
117 if (elapsed > MIN_INTERESTING_DURATION_MILLIS) { 117 if (elapsed > MIN_INTERESTING_DURATION_MILLIS) {
118 Log.w(TAG, "observed a task that took " 118 traceAndLog(Log.WARN, "observed a task that took "
119 + elapsed + "ms: " + line); 119 + elapsed + "ms: " + line);
120 } 120 }
121 TraceEvent.end(DISPATCH_EVENT_NAME);
121 syncIdleMonitoring(); 122 syncIdleMonitoring();
122 mNumTasksSeen++; 123 mNumTasksSeen++;
123 mNumTasksSinceLastIdle++; 124 mNumTasksSinceLastIdle++;
124 } 125 }
125 126
127 private static void traceAndLog(int level, String message) {
128 TraceEvent.instant("TraceEvent.LooperMonitor:IdleStats", message);
129 Log.println(level, TAG, message);
130 }
131
126 @Override 132 @Override
127 public final boolean queueIdle() { 133 public final boolean queueIdle() {
128 final long now = SystemClock.elapsedRealtime(); 134 final long now = SystemClock.elapsedRealtime();
129 if (mLastIdleStartedAt == 0) mLastIdleStartedAt = now; 135 if (mLastIdleStartedAt == 0) mLastIdleStartedAt = now;
130 final long elapsed = now - mLastIdleStartedAt; 136 final long elapsed = now - mLastIdleStartedAt;
131 mNumIdlesSeen++; 137 mNumIdlesSeen++;
138 TraceEvent.begin(IDLE_EVENT_NAME, "Tasks since last idle " + mNumTas ksSinceLastIdle);
Andrew Hayden (chromium.org) 2013/06/08 08:32:07 nit: mNumTasksSinceLastIdle + " tasks since last i
132 if (elapsed > MIN_INTERESTING_BURST_DURATION_MILLIS) { 139 if (elapsed > MIN_INTERESTING_BURST_DURATION_MILLIS) {
133 // Dump stats 140 // Dump stats
134 String statsString = mNumTasksSeen + " tasks and " 141 String statsString = mNumTasksSeen + " tasks and "
135 + mNumIdlesSeen + " idles processed so far, " 142 + mNumIdlesSeen + " idles processed so far, "
136 + mNumTasksSinceLastIdle + " tasks bursted and " 143 + mNumTasksSinceLastIdle + " tasks bursted and "
137 + elapsed + "ms elapsed since last idle"; 144 + elapsed + "ms elapsed since last idle";
138 Log.d(TAG, statsString); 145 traceAndLog(Log.DEBUG, statsString);
139 instant("TraceEvent.LooperMonitor:IdleStats", statsString);
140 TraceEvent.begin(IDLE_EVENT_NAME, statsString);
141 } else {
142 TraceEvent.begin(IDLE_EVENT_NAME);
143 } 146 }
144 mLastIdleStartedAt = now; 147 mLastIdleStartedAt = now;
145 mNumTasksSinceLastIdle = 0; 148 mNumTasksSinceLastIdle = 0;
146 return true; // stay installed 149 return true; // stay installed
147 } 150 }
148 151
149 // Holder for monitor avoids unnecessary construction on non-debug runs 152 // Holder for monitor avoids unnecessary construction on non-debug runs
150 private final static class Holder { 153 private final static class Holder {
151 private final static LooperMonitor sInstance = new LooperMonitor(); 154 private final static LooperMonitor sInstance = new LooperMonitor();
152 } 155 }
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 394
392 private static native boolean nativeTraceEnabled(); 395 private static native boolean nativeTraceEnabled();
393 private static native void nativeStartATrace(); 396 private static native void nativeStartATrace();
394 private static native void nativeStopATrace(); 397 private static native void nativeStopATrace();
395 private static native void nativeInstant(String name, String arg); 398 private static native void nativeInstant(String name, String arg);
396 private static native void nativeBegin(String name, String arg); 399 private static native void nativeBegin(String name, String arg);
397 private static native void nativeEnd(String name, String arg); 400 private static native void nativeEnd(String name, String arg);
398 private static native void nativeStartAsync(String name, long id, String arg ); 401 private static native void nativeStartAsync(String name, long id, String arg );
399 private static native void nativeFinishAsync(String name, long id, String ar g); 402 private static native void nativeFinishAsync(String name, long id, String ar g);
400 } 403 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698