|
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 TRACED_TASK_COMMON_H |
|
8 #define TRACED_TASK_COMMON_H |
|
9 |
|
10 #include "base/task.h" |
|
11 #include "GeckoTaskTracer.h" |
|
12 #include "nsCOMPtr.h" |
|
13 #include "nsThreadUtils.h" |
|
14 |
|
15 namespace mozilla { |
|
16 namespace tasktracer { |
|
17 |
|
18 class TracedTaskCommon |
|
19 { |
|
20 public: |
|
21 TracedTaskCommon(); |
|
22 virtual ~TracedTaskCommon() {} |
|
23 |
|
24 protected: |
|
25 void Init(); |
|
26 |
|
27 // Sets up the metadata on the current thread's TraceInfo for this task. |
|
28 // After Run(), ClearTraceInfo is called to reset the metadata. |
|
29 void SetTraceInfo(); |
|
30 void ClearTraceInfo(); |
|
31 |
|
32 // Its own task Id, an unique number base on its thread Id and a last unique |
|
33 // task Id stored in its TraceInfo. |
|
34 uint64_t mTaskId; |
|
35 |
|
36 uint64_t mSourceEventId; |
|
37 SourceEventType mSourceEventType; |
|
38 }; |
|
39 |
|
40 class TracedRunnable : public TracedTaskCommon |
|
41 , public nsRunnable |
|
42 { |
|
43 public: |
|
44 NS_DECL_NSIRUNNABLE |
|
45 |
|
46 TracedRunnable(nsIRunnable* aOriginalObj); |
|
47 |
|
48 private: |
|
49 virtual ~TracedRunnable() {} |
|
50 |
|
51 nsCOMPtr<nsIRunnable> mOriginalObj; |
|
52 }; |
|
53 |
|
54 class TracedTask : public TracedTaskCommon |
|
55 , public Task |
|
56 { |
|
57 public: |
|
58 TracedTask(Task* aOriginalObj); |
|
59 ~TracedTask() |
|
60 { |
|
61 if (mOriginalObj) { |
|
62 delete mOriginalObj; |
|
63 mOriginalObj = nullptr; |
|
64 } |
|
65 } |
|
66 |
|
67 virtual void Run(); |
|
68 |
|
69 private: |
|
70 Task* mOriginalObj; |
|
71 }; |
|
72 |
|
73 // FakeTracedTask is for tracking events that are not directly dispatched from |
|
74 // their parents, e.g. The timer events. |
|
75 class FakeTracedTask : public TracedTaskCommon |
|
76 { |
|
77 public: |
|
78 FakeTracedTask() : TracedTaskCommon() {} |
|
79 FakeTracedTask(int* aVptr); |
|
80 FakeTracedTask(const FakeTracedTask& aTask); |
|
81 void BeginFakeTracedTask(); |
|
82 void EndFakeTracedTask(); |
|
83 }; |
|
84 |
|
85 class AutoRunFakeTracedTask |
|
86 { |
|
87 public: |
|
88 AutoRunFakeTracedTask(FakeTracedTask* aFakeTracedTask); |
|
89 ~AutoRunFakeTracedTask(); |
|
90 private: |
|
91 FakeTracedTask mFakeTracedTask; |
|
92 bool mInitialized; |
|
93 }; |
|
94 |
|
95 } // namespace tasktracer |
|
96 } // namespace mozilla |
|
97 |
|
98 #endif |