michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim:set ts=2 sw=2 sts=2 et cindent: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef GECKO_TASK_TRACER_H michael@0: #define GECKO_TASK_TRACER_H michael@0: michael@0: #include "nsCOMPtr.h" michael@0: michael@0: /** michael@0: * TaskTracer provides a way to trace the correlation between different tasks michael@0: * across threads and processes. Unlike sampling based profilers, TaskTracer can michael@0: * tell you where a task is dispatched from, what its original source was, how michael@0: * long it waited in the event queue, and how long it took to execute. michael@0: * michael@0: * Source Events are usually some kinds of I/O events we're interested in, such michael@0: * as touch events, timer events, network events, etc. When a source event is michael@0: * created, TaskTracer records the entire chain of Tasks and nsRunnables as they michael@0: * are dispatched to different threads and processes. It records latency, michael@0: * execution time, etc. for each Task and nsRunnable that chains back to the michael@0: * original source event. michael@0: */ michael@0: michael@0: class Task; michael@0: class nsIRunnable; michael@0: michael@0: namespace mozilla { michael@0: namespace tasktracer { michael@0: michael@0: class FakeTracedTask; michael@0: michael@0: enum SourceEventType { michael@0: UNKNOWN = 0, michael@0: TOUCH, michael@0: MOUSE, michael@0: KEY, michael@0: BLUETOOTH, michael@0: UNIXSOCKET, michael@0: WIFI michael@0: }; michael@0: michael@0: class AutoSourceEvent michael@0: { michael@0: public: michael@0: AutoSourceEvent(SourceEventType aType); michael@0: ~AutoSourceEvent(); michael@0: }; michael@0: michael@0: // Add a label to the currently running task, aFormat is the message to log, michael@0: // followed by corresponding parameters. michael@0: void AddLabel(const char* aFormat, ...); michael@0: michael@0: /** michael@0: * Internal functions. michael@0: */ michael@0: michael@0: Task* CreateTracedTask(Task* aTask); michael@0: michael@0: already_AddRefed CreateTracedRunnable(nsIRunnable* aRunnable); michael@0: michael@0: FakeTracedTask* CreateFakeTracedTask(int* aVptr); michael@0: michael@0: // Free the TraceInfo allocated on a thread's TLS. Currently we are wrapping michael@0: // tasks running on nsThreads and base::thread, so FreeTraceInfo is called at michael@0: // where nsThread and base::thread release themselves. michael@0: void FreeTraceInfo(); michael@0: michael@0: } // namespace tasktracer michael@0: } // namespace mozilla. michael@0: michael@0: #endif