|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* vim:set ts=2 sw=2 sts=2 et cindent: */ |
|
3 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
4 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 |
|
7 #ifndef GECKO_TASK_TRACER_H |
|
8 #define GECKO_TASK_TRACER_H |
|
9 |
|
10 #include "nsCOMPtr.h" |
|
11 |
|
12 /** |
|
13 * TaskTracer provides a way to trace the correlation between different tasks |
|
14 * across threads and processes. Unlike sampling based profilers, TaskTracer can |
|
15 * tell you where a task is dispatched from, what its original source was, how |
|
16 * long it waited in the event queue, and how long it took to execute. |
|
17 * |
|
18 * Source Events are usually some kinds of I/O events we're interested in, such |
|
19 * as touch events, timer events, network events, etc. When a source event is |
|
20 * created, TaskTracer records the entire chain of Tasks and nsRunnables as they |
|
21 * are dispatched to different threads and processes. It records latency, |
|
22 * execution time, etc. for each Task and nsRunnable that chains back to the |
|
23 * original source event. |
|
24 */ |
|
25 |
|
26 class Task; |
|
27 class nsIRunnable; |
|
28 |
|
29 namespace mozilla { |
|
30 namespace tasktracer { |
|
31 |
|
32 class FakeTracedTask; |
|
33 |
|
34 enum SourceEventType { |
|
35 UNKNOWN = 0, |
|
36 TOUCH, |
|
37 MOUSE, |
|
38 KEY, |
|
39 BLUETOOTH, |
|
40 UNIXSOCKET, |
|
41 WIFI |
|
42 }; |
|
43 |
|
44 class AutoSourceEvent |
|
45 { |
|
46 public: |
|
47 AutoSourceEvent(SourceEventType aType); |
|
48 ~AutoSourceEvent(); |
|
49 }; |
|
50 |
|
51 // Add a label to the currently running task, aFormat is the message to log, |
|
52 // followed by corresponding parameters. |
|
53 void AddLabel(const char* aFormat, ...); |
|
54 |
|
55 /** |
|
56 * Internal functions. |
|
57 */ |
|
58 |
|
59 Task* CreateTracedTask(Task* aTask); |
|
60 |
|
61 already_AddRefed<nsIRunnable> CreateTracedRunnable(nsIRunnable* aRunnable); |
|
62 |
|
63 FakeTracedTask* CreateFakeTracedTask(int* aVptr); |
|
64 |
|
65 // Free the TraceInfo allocated on a thread's TLS. Currently we are wrapping |
|
66 // tasks running on nsThreads and base::thread, so FreeTraceInfo is called at |
|
67 // where nsThread and base::thread release themselves. |
|
68 void FreeTraceInfo(); |
|
69 |
|
70 } // namespace tasktracer |
|
71 } // namespace mozilla. |
|
72 |
|
73 #endif |