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/. */
7 #ifndef GECKO_TASK_TRACER_IMPL_H
8 #define GECKO_TASK_TRACER_IMPL_H
10 #include "GeckoTaskTracer.h"
11 #include "mozilla/Mutex.h"
15 namespace tasktracer
{
17 typedef nsTArray
<nsCString
> TraceInfoLogsType
;
21 TraceInfo(uint32_t aThreadId
, bool aStartLogging
)
22 : mCurTraceSourceId(0)
24 , mSavedCurTraceSourceId(0)
26 , mCurTraceSourceType(UNKNOWN
)
27 , mSavedCurTraceSourceType(UNKNOWN
)
28 , mThreadId(aThreadId
)
29 , mLastUniqueTaskId(0)
30 , mStartLogging(aStartLogging
)
31 , mLogsMutex("TraceInfoMutex")
33 MOZ_COUNT_CTOR(TraceInfo
);
36 ~TraceInfo() { MOZ_COUNT_DTOR(TraceInfo
); }
38 nsCString
* AppendLog();
39 void MoveLogsInto(TraceInfoLogsType
& aResult
);
41 uint64_t mCurTraceSourceId
;
43 uint64_t mSavedCurTraceSourceId
;
44 uint64_t mSavedCurTaskId
;
45 SourceEventType mCurTraceSourceType
;
46 SourceEventType mSavedCurTraceSourceType
;
48 uint32_t mLastUniqueTaskId
;
51 // This mutex protects the following log array because MoveLogsInto() might
52 // be called on another thread.
53 mozilla::Mutex mLogsMutex
;
54 TraceInfoLogsType mLogs
;
57 // Return the TraceInfo of current thread, allocate a new one if not exit.
58 TraceInfo
* GetOrCreateTraceInfo();
60 uint64_t GenNewUniqueTaskId();
62 class AutoSaveCurTraceInfo
65 AutoSaveCurTraceInfo();
66 ~AutoSaveCurTraceInfo();
69 void SetCurTraceInfo(uint64_t aSourceEventId
, uint64_t aParentTaskId
,
70 SourceEventType aSourceEventType
);
72 void GetCurTraceInfo(uint64_t* aOutSourceEventId
, uint64_t* aOutParentTaskId
,
73 SourceEventType
* aOutSourceEventType
);
76 * Logging functions of different trace actions.
86 void LogDispatch(uint64_t aTaskId
, uint64_t aParentTaskId
,
87 uint64_t aSourceEventId
, SourceEventType aSourceEventType
);
89 void LogBegin(uint64_t aTaskId
, uint64_t aSourceEventId
);
91 void LogEnd(uint64_t aTaskId
, uint64_t aSourceEventId
);
93 void LogVirtualTablePtr(uint64_t aTaskId
, uint64_t aSourceEventId
, int* aVptr
);
95 } // namespace mozilla
96 } // namespace tasktracer