Index: Source/platform/scheduler/Scheduler.cpp |
diff --git a/Source/platform/scheduler/Scheduler.cpp b/Source/platform/scheduler/Scheduler.cpp |
index fb331ac6e3766aad23db042059ad0c43b549bb18..2805aa4b37953a315b14d422c637f33ae9a0beeb 100644 |
--- a/Source/platform/scheduler/Scheduler.cpp |
+++ b/Source/platform/scheduler/Scheduler.cpp |
@@ -73,8 +73,8 @@ public: |
class Scheduler::MainThreadPendingTaskRunner : public WebThread::Task { |
public: |
MainThreadPendingTaskRunner( |
- const Scheduler::Task& task, const TraceLocation& location) |
- : m_task(task, location) |
+ const Scheduler::Task& task, const TraceLocation& location, const char * name, int flowTraceID) |
Sami
2014/08/29 14:50:25
No space before "*".
picksi1
2014/09/01 11:06:51
Done.
|
+ : m_task(task, location, name, flowTraceID) |
{ |
ASSERT(Scheduler::shared()); |
} |
@@ -90,7 +90,7 @@ public: |
m_task.run(); |
} |
- Scheduler::TracedTask m_task; |
+ TracedTask m_task; |
}; |
Scheduler* Scheduler::s_sharedScheduler = nullptr; |
@@ -117,6 +117,12 @@ Scheduler::Scheduler() |
, m_highPriorityTaskCount(0) |
, m_highPriorityTaskRunnerPosted(false) |
{ |
+ // Start trace ID off as 'this' to keep multiple instances of the scheduler |
+ // having different(-ish) unique flow tracing IDs. Keep compiler happy |
+ // by casting to a pointer and then to an integer. |
+ intptr_t thisAsPointer = reinterpret_cast<intptr_t>(this); |
Sami
2014/08/29 14:50:25
Maybe it's just me, but I think this is a little v
picksi1
2014/09/01 11:06:51
Done.
|
+ int thisAsInteger = static_cast<int>(thisAsPointer); |
+ m_nextFlowTraceID = thisAsInteger; |
} |
Scheduler::~Scheduler() |
@@ -126,31 +132,40 @@ Scheduler::~Scheduler() |
} |
} |
+int Scheduler::generateFlowTraceID() |
+{ |
+ return atomicIncrement(&m_nextFlowTraceID); |
+} |
+ |
void Scheduler::scheduleIdleTask(const TraceLocation& location, const IdleTask& idleTask) |
{ |
// TODO: send a real allottedTime here. |
m_mainThread->postTask(new MainThreadIdleTaskAdapter(idleTask, 0, location)); |
} |
+void Scheduler::postAsHighPriorityTask(const TraceLocation& location, const Task& task, const char * traceName) |
Sami
2014/08/29 14:50:25
nit: postHighPriorityTask to match the wording of
picksi1
2014/09/01 11:06:51
I'd named this differently on purpose as it is an
|
+{ |
+ Locker<Mutex> lock(m_pendingTasksMutex); |
+ |
+ TracedTask tracedTask = TracedTask(task, location, traceName, generateFlowTraceID()); |
+ m_pendingHighPriorityTasks.append(tracedTask); |
+ atomicIncrement(&m_highPriorityTaskCount); |
+ maybePostMainThreadPendingHighPriorityTaskRunner(); |
+} |
+ |
void Scheduler::postTask(const TraceLocation& location, const Task& task) |
{ |
- m_mainThread->postTask(new MainThreadPendingTaskRunner(task, location)); |
+ m_mainThread->postTask(new MainThreadPendingTaskRunner(task, location, "Scheduler::MainThreadTask", generateFlowTraceID())); |
} |
void Scheduler::postInputTask(const TraceLocation& location, const Task& task) |
{ |
- Locker<Mutex> lock(m_pendingTasksMutex); |
- m_pendingHighPriorityTasks.append(TracedTask(task, location)); |
- atomicIncrement(&m_highPriorityTaskCount); |
- maybePostMainThreadPendingHighPriorityTaskRunner(); |
+ postAsHighPriorityTask(location, task, "Scheduler::InputTask"); |
} |
void Scheduler::postCompositorTask(const TraceLocation& location, const Task& task) |
{ |
- Locker<Mutex> lock(m_pendingTasksMutex); |
- m_pendingHighPriorityTasks.append(TracedTask(task, location)); |
- atomicIncrement(&m_highPriorityTaskCount); |
- maybePostMainThreadPendingHighPriorityTaskRunner(); |
+ postAsHighPriorityTask(location, task, "Scheduler::CompositorTask"); |
} |
void Scheduler::maybePostMainThreadPendingHighPriorityTaskRunner() |
@@ -256,12 +271,4 @@ bool Scheduler::hasPendingHighPriorityWork() const |
return acquireLoad(&m_highPriorityTaskCount) != 0; |
} |
-void Scheduler::TracedTask::run() |
-{ |
- TRACE_EVENT2("blink", "TracedTask::run", |
- "src_file", m_location.fileName(), |
- "src_func", m_location.functionName()); |
- m_task(); |
-} |
- |
} // namespace blink |