void TracedTaskCommon::ClearTLSTraceInfo() { TraceInfo* info = GetOrCreateTraceInfo(); ENSURE_TRUE_VOID(info); info->mCurTraceSourceId = 0; info->mCurTraceSourceType = SourceEventType::Unknown; info->mCurTaskId = 0; }
uint64_t GenNewUniqueTaskId() { TraceInfo* info = GetOrCreateTraceInfo(); ENSURE_TRUE(info, 0); pid_t tid = gettid(); uint64_t taskid = ((uint64_t)tid << 32) | ++info->mLastUniqueTaskId; return taskid; }
void TracedTaskCommon::GetTLSTraceInfo() { TraceInfo* info = GetOrCreateTraceInfo(); ENSURE_TRUE_VOID(info); mSourceEventType = info->mCurTraceSourceType; mSourceEventId = info->mCurTraceSourceId; mTaskId = info->mCurTaskId; mIsTraceInfoInit = true; }
void GetCurTraceInfo(uint64_t* aOutSourceEventId, uint64_t* aOutParentTaskId, SourceEventType* aOutSourceEventType) { TraceInfo* info = GetOrCreateTraceInfo(); ENSURE_TRUE_VOID(info); *aOutSourceEventId = info->mCurTraceSourceId; *aOutParentTaskId = info->mCurTaskId; *aOutSourceEventType = info->mCurTraceSourceType; }
void SetCurTraceInfo(uint64_t aSourceEventId, uint64_t aParentTaskId, SourceEventType aSourceEventType) { TraceInfo* info = GetOrCreateTraceInfo(); ENSURE_TRUE_VOID(info); info->mCurTraceSourceId = aSourceEventId; info->mCurTaskId = aParentTaskId; info->mCurTraceSourceType = aSourceEventType; }
void TracedTaskCommon::ClearTraceInfo() { TraceInfo* info = GetOrCreateTraceInfo(); if (!info) { return; } info->mCurTraceSourceId = 0; info->mCurTraceSourceType = SourceEventType::Unknown; info->mCurTaskId = 0; }
void TracedTaskCommon::SetTraceInfo() { TraceInfo* info = GetOrCreateTraceInfo(); if (!info) { return; } info->mCurTraceSourceId = mSourceEventId; info->mCurTraceSourceType = mSourceEventType; info->mCurTaskId = mTaskId; }
void TracedTaskCommon::Init() { TraceInfo* info = GetOrCreateTraceInfo(); NS_ENSURE_TRUE_VOID(info); mTaskId = GenNewUniqueTaskId(); mSourceEventId = info->mCurTraceSourceId; mSourceEventType = info->mCurTraceSourceType; LogDispatch(mTaskId, info->mCurTaskId, mSourceEventId, mSourceEventType); }
void TracedTaskCommon::DoGetTLSTraceInfo() { TraceInfoHolder info = GetOrCreateTraceInfo(); ENSURE_TRUE_VOID(info); MOZ_ASSERT(!mIsTraceInfoInit); mSourceEventType = info->mCurTraceSourceType; mSourceEventId = info->mCurTraceSourceId; mTaskId = info->mCurTaskId; mIsTraceInfoInit = true; }
void TracedTaskCommon::SetTLSTraceInfo() { TraceInfo* info = GetOrCreateTraceInfo(); ENSURE_TRUE_VOID(info); if (mIsTraceInfoInit) { info->mCurTraceSourceId = mSourceEventId; info->mCurTraceSourceType = mSourceEventType; info->mCurTaskId = mTaskId; } }
static void DestroySourceEvent() { // Log a fake end for this source event. TraceInfo* info = GetOrCreateTraceInfo(); ENSURE_TRUE_VOID(info); LogEnd(info->mCurTraceSourceId, info->mCurTraceSourceId); // Restore the previously saved source event info. RestoreCurTraceInfo(); }
void LogVirtualTablePtr(uint64_t aTaskId, uint64_t aSourceEventId, int* aVptr) { TraceInfo* info = GetOrCreateTraceInfo(); ENSURE_TRUE_VOID(info); // Log format: // [4 taskId address] nsCString* log = info->AppendLog(); if (log) { log->AppendPrintf("%d %lld %p", ACTION_GET_VTABLE, aTaskId, aVptr); } }
void LogEnd(uint64_t aTaskId, uint64_t aSourceEventId) { TraceInfo* info = GetOrCreateTraceInfo(); ENSURE_TRUE_VOID(info); // Log format: // [2 taskId endTime] nsCString* log = info->AppendLog(); if (log) { log->AppendPrintf("%d %lld %lld", ACTION_END, aTaskId, GetTimestamp()); } }
void LogBegin(uint64_t aTaskId, uint64_t aSourceEventId) { TraceInfo* info = GetOrCreateTraceInfo(); ENSURE_TRUE_VOID(info); // Log format: // [1 taskId beginTime processId threadId] nsCString* log = info->AppendLog(); if (log) { log->AppendPrintf("%d %lld %lld %d %d", ACTION_BEGIN, aTaskId, GetTimestamp(), getpid(), gettid()); } }
void TracedTaskCommon::Init() { // Keep the following line before GetOrCreateTraceInfo() to avoid a // deadlock. uint64_t taskid = GenNewUniqueTaskId(); TraceInfoHolder info = GetOrCreateTraceInfo(); ENSURE_TRUE_VOID(info); mTaskId = taskid; mSourceEventId = info->mCurTraceSourceId; mSourceEventType = info->mCurTraceSourceType; mParentTaskId = info->mCurTaskId; mIsTraceInfoInit = true; }
void AddLabel(const char* aFormat, ...) { TraceInfo* info = GetOrCreateTraceInfo(); ENSURE_TRUE_VOID(info); va_list args; va_start(args, aFormat); nsAutoCString buffer; buffer.AppendPrintf(aFormat, args); va_end(args); // Log format: // [3 taskId "label"] nsCString* log = info->AppendLog(); if (log) { log->AppendPrintf("%d %lld %lld \"%s\"", ACTION_ADD_LABEL, info->mCurTaskId, GetTimestamp(), buffer.get()); } }
void LogDispatch(uint64_t aTaskId, uint64_t aParentTaskId, uint64_t aSourceEventId, SourceEventType aSourceEventType, int aDelayTimeMs) { TraceInfo* info = GetOrCreateTraceInfo(); ENSURE_TRUE_VOID(info); // aDelayTimeMs is the expected delay time in milliseconds, thus the dispatch // time calculated of it might be slightly off in the real world. uint64_t time = (aDelayTimeMs <= 0) ? GetTimestamp() : GetTimestamp() + aDelayTimeMs; // Log format: // [0 taskId dispatchTime sourceEventId sourceEventType parentTaskId] nsCString* log = info->AppendLog(); if (log) { log->AppendPrintf("%d %lld %lld %lld %d %lld", ACTION_DISPATCH, aTaskId, time, aSourceEventId, aSourceEventType, aParentTaskId); } }
static void CreateSourceEvent(SourceEventType aType) { // Save the currently traced source event info. SaveCurTraceInfo(); // Create a new unique task id. uint64_t newId = GenNewUniqueTaskId(); TraceInfo* info = GetOrCreateTraceInfo(); ENSURE_TRUE_VOID(info); info->mCurTraceSourceId = newId; info->mCurTraceSourceType = aType; info->mCurTaskId = newId; uintptr_t* namePtr; #define SOURCE_EVENT_NAME(type) \ case SourceEventType::type: \ { \ static int CreateSourceEvent##type; \ namePtr = (uintptr_t*)&CreateSourceEvent##type; \ break; \ } switch (aType) { #include "SourceEventTypeMap.h" default: MOZ_CRASH("Unknown SourceEvent."); } #undef CREATE_SOURCE_EVENT_NAME // Log a fake dispatch and start for this source event. LogDispatch(newId, newId, newId, aType); LogVirtualTablePtr(newId, newId, namePtr); LogBegin(newId, newId); }