blob: d99b6fe49d0699dfae413f92cc8fe15aa662452a [file] [log] [blame]
Jamie Gennis6eea6fb2012-12-07 14:03:07 -08001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <errno.h>
18#include <fcntl.h>
19#include <getopt.h>
Mark Salyzyn92dc3fc2014-03-12 13:12:44 -070020#include <inttypes.h>
Jamie Gennis6eea6fb2012-12-07 14:03:07 -080021#include <signal.h>
22#include <stdarg.h>
23#include <stdbool.h>
24#include <stdio.h>
25#include <stdlib.h>
Elliott Hughes3da5d232015-01-25 08:35:20 -080026#include <string.h>
Jamie Gennis6eea6fb2012-12-07 14:03:07 -080027#include <sys/sendfile.h>
28#include <time.h>
Martijn Coenend9535872015-11-26 10:00:55 +010029#include <unistd.h>
Jamie Gennis6eea6fb2012-12-07 14:03:07 -080030#include <zlib.h>
31
32#include <binder/IBinder.h>
33#include <binder/IServiceManager.h>
34#include <binder/Parcel.h>
35
36#include <cutils/properties.h>
37
38#include <utils/String8.h>
John Reck469a1942015-03-26 15:31:35 -070039#include <utils/Timers.h>
Yasuhiro Matsuda46c51fb2015-06-29 19:20:39 +090040#include <utils/Tokenizer.h>
Jamie Gennis6eea6fb2012-12-07 14:03:07 -080041#include <utils/Trace.h>
Stephane Gasparinid8419c22016-03-02 13:45:15 +010042#include <android-base/file.h>
Jamie Gennis6eea6fb2012-12-07 14:03:07 -080043
44using namespace android;
45
46#define NELEM(x) ((int) (sizeof(x) / sizeof((x)[0])))
47
Mohamad Ayyash26dbcbe2014-04-08 15:24:11 -070048enum { MAX_SYS_FILES = 10 };
Jamie Gennis6eea6fb2012-12-07 14:03:07 -080049
50const char* k_traceTagsProperty = "debug.atrace.tags.enableflags";
Jamie Gennisf7f29c82013-03-27 15:50:58 -070051const char* k_traceAppCmdlineProperty = "debug.atrace.app_cmdlines";
Jamie Gennis6eea6fb2012-12-07 14:03:07 -080052
53typedef enum { OPT, REQ } requiredness ;
54
55struct TracingCategory {
56 // The name identifying the category.
57 const char* name;
58
59 // A longer description of the category.
60 const char* longname;
61
62 // The userland tracing tags that the category enables.
63 uint64_t tags;
64
65 // The fname==NULL terminated list of /sys/ files that the category
66 // enables.
67 struct {
68 // Whether the file must be writable in order to enable the tracing
69 // category.
70 requiredness required;
71
72 // The path to the enable file.
73 const char* path;
74 } sysfiles[MAX_SYS_FILES];
75};
76
77/* Tracing categories */
78static const TracingCategory k_categories[] = {
Jamie Gennisb2a89e32013-03-11 19:37:53 -070079 { "gfx", "Graphics", ATRACE_TAG_GRAPHICS, { } },
80 { "input", "Input", ATRACE_TAG_INPUT, { } },
81 { "view", "View System", ATRACE_TAG_VIEW, { } },
82 { "webview", "WebView", ATRACE_TAG_WEBVIEW, { } },
83 { "wm", "Window Manager", ATRACE_TAG_WINDOW_MANAGER, { } },
84 { "am", "Activity Manager", ATRACE_TAG_ACTIVITY_MANAGER, { } },
Patrick Auchter70ec2942014-09-30 15:38:30 -050085 { "sm", "Sync Manager", ATRACE_TAG_SYNC_MANAGER, { } },
Jamie Gennisb2a89e32013-03-11 19:37:53 -070086 { "audio", "Audio", ATRACE_TAG_AUDIO, { } },
87 { "video", "Video", ATRACE_TAG_VIDEO, { } },
88 { "camera", "Camera", ATRACE_TAG_CAMERA, { } },
89 { "hal", "Hardware Modules", ATRACE_TAG_HAL, { } },
Jeff Brown3200b0b2014-08-14 19:24:47 -070090 { "app", "Application", ATRACE_TAG_APP, { } },
Dianne Hackborn9380d782013-04-12 14:52:35 -070091 { "res", "Resource Loading", ATRACE_TAG_RESOURCES, { } },
Jamie Genniseff2e8d2013-05-07 15:20:39 -070092 { "dalvik", "Dalvik VM", ATRACE_TAG_DALVIK, { } },
Tim Murrayf0f28412013-05-23 14:39:42 -070093 { "rs", "RenderScript", ATRACE_TAG_RS, { } },
Brigid Smith750aa972014-05-28 14:23:24 -070094 { "bionic", "Bionic C Library", ATRACE_TAG_BIONIC, { } },
Jeff Brown3200b0b2014-08-14 19:24:47 -070095 { "power", "Power Management", ATRACE_TAG_POWER, { } },
Todd Kennedy01e111b2015-07-31 14:36:20 -070096 { "pm", "Package Manager", ATRACE_TAG_PACKAGE_MANAGER, { } },
Yasuhiro Matsuda7cc49772015-07-01 01:46:25 +090097 { "ss", "System Server", ATRACE_TAG_SYSTEM_SERVER, { } },
Greg Hackmannbbd7d992014-12-01 14:43:34 -080098 { "database", "Database", ATRACE_TAG_DATABASE, { } },
Jamie Gennisb2a89e32013-03-11 19:37:53 -070099 { "sched", "CPU Scheduling", 0, {
100 { REQ, "/sys/kernel/debug/tracing/events/sched/sched_switch/enable" },
101 { REQ, "/sys/kernel/debug/tracing/events/sched/sched_wakeup/enable" },
Riley Andrews5672bb72015-11-19 13:31:17 -0800102 { OPT, "/sys/kernel/debug/tracing/events/sched/sched_blocked_reason/enable" },
Jamie Gennis6eea6fb2012-12-07 14:03:07 -0800103 } },
Dan Willemsenf440d392014-04-11 15:44:09 -0700104 { "irq", "IRQ Events", 0, {
105 { REQ, "/sys/kernel/debug/tracing/events/irq/enable" },
Riley Andrews412e4f62015-11-02 21:01:34 -0800106 { OPT, "/sys/kernel/debug/tracing/events/ipi/enable" },
Dan Willemsenf440d392014-04-11 15:44:09 -0700107 } },
Jamie Gennisb2a89e32013-03-11 19:37:53 -0700108 { "freq", "CPU Frequency", 0, {
109 { REQ, "/sys/kernel/debug/tracing/events/power/cpu_frequency/enable" },
110 { OPT, "/sys/kernel/debug/tracing/events/power/clock_set_rate/enable" },
Jamie Gennis6eea6fb2012-12-07 14:03:07 -0800111 } },
Jamie Gennisb2a89e32013-03-11 19:37:53 -0700112 { "membus", "Memory Bus Utilization", 0, {
113 { REQ, "/sys/kernel/debug/tracing/events/memory_bus/enable" },
Jamie Gennis6eea6fb2012-12-07 14:03:07 -0800114 } },
Jamie Gennisb2a89e32013-03-11 19:37:53 -0700115 { "idle", "CPU Idle", 0, {
116 { REQ, "/sys/kernel/debug/tracing/events/power/cpu_idle/enable" },
Jamie Gennis6eea6fb2012-12-07 14:03:07 -0800117 } },
Jamie Gennisb2a89e32013-03-11 19:37:53 -0700118 { "disk", "Disk I/O", 0, {
Greg Hackmanne80d32c2014-11-20 12:59:44 -0800119 { OPT, "/sys/kernel/debug/tracing/events/f2fs/f2fs_sync_file_enter/enable" },
120 { OPT, "/sys/kernel/debug/tracing/events/f2fs/f2fs_sync_file_exit/enable" },
121 { OPT, "/sys/kernel/debug/tracing/events/f2fs/f2fs_write_begin/enable" },
122 { OPT, "/sys/kernel/debug/tracing/events/f2fs/f2fs_write_end/enable" },
123 { OPT, "/sys/kernel/debug/tracing/events/ext4/ext4_da_write_begin/enable" },
124 { OPT, "/sys/kernel/debug/tracing/events/ext4/ext4_da_write_end/enable" },
125 { OPT, "/sys/kernel/debug/tracing/events/ext4/ext4_sync_file_enter/enable" },
126 { OPT, "/sys/kernel/debug/tracing/events/ext4/ext4_sync_file_exit/enable" },
Jamie Gennisb2a89e32013-03-11 19:37:53 -0700127 { REQ, "/sys/kernel/debug/tracing/events/block/block_rq_issue/enable" },
128 { REQ, "/sys/kernel/debug/tracing/events/block/block_rq_complete/enable" },
Jamie Gennis6eea6fb2012-12-07 14:03:07 -0800129 } },
Ken Sumralld3fa5612013-07-03 12:32:03 -0700130 { "mmc", "eMMC commands", 0, {
131 { REQ, "/sys/kernel/debug/tracing/events/mmc/enable" },
132 } },
Jamie Gennisb2a89e32013-03-11 19:37:53 -0700133 { "load", "CPU Load", 0, {
134 { REQ, "/sys/kernel/debug/tracing/events/cpufreq_interactive/enable" },
Jamie Gennis6eea6fb2012-12-07 14:03:07 -0800135 } },
Jamie Gennisb2a89e32013-03-11 19:37:53 -0700136 { "sync", "Synchronization", 0, {
137 { REQ, "/sys/kernel/debug/tracing/events/sync/enable" },
Jamie Gennis6eea6fb2012-12-07 14:03:07 -0800138 } },
Jamie Gennisb2a89e32013-03-11 19:37:53 -0700139 { "workq", "Kernel Workqueues", 0, {
140 { REQ, "/sys/kernel/debug/tracing/events/workqueue/enable" },
Jamie Gennis6eea6fb2012-12-07 14:03:07 -0800141 } },
Colin Cross580407f2014-08-18 15:22:13 -0700142 { "memreclaim", "Kernel Memory Reclaim", 0, {
143 { REQ, "/sys/kernel/debug/tracing/events/vmscan/mm_vmscan_direct_reclaim_begin/enable" },
144 { REQ, "/sys/kernel/debug/tracing/events/vmscan/mm_vmscan_direct_reclaim_end/enable" },
145 { REQ, "/sys/kernel/debug/tracing/events/vmscan/mm_vmscan_kswapd_wake/enable" },
146 { REQ, "/sys/kernel/debug/tracing/events/vmscan/mm_vmscan_kswapd_sleep/enable" },
147 } },
Aaron Schulmanc2c6ecd2015-02-25 08:37:09 -0800148 { "regulators", "Voltage and Current Regulators", 0, {
149 { REQ, "/sys/kernel/debug/tracing/events/regulator/enable" },
150 } },
Scott Bauerae473362015-06-08 16:32:36 -0700151 { "binder_driver", "Binder Kernel driver", 0, {
152 { REQ, "/sys/kernel/debug/tracing/events/binder/binder_transaction/enable" },
153 { REQ, "/sys/kernel/debug/tracing/events/binder/binder_transaction_received/enable" },
154 } },
155 { "binder_lock", "Binder global lock trace", 0, {
156 { REQ, "/sys/kernel/debug/tracing/events/binder/binder_lock/enable" },
157 { REQ, "/sys/kernel/debug/tracing/events/binder/binder_locked/enable" },
158 { REQ, "/sys/kernel/debug/tracing/events/binder/binder_unlock/enable" },
159 } },
Jamie Gennis6eea6fb2012-12-07 14:03:07 -0800160};
161
162/* Command line options */
163static int g_traceDurationSeconds = 5;
164static bool g_traceOverwrite = false;
165static int g_traceBufferSizeKB = 2048;
166static bool g_compress = false;
167static bool g_nohup = false;
168static int g_initialSleepSecs = 0;
Yasuhiro Matsuda46c51fb2015-06-29 19:20:39 +0900169static const char* g_categoriesFile = NULL;
Jamie Gennise9b8cfb2013-03-12 16:00:10 -0700170static const char* g_kernelTraceFuncs = NULL;
Jamie Gennisf7f29c82013-03-27 15:50:58 -0700171static const char* g_debugAppCmdLine = "";
Jamie Gennis6eea6fb2012-12-07 14:03:07 -0800172
173/* Global state */
174static bool g_traceAborted = false;
175static bool g_categoryEnables[NELEM(k_categories)] = {};
176
177/* Sys file paths */
178static const char* k_traceClockPath =
179 "/sys/kernel/debug/tracing/trace_clock";
180
181static const char* k_traceBufferSizePath =
182 "/sys/kernel/debug/tracing/buffer_size_kb";
183
184static const char* k_tracingOverwriteEnablePath =
185 "/sys/kernel/debug/tracing/options/overwrite";
186
Jamie Gennise9b8cfb2013-03-12 16:00:10 -0700187static const char* k_currentTracerPath =
188 "/sys/kernel/debug/tracing/current_tracer";
189
190static const char* k_printTgidPath =
191 "/sys/kernel/debug/tracing/options/print-tgid";
192
193static const char* k_funcgraphAbsTimePath =
194 "/sys/kernel/debug/tracing/options/funcgraph-abstime";
195
196static const char* k_funcgraphCpuPath =
197 "/sys/kernel/debug/tracing/options/funcgraph-cpu";
198
199static const char* k_funcgraphProcPath =
200 "/sys/kernel/debug/tracing/options/funcgraph-proc";
201
202static const char* k_funcgraphFlatPath =
203 "/sys/kernel/debug/tracing/options/funcgraph-flat";
204
205static const char* k_funcgraphDurationPath =
206 "/sys/kernel/debug/tracing/options/funcgraph-duration";
207
208static const char* k_ftraceFilterPath =
209 "/sys/kernel/debug/tracing/set_ftrace_filter";
210
Jamie Gennis6eea6fb2012-12-07 14:03:07 -0800211static const char* k_tracingOnPath =
212 "/sys/kernel/debug/tracing/tracing_on";
213
214static const char* k_tracePath =
215 "/sys/kernel/debug/tracing/trace";
216
Martijn Coenend9535872015-11-26 10:00:55 +0100217static const char* k_traceStreamPath =
218 "/sys/kernel/debug/tracing/trace_pipe";
219
John Reck469a1942015-03-26 15:31:35 -0700220static const char* k_traceMarkerPath =
221 "/sys/kernel/debug/tracing/trace_marker";
222
Jamie Gennis6eea6fb2012-12-07 14:03:07 -0800223// Check whether a file exists.
224static bool fileExists(const char* filename) {
225 return access(filename, F_OK) != -1;
226}
227
228// Check whether a file is writable.
229static bool fileIsWritable(const char* filename) {
230 return access(filename, W_OK) != -1;
231}
232
Jamie Gennise9b8cfb2013-03-12 16:00:10 -0700233// Truncate a file.
234static bool truncateFile(const char* path)
Jamie Gennis6eea6fb2012-12-07 14:03:07 -0800235{
Jamie Gennis43122e72013-03-21 14:06:31 -0700236 // This uses creat rather than truncate because some of the debug kernel
237 // device nodes (e.g. k_ftraceFilterPath) currently aren't changed by
238 // calls to truncate, but they are cleared by calls to creat.
239 int traceFD = creat(path, 0);
240 if (traceFD == -1) {
Jamie Gennise9b8cfb2013-03-12 16:00:10 -0700241 fprintf(stderr, "error truncating %s: %s (%d)\n", path,
Jamie Gennis43122e72013-03-21 14:06:31 -0700242 strerror(errno), errno);
Jamie Gennise9b8cfb2013-03-12 16:00:10 -0700243 return false;
244 }
245
Jamie Gennis43122e72013-03-21 14:06:31 -0700246 close(traceFD);
247
Jamie Gennise9b8cfb2013-03-12 16:00:10 -0700248 return true;
249}
250
251static bool _writeStr(const char* filename, const char* str, int flags)
252{
253 int fd = open(filename, flags);
Jamie Gennis6eea6fb2012-12-07 14:03:07 -0800254 if (fd == -1) {
255 fprintf(stderr, "error opening %s: %s (%d)\n", filename,
256 strerror(errno), errno);
257 return false;
258 }
259
260 bool ok = true;
261 ssize_t len = strlen(str);
262 if (write(fd, str, len) != len) {
263 fprintf(stderr, "error writing to %s: %s (%d)\n", filename,
264 strerror(errno), errno);
265 ok = false;
266 }
267
268 close(fd);
269
270 return ok;
271}
272
Jamie Gennise9b8cfb2013-03-12 16:00:10 -0700273// Write a string to a file, returning true if the write was successful.
274static bool writeStr(const char* filename, const char* str)
275{
276 return _writeStr(filename, str, O_WRONLY);
277}
278
279// Append a string to a file, returning true if the write was successful.
280static bool appendStr(const char* filename, const char* str)
281{
282 return _writeStr(filename, str, O_APPEND|O_WRONLY);
283}
284
John Reck469a1942015-03-26 15:31:35 -0700285static void writeClockSyncMarker()
286{
287 char buffer[128];
Martijn Coenen0bcd97a2015-07-15 14:25:23 +0200288 int len = 0;
289 int fd = open(k_traceMarkerPath, O_WRONLY);
290 if (fd == -1) {
291 fprintf(stderr, "error opening %s: %s (%d)\n", k_traceMarkerPath,
292 strerror(errno), errno);
293 return;
294 }
John Reck469a1942015-03-26 15:31:35 -0700295 float now_in_seconds = systemTime(CLOCK_MONOTONIC) / 1000000000.0f;
Martijn Coenen0bcd97a2015-07-15 14:25:23 +0200296
297 len = snprintf(buffer, 128, "trace_event_clock_sync: parent_ts=%f\n", now_in_seconds);
298 if (write(fd, buffer, len) != len) {
299 fprintf(stderr, "error writing clock sync marker %s (%d)\n", strerror(errno), errno);
300 }
301
302 int64_t realtime_in_ms = systemTime(CLOCK_REALTIME) / 1000000;
303 len = snprintf(buffer, 128, "trace_event_clock_sync: realtime_ts=%" PRId64 "\n", realtime_in_ms);
304 if (write(fd, buffer, len) != len) {
305 fprintf(stderr, "error writing clock sync marker %s (%d)\n", strerror(errno), errno);
306 }
307
308 close(fd);
John Reck469a1942015-03-26 15:31:35 -0700309}
310
Jamie Gennis6eea6fb2012-12-07 14:03:07 -0800311// Enable or disable a kernel option by writing a "1" or a "0" into a /sys
312// file.
313static bool setKernelOptionEnable(const char* filename, bool enable)
314{
315 return writeStr(filename, enable ? "1" : "0");
316}
317
318// Check whether the category is supported on the device with the current
319// rootness. A category is supported only if all its required /sys/ files are
320// writable and if enabling the category will enable one or more tracing tags
321// or /sys/ files.
322static bool isCategorySupported(const TracingCategory& category)
323{
324 bool ok = category.tags != 0;
325 for (int i = 0; i < MAX_SYS_FILES; i++) {
326 const char* path = category.sysfiles[i].path;
327 bool req = category.sysfiles[i].required == REQ;
328 if (path != NULL) {
329 if (req) {
330 if (!fileIsWritable(path)) {
331 return false;
332 } else {
333 ok = true;
334 }
335 } else {
336 ok |= fileIsWritable(path);
337 }
338 }
339 }
340 return ok;
341}
342
343// Check whether the category would be supported on the device if the user
344// were root. This function assumes that root is able to write to any file
345// that exists. It performs the same logic as isCategorySupported, but it
346// uses file existance rather than writability in the /sys/ file checks.
347static bool isCategorySupportedForRoot(const TracingCategory& category)
348{
349 bool ok = category.tags != 0;
350 for (int i = 0; i < MAX_SYS_FILES; i++) {
351 const char* path = category.sysfiles[i].path;
352 bool req = category.sysfiles[i].required == REQ;
353 if (path != NULL) {
354 if (req) {
355 if (!fileExists(path)) {
356 return false;
357 } else {
358 ok = true;
359 }
360 } else {
361 ok |= fileExists(path);
362 }
363 }
364 }
365 return ok;
366}
367
368// Enable or disable overwriting of the kernel trace buffers. Disabling this
369// will cause tracing to stop once the trace buffers have filled up.
370static bool setTraceOverwriteEnable(bool enable)
371{
372 return setKernelOptionEnable(k_tracingOverwriteEnablePath, enable);
373}
374
375// Enable or disable kernel tracing.
376static bool setTracingEnabled(bool enable)
377{
378 return setKernelOptionEnable(k_tracingOnPath, enable);
379}
380
381// Clear the contents of the kernel trace.
382static bool clearTrace()
383{
Jamie Gennise9b8cfb2013-03-12 16:00:10 -0700384 return truncateFile(k_tracePath);
Jamie Gennis6eea6fb2012-12-07 14:03:07 -0800385}
386
387// Set the size of the kernel's trace buffer in kilobytes.
388static bool setTraceBufferSizeKB(int size)
389{
390 char str[32] = "1";
391 int len;
392 if (size < 1) {
393 size = 1;
394 }
395 snprintf(str, 32, "%d", size);
396 return writeStr(k_traceBufferSizePath, str);
397}
398
Colin Crossb1ce49b2014-08-20 14:28:47 -0700399// Read the trace_clock sysfs file and return true if it matches the requested
400// value. The trace_clock file format is:
401// local [global] counter uptime perf
402static bool isTraceClock(const char *mode)
403{
404 int fd = open(k_traceClockPath, O_RDONLY);
405 if (fd == -1) {
406 fprintf(stderr, "error opening %s: %s (%d)\n", k_traceClockPath,
407 strerror(errno), errno);
408 return false;
409 }
410
411 char buf[4097];
412 ssize_t n = read(fd, buf, 4096);
413 close(fd);
414 if (n == -1) {
415 fprintf(stderr, "error reading %s: %s (%d)\n", k_traceClockPath,
416 strerror(errno), errno);
417 return false;
418 }
419 buf[n] = '\0';
420
421 char *start = strchr(buf, '[');
422 if (start == NULL) {
423 return false;
424 }
425 start++;
426
427 char *end = strchr(start, ']');
428 if (end == NULL) {
429 return false;
430 }
431 *end = '\0';
432
433 return strcmp(mode, start) == 0;
434}
435
Jamie Gennis6eea6fb2012-12-07 14:03:07 -0800436// Enable or disable the kernel's use of the global clock. Disabling the global
437// clock will result in the kernel using a per-CPU local clock.
Colin Crossb1ce49b2014-08-20 14:28:47 -0700438// Any write to the trace_clock sysfs file will reset the buffer, so only
439// update it if the requested value is not the current value.
Jamie Gennis6eea6fb2012-12-07 14:03:07 -0800440static bool setGlobalClockEnable(bool enable)
441{
Colin Crossb1ce49b2014-08-20 14:28:47 -0700442 const char *clock = enable ? "global" : "local";
443
444 if (isTraceClock(clock)) {
445 return true;
446 }
447
448 return writeStr(k_traceClockPath, clock);
Jamie Gennis6eea6fb2012-12-07 14:03:07 -0800449}
450
Jamie Gennise9b8cfb2013-03-12 16:00:10 -0700451static bool setPrintTgidEnableIfPresent(bool enable)
452{
453 if (fileExists(k_printTgidPath)) {
454 return setKernelOptionEnable(k_printTgidPath, enable);
455 }
456 return true;
457}
458
Jamie Gennis6eea6fb2012-12-07 14:03:07 -0800459// Poke all the binder-enabled processes in the system to get them to re-read
460// their system properties.
461static bool pokeBinderServices()
462{
463 sp<IServiceManager> sm = defaultServiceManager();
464 Vector<String16> services = sm->listServices();
465 for (size_t i = 0; i < services.size(); i++) {
466 sp<IBinder> obj = sm->checkService(services[i]);
467 if (obj != NULL) {
468 Parcel data;
469 if (obj->transact(IBinder::SYSPROPS_TRANSACTION, data,
470 NULL, 0) != OK) {
471 if (false) {
472 // XXX: For some reason this fails on tablets trying to
473 // poke the "phone" service. It's not clear whether some
474 // are expected to fail.
475 String8 svc(services[i]);
476 fprintf(stderr, "error poking binder service %s\n",
477 svc.string());
478 return false;
479 }
480 }
481 }
482 }
483 return true;
484}
485
486// Set the trace tags that userland tracing uses, and poke the running
487// processes to pick up the new value.
488static bool setTagsProperty(uint64_t tags)
489{
490 char buf[64];
Mark Salyzyn92dc3fc2014-03-12 13:12:44 -0700491 snprintf(buf, 64, "%#" PRIx64, tags);
Jamie Gennis6eea6fb2012-12-07 14:03:07 -0800492 if (property_set(k_traceTagsProperty, buf) < 0) {
493 fprintf(stderr, "error setting trace tags system property\n");
494 return false;
495 }
Jamie Gennisf7f29c82013-03-27 15:50:58 -0700496 return true;
497}
498
499// Set the system property that indicates which apps should perform
500// application-level tracing.
501static bool setAppCmdlineProperty(const char* cmdline)
502{
503 if (property_set(k_traceAppCmdlineProperty, cmdline) < 0) {
504 fprintf(stderr, "error setting trace app system property\n");
505 return false;
506 }
507 return true;
Jamie Gennis6eea6fb2012-12-07 14:03:07 -0800508}
509
510// Disable all /sys/ enable files.
511static bool disableKernelTraceEvents() {
512 bool ok = true;
513 for (int i = 0; i < NELEM(k_categories); i++) {
514 const TracingCategory &c = k_categories[i];
515 for (int j = 0; j < MAX_SYS_FILES; j++) {
516 const char* path = c.sysfiles[j].path;
517 if (path != NULL && fileIsWritable(path)) {
518 ok &= setKernelOptionEnable(path, false);
519 }
520 }
521 }
522 return ok;
523}
524
Jamie Gennise9b8cfb2013-03-12 16:00:10 -0700525// Verify that the comma separated list of functions are being traced by the
526// kernel.
527static bool verifyKernelTraceFuncs(const char* funcs)
528{
Stephane Gasparinid8419c22016-03-02 13:45:15 +0100529 std::string buf;
530 if (!android::base::ReadFileToString(k_ftraceFilterPath, &buf)) {
531 fprintf(stderr, "error opening %s: %s (%d)\n", k_ftraceFilterPath,
Jamie Gennise9b8cfb2013-03-12 16:00:10 -0700532 strerror(errno), errno);
Stephane Gasparinid8419c22016-03-02 13:45:15 +0100533 return false;
Jamie Gennise9b8cfb2013-03-12 16:00:10 -0700534 }
535
Stephane Gasparinid8419c22016-03-02 13:45:15 +0100536 String8 funcList = String8::format("\n%s",buf.c_str());
Jamie Gennise9b8cfb2013-03-12 16:00:10 -0700537
538 // Make sure that every function listed in funcs is in the list we just
Thomas Buhota2c22872016-01-27 09:44:31 +0100539 // read from the kernel, except for wildcard inputs.
Jamie Gennise9b8cfb2013-03-12 16:00:10 -0700540 bool ok = true;
541 char* myFuncs = strdup(funcs);
542 char* func = strtok(myFuncs, ",");
543 while (func) {
Thomas Buhota2c22872016-01-27 09:44:31 +0100544 if (!strchr(func, '*')) {
545 String8 fancyFunc = String8::format("\n%s\n", func);
546 bool found = funcList.find(fancyFunc.string(), 0) >= 0;
547 if (!found || func[0] == '\0') {
548 fprintf(stderr, "error: \"%s\" is not a valid kernel function "
549 "to trace.\n", func);
550 ok = false;
551 }
Jamie Gennise9b8cfb2013-03-12 16:00:10 -0700552 }
553 func = strtok(NULL, ",");
554 }
555 free(myFuncs);
Jamie Gennise9b8cfb2013-03-12 16:00:10 -0700556 return ok;
557}
558
559// Set the comma separated list of functions that the kernel is to trace.
560static bool setKernelTraceFuncs(const char* funcs)
561{
562 bool ok = true;
563
564 if (funcs == NULL || funcs[0] == '\0') {
565 // Disable kernel function tracing.
Jamie Gennis6f6f3f72013-03-27 15:50:30 -0700566 if (fileIsWritable(k_currentTracerPath)) {
567 ok &= writeStr(k_currentTracerPath, "nop");
568 }
569 if (fileIsWritable(k_ftraceFilterPath)) {
Jamie Gennise9b8cfb2013-03-12 16:00:10 -0700570 ok &= truncateFile(k_ftraceFilterPath);
571 }
572 } else {
573 // Enable kernel function tracing.
574 ok &= writeStr(k_currentTracerPath, "function_graph");
575 ok &= setKernelOptionEnable(k_funcgraphAbsTimePath, true);
576 ok &= setKernelOptionEnable(k_funcgraphCpuPath, true);
577 ok &= setKernelOptionEnable(k_funcgraphProcPath, true);
578 ok &= setKernelOptionEnable(k_funcgraphFlatPath, true);
579
580 // Set the requested filter functions.
581 ok &= truncateFile(k_ftraceFilterPath);
582 char* myFuncs = strdup(funcs);
583 char* func = strtok(myFuncs, ",");
584 while (func) {
585 ok &= appendStr(k_ftraceFilterPath, func);
586 func = strtok(NULL, ",");
587 }
588 free(myFuncs);
589
590 // Verify that the set functions are being traced.
591 if (ok) {
592 ok &= verifyKernelTraceFuncs(funcs);
593 }
594 }
595
596 return ok;
597}
598
Yasuhiro Matsuda46c51fb2015-06-29 19:20:39 +0900599static bool setCategoryEnable(const char* name, bool enable)
600{
601 for (int i = 0; i < NELEM(k_categories); i++) {
602 const TracingCategory& c = k_categories[i];
603 if (strcmp(name, c.name) == 0) {
604 if (isCategorySupported(c)) {
605 g_categoryEnables[i] = enable;
606 return true;
607 } else {
608 if (isCategorySupportedForRoot(c)) {
609 fprintf(stderr, "error: category \"%s\" requires root "
610 "privileges.\n", name);
611 } else {
612 fprintf(stderr, "error: category \"%s\" is not supported "
613 "on this device.\n", name);
614 }
615 return false;
616 }
617 }
618 }
619 fprintf(stderr, "error: unknown tracing category \"%s\"\n", name);
620 return false;
621}
622
623static bool setCategoriesEnableFromFile(const char* categories_file)
624{
625 if (!categories_file) {
626 return true;
627 }
628 Tokenizer* tokenizer = NULL;
629 if (Tokenizer::open(String8(categories_file), &tokenizer) != NO_ERROR) {
630 return false;
631 }
632 bool ok = true;
633 while (!tokenizer->isEol()) {
634 String8 token = tokenizer->nextToken(" ");
635 if (token.isEmpty()) {
636 tokenizer->skipDelimiters(" ");
637 continue;
638 }
639 ok &= setCategoryEnable(token.string(), true);
640 }
641 delete tokenizer;
642 return ok;
643}
644
Jamie Gennise9b8cfb2013-03-12 16:00:10 -0700645// Set all the kernel tracing settings to the desired state for this trace
646// capture.
647static bool setUpTrace()
Jamie Gennis6eea6fb2012-12-07 14:03:07 -0800648{
649 bool ok = true;
650
651 // Set up the tracing options.
Yasuhiro Matsuda46c51fb2015-06-29 19:20:39 +0900652 ok &= setCategoriesEnableFromFile(g_categoriesFile);
Jamie Gennis6eea6fb2012-12-07 14:03:07 -0800653 ok &= setTraceOverwriteEnable(g_traceOverwrite);
654 ok &= setTraceBufferSizeKB(g_traceBufferSizeKB);
655 ok &= setGlobalClockEnable(true);
Jamie Gennise9b8cfb2013-03-12 16:00:10 -0700656 ok &= setPrintTgidEnableIfPresent(true);
657 ok &= setKernelTraceFuncs(g_kernelTraceFuncs);
Jamie Gennis6eea6fb2012-12-07 14:03:07 -0800658
659 // Set up the tags property.
660 uint64_t tags = 0;
661 for (int i = 0; i < NELEM(k_categories); i++) {
662 if (g_categoryEnables[i]) {
663 const TracingCategory &c = k_categories[i];
664 tags |= c.tags;
665 }
666 }
667 ok &= setTagsProperty(tags);
Jamie Gennisf7f29c82013-03-27 15:50:58 -0700668 ok &= setAppCmdlineProperty(g_debugAppCmdLine);
669 ok &= pokeBinderServices();
Jamie Gennis6eea6fb2012-12-07 14:03:07 -0800670
671 // Disable all the sysfs enables. This is done as a separate loop from
672 // the enables to allow the same enable to exist in multiple categories.
673 ok &= disableKernelTraceEvents();
674
675 // Enable all the sysfs enables that are in an enabled category.
676 for (int i = 0; i < NELEM(k_categories); i++) {
677 if (g_categoryEnables[i]) {
678 const TracingCategory &c = k_categories[i];
679 for (int j = 0; j < MAX_SYS_FILES; j++) {
680 const char* path = c.sysfiles[j].path;
681 bool required = c.sysfiles[j].required == REQ;
682 if (path != NULL) {
683 if (fileIsWritable(path)) {
684 ok &= setKernelOptionEnable(path, true);
685 } else if (required) {
686 fprintf(stderr, "error writing file %s\n", path);
687 ok = false;
688 }
689 }
690 }
691 }
692 }
693
Jamie Gennis6eea6fb2012-12-07 14:03:07 -0800694 return ok;
695}
696
Jamie Gennise9b8cfb2013-03-12 16:00:10 -0700697// Reset all the kernel tracing settings to their default state.
698static void cleanUpTrace()
Jamie Gennis6eea6fb2012-12-07 14:03:07 -0800699{
Jamie Gennis6eea6fb2012-12-07 14:03:07 -0800700 // Disable all tracing that we're able to.
701 disableKernelTraceEvents();
702
Jamie Gennisf7f29c82013-03-27 15:50:58 -0700703 // Reset the system properties.
Jamie Gennis6eea6fb2012-12-07 14:03:07 -0800704 setTagsProperty(0);
Jamie Gennisf7f29c82013-03-27 15:50:58 -0700705 setAppCmdlineProperty("");
706 pokeBinderServices();
Jamie Gennis6eea6fb2012-12-07 14:03:07 -0800707
708 // Set the options back to their defaults.
709 setTraceOverwriteEnable(true);
Jamie Gennise9b8cfb2013-03-12 16:00:10 -0700710 setTraceBufferSizeKB(1);
Jamie Gennis6eea6fb2012-12-07 14:03:07 -0800711 setGlobalClockEnable(false);
Jamie Gennise9b8cfb2013-03-12 16:00:10 -0700712 setPrintTgidEnableIfPresent(false);
713 setKernelTraceFuncs(NULL);
714}
Jamie Gennis6eea6fb2012-12-07 14:03:07 -0800715
Jamie Gennise9b8cfb2013-03-12 16:00:10 -0700716
717// Enable tracing in the kernel.
718static bool startTrace()
719{
720 return setTracingEnabled(true);
721}
722
723// Disable tracing in the kernel.
724static void stopTrace()
725{
726 setTracingEnabled(false);
Jamie Gennis6eea6fb2012-12-07 14:03:07 -0800727}
728
Martijn Coenend9535872015-11-26 10:00:55 +0100729// Read data from the tracing pipe and forward to stdout
730static void streamTrace()
731{
732 char trace_data[4096];
733 int traceFD = open(k_traceStreamPath, O_RDWR);
734 if (traceFD == -1) {
735 fprintf(stderr, "error opening %s: %s (%d)\n", k_traceStreamPath,
736 strerror(errno), errno);
737 return;
738 }
739 while (!g_traceAborted) {
740 ssize_t bytes_read = read(traceFD, trace_data, 4096);
741 if (bytes_read > 0) {
742 write(STDOUT_FILENO, trace_data, bytes_read);
743 fflush(stdout);
744 } else {
745 if (!g_traceAborted) {
746 fprintf(stderr, "read returned %zd bytes err %d (%s)\n",
747 bytes_read, errno, strerror(errno));
748 }
749 break;
750 }
751 }
752}
753
Jamie Gennis6eea6fb2012-12-07 14:03:07 -0800754// Read the current kernel trace and write it to stdout.
755static void dumpTrace()
756{
757 int traceFD = open(k_tracePath, O_RDWR);
758 if (traceFD == -1) {
759 fprintf(stderr, "error opening %s: %s (%d)\n", k_tracePath,
760 strerror(errno), errno);
761 return;
762 }
763
764 if (g_compress) {
765 z_stream zs;
766 uint8_t *in, *out;
767 int result, flush;
768
Elliott Hughes3da5d232015-01-25 08:35:20 -0800769 memset(&zs, 0, sizeof(zs));
Jamie Gennis6eea6fb2012-12-07 14:03:07 -0800770 result = deflateInit(&zs, Z_DEFAULT_COMPRESSION);
771 if (result != Z_OK) {
772 fprintf(stderr, "error initializing zlib: %d\n", result);
773 close(traceFD);
774 return;
775 }
776
777 const size_t bufSize = 64*1024;
778 in = (uint8_t*)malloc(bufSize);
779 out = (uint8_t*)malloc(bufSize);
780 flush = Z_NO_FLUSH;
781
782 zs.next_out = out;
783 zs.avail_out = bufSize;
784
785 do {
786
787 if (zs.avail_in == 0) {
788 // More input is needed.
789 result = read(traceFD, in, bufSize);
790 if (result < 0) {
791 fprintf(stderr, "error reading trace: %s (%d)\n",
792 strerror(errno), errno);
793 result = Z_STREAM_END;
794 break;
795 } else if (result == 0) {
796 flush = Z_FINISH;
797 } else {
798 zs.next_in = in;
799 zs.avail_in = result;
800 }
801 }
802
803 if (zs.avail_out == 0) {
804 // Need to write the output.
805 result = write(STDOUT_FILENO, out, bufSize);
806 if ((size_t)result < bufSize) {
807 fprintf(stderr, "error writing deflated trace: %s (%d)\n",
808 strerror(errno), errno);
809 result = Z_STREAM_END; // skip deflate error message
810 zs.avail_out = bufSize; // skip the final write
811 break;
812 }
813 zs.next_out = out;
814 zs.avail_out = bufSize;
815 }
816
817 } while ((result = deflate(&zs, flush)) == Z_OK);
818
819 if (result != Z_STREAM_END) {
820 fprintf(stderr, "error deflating trace: %s\n", zs.msg);
821 }
822
823 if (zs.avail_out < bufSize) {
824 size_t bytes = bufSize - zs.avail_out;
825 result = write(STDOUT_FILENO, out, bytes);
826 if ((size_t)result < bytes) {
827 fprintf(stderr, "error writing deflated trace: %s (%d)\n",
828 strerror(errno), errno);
829 }
830 }
831
832 result = deflateEnd(&zs);
833 if (result != Z_OK) {
834 fprintf(stderr, "error cleaning up zlib: %d\n", result);
835 }
836
837 free(in);
838 free(out);
839 } else {
840 ssize_t sent = 0;
841 while ((sent = sendfile(STDOUT_FILENO, traceFD, NULL, 64*1024*1024)) > 0);
842 if (sent == -1) {
843 fprintf(stderr, "error dumping trace: %s (%d)\n", strerror(errno),
844 errno);
845 }
846 }
847
848 close(traceFD);
849}
850
Mark Salyzyn92dc3fc2014-03-12 13:12:44 -0700851static void handleSignal(int /*signo*/)
Jamie Gennis6eea6fb2012-12-07 14:03:07 -0800852{
853 if (!g_nohup) {
854 g_traceAborted = true;
855 }
856}
857
858static void registerSigHandler()
859{
860 struct sigaction sa;
861 sigemptyset(&sa.sa_mask);
862 sa.sa_flags = 0;
863 sa.sa_handler = handleSignal;
864 sigaction(SIGHUP, &sa, NULL);
865 sigaction(SIGINT, &sa, NULL);
866 sigaction(SIGQUIT, &sa, NULL);
867 sigaction(SIGTERM, &sa, NULL);
868}
869
Jamie Gennis6eea6fb2012-12-07 14:03:07 -0800870static void listSupportedCategories()
871{
872 for (int i = 0; i < NELEM(k_categories); i++) {
873 const TracingCategory& c = k_categories[i];
874 if (isCategorySupported(c)) {
875 printf(" %10s - %s\n", c.name, c.longname);
876 }
877 }
878}
879
880// Print the command usage help to stderr.
881static void showHelp(const char *cmd)
882{
883 fprintf(stderr, "usage: %s [options] [categories...]\n", cmd);
884 fprintf(stderr, "options include:\n"
Jamie Gennisf7f29c82013-03-27 15:50:58 -0700885 " -a appname enable app-level tracing for a comma "
886 "separated list of cmdlines\n"
Jamie Gennis6eea6fb2012-12-07 14:03:07 -0800887 " -b N use a trace buffer size of N KB\n"
888 " -c trace into a circular buffer\n"
Yasuhiro Matsuda46c51fb2015-06-29 19:20:39 +0900889 " -f filename use the categories written in a file as space-separated\n"
890 " values in a line\n"
Jamie Gennise9b8cfb2013-03-12 16:00:10 -0700891 " -k fname,... trace the listed kernel functions\n"
Jamie Gennis6eea6fb2012-12-07 14:03:07 -0800892 " -n ignore signals\n"
893 " -s N sleep for N seconds before tracing [default 0]\n"
894 " -t N trace for N seconds [defualt 5]\n"
895 " -z compress the trace dump\n"
896 " --async_start start circular trace and return immediatly\n"
897 " --async_dump dump the current contents of circular trace buffer\n"
898 " --async_stop stop tracing and dump the current contents of circular\n"
899 " trace buffer\n"
Martijn Coenend9535872015-11-26 10:00:55 +0100900 " --stream stream trace to stdout as it enters the trace buffer\n"
901 " Note: this can take significant CPU time, and is best\n"
902 " used for measuring things that are not affected by\n"
903 " CPU performance, like pagecache usage.\n"
Jamie Gennis92573f12012-12-07 16:29:03 -0800904 " --list_categories\n"
905 " list the available tracing categories\n"
Jamie Gennis6eea6fb2012-12-07 14:03:07 -0800906 );
907}
908
909int main(int argc, char **argv)
910{
911 bool async = false;
912 bool traceStart = true;
913 bool traceStop = true;
914 bool traceDump = true;
Martijn Coenend9535872015-11-26 10:00:55 +0100915 bool traceStream = false;
Jamie Gennis6eea6fb2012-12-07 14:03:07 -0800916
917 if (argc == 2 && 0 == strcmp(argv[1], "--help")) {
918 showHelp(argv[0]);
919 exit(0);
920 }
921
922 for (;;) {
923 int ret;
924 int option_index = 0;
925 static struct option long_options[] = {
926 {"async_start", no_argument, 0, 0 },
927 {"async_stop", no_argument, 0, 0 },
928 {"async_dump", no_argument, 0, 0 },
929 {"list_categories", no_argument, 0, 0 },
Martijn Coenend9535872015-11-26 10:00:55 +0100930 {"stream", no_argument, 0, 0 },
Jamie Gennis6eea6fb2012-12-07 14:03:07 -0800931 { 0, 0, 0, 0 }
932 };
933
Yasuhiro Matsuda46c51fb2015-06-29 19:20:39 +0900934 ret = getopt_long(argc, argv, "a:b:cf:k:ns:t:z",
Jamie Gennis6eea6fb2012-12-07 14:03:07 -0800935 long_options, &option_index);
936
937 if (ret < 0) {
938 for (int i = optind; i < argc; i++) {
939 if (!setCategoryEnable(argv[i], true)) {
940 fprintf(stderr, "error enabling tracing category \"%s\"\n", argv[i]);
941 exit(1);
942 }
943 }
944 break;
945 }
946
947 switch(ret) {
Jamie Gennisf7f29c82013-03-27 15:50:58 -0700948 case 'a':
949 g_debugAppCmdLine = optarg;
950 break;
951
Jamie Gennis6eea6fb2012-12-07 14:03:07 -0800952 case 'b':
953 g_traceBufferSizeKB = atoi(optarg);
954 break;
955
956 case 'c':
957 g_traceOverwrite = true;
958 break;
959
Yasuhiro Matsuda46c51fb2015-06-29 19:20:39 +0900960 case 'f':
961 g_categoriesFile = optarg;
962 break;
963
Jamie Gennise9b8cfb2013-03-12 16:00:10 -0700964 case 'k':
965 g_kernelTraceFuncs = optarg;
Jamie Gennis6f6f3f72013-03-27 15:50:30 -0700966 break;
Jamie Gennise9b8cfb2013-03-12 16:00:10 -0700967
Jamie Gennis6eea6fb2012-12-07 14:03:07 -0800968 case 'n':
969 g_nohup = true;
Jamie Gennis6f6f3f72013-03-27 15:50:30 -0700970 break;
Jamie Gennis6eea6fb2012-12-07 14:03:07 -0800971
972 case 's':
973 g_initialSleepSecs = atoi(optarg);
974 break;
975
976 case 't':
977 g_traceDurationSeconds = atoi(optarg);
978 break;
979
980 case 'z':
981 g_compress = true;
982 break;
983
984 case 0:
985 if (!strcmp(long_options[option_index].name, "async_start")) {
986 async = true;
987 traceStop = false;
988 traceDump = false;
989 g_traceOverwrite = true;
990 } else if (!strcmp(long_options[option_index].name, "async_stop")) {
991 async = true;
John Reck4ba2b632015-05-15 10:00:34 -0700992 traceStart = false;
Jamie Gennis6eea6fb2012-12-07 14:03:07 -0800993 } else if (!strcmp(long_options[option_index].name, "async_dump")) {
994 async = true;
995 traceStart = false;
996 traceStop = false;
Martijn Coenend9535872015-11-26 10:00:55 +0100997 } else if (!strcmp(long_options[option_index].name, "stream")) {
998 traceStream = true;
999 traceDump = false;
Jamie Gennis6eea6fb2012-12-07 14:03:07 -08001000 } else if (!strcmp(long_options[option_index].name, "list_categories")) {
1001 listSupportedCategories();
1002 exit(0);
1003 }
Jamie Gennis6f6f3f72013-03-27 15:50:30 -07001004 break;
Jamie Gennis6eea6fb2012-12-07 14:03:07 -08001005
1006 default:
1007 fprintf(stderr, "\n");
1008 showHelp(argv[0]);
1009 exit(-1);
1010 break;
1011 }
1012 }
1013
1014 registerSigHandler();
1015
1016 if (g_initialSleepSecs > 0) {
1017 sleep(g_initialSleepSecs);
1018 }
1019
Jamie Gennise9b8cfb2013-03-12 16:00:10 -07001020 bool ok = true;
1021 ok &= setUpTrace();
1022 ok &= startTrace();
Jamie Gennis6eea6fb2012-12-07 14:03:07 -08001023
1024 if (ok && traceStart) {
Martijn Coenend9535872015-11-26 10:00:55 +01001025 if (!traceStream) {
1026 printf("capturing trace...");
1027 fflush(stdout);
1028 }
Jamie Gennis6eea6fb2012-12-07 14:03:07 -08001029
1030 // We clear the trace after starting it because tracing gets enabled for
1031 // each CPU individually in the kernel. Having the beginning of the trace
1032 // contain entries from only one CPU can cause "begin" entries without a
1033 // matching "end" entry to show up if a task gets migrated from one CPU to
1034 // another.
1035 ok = clearTrace();
1036
Martijn Coenen0bcd97a2015-07-15 14:25:23 +02001037 writeClockSyncMarker();
Martijn Coenend9535872015-11-26 10:00:55 +01001038 if (ok && !async && !traceStream) {
Jamie Gennis6eea6fb2012-12-07 14:03:07 -08001039 // Sleep to allow the trace to be captured.
1040 struct timespec timeLeft;
1041 timeLeft.tv_sec = g_traceDurationSeconds;
1042 timeLeft.tv_nsec = 0;
1043 do {
1044 if (g_traceAborted) {
1045 break;
1046 }
1047 } while (nanosleep(&timeLeft, &timeLeft) == -1 && errno == EINTR);
1048 }
Martijn Coenend9535872015-11-26 10:00:55 +01001049
1050 if (traceStream) {
1051 streamTrace();
1052 }
Jamie Gennis6eea6fb2012-12-07 14:03:07 -08001053 }
1054
1055 // Stop the trace and restore the default settings.
1056 if (traceStop)
1057 stopTrace();
1058
1059 if (ok && traceDump) {
1060 if (!g_traceAborted) {
1061 printf(" done\nTRACE:\n");
1062 fflush(stdout);
1063 dumpTrace();
1064 } else {
1065 printf("\ntrace aborted.\n");
1066 fflush(stdout);
1067 }
1068 clearTrace();
1069 } else if (!ok) {
1070 fprintf(stderr, "unable to start tracing\n");
1071 }
1072
1073 // Reset the trace buffer size to 1.
1074 if (traceStop)
Jamie Gennise9b8cfb2013-03-12 16:00:10 -07001075 cleanUpTrace();
Jamie Gennis6eea6fb2012-12-07 14:03:07 -08001076
1077 return g_traceAborted ? 1 : 0;
1078}