Bug 1079322 - Extract properties using libc functions. r=gwagner
[gecko.git] / tools / profiler / GeckoTaskTracerImpl.h
blobfc81d17ef956190c110d1448447f8322344d4483
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"
12 #include "nsTArray.h"
14 namespace mozilla {
15 namespace tasktracer {
17 typedef nsTArray<nsCString> TraceInfoLogsType;
19 struct TraceInfo
21 TraceInfo(uint32_t aThreadId, bool aStartLogging)
22 : mCurTraceSourceId(0)
23 , mCurTaskId(0)
24 , mSavedCurTraceSourceId(0)
25 , mSavedCurTaskId(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;
42 uint64_t mCurTaskId;
43 uint64_t mSavedCurTraceSourceId;
44 uint64_t mSavedCurTaskId;
45 SourceEventType mCurTraceSourceType;
46 SourceEventType mSavedCurTraceSourceType;
47 uint32_t mThreadId;
48 uint32_t mLastUniqueTaskId;
49 bool mStartLogging;
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
64 public:
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);
75 /**
76 * Logging functions of different trace actions.
78 enum ActionType {
79 ACTION_DISPATCH = 0,
80 ACTION_BEGIN,
81 ACTION_END,
82 ACTION_ADD_LABEL,
83 ACTION_GET_VTABLE
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
98 #endif