tools/profiler/TracedTaskCommon.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #ifndef TRACED_TASK_COMMON_H
michael@0 8 #define TRACED_TASK_COMMON_H
michael@0 9
michael@0 10 #include "base/task.h"
michael@0 11 #include "GeckoTaskTracer.h"
michael@0 12 #include "nsCOMPtr.h"
michael@0 13 #include "nsThreadUtils.h"
michael@0 14
michael@0 15 namespace mozilla {
michael@0 16 namespace tasktracer {
michael@0 17
michael@0 18 class TracedTaskCommon
michael@0 19 {
michael@0 20 public:
michael@0 21 TracedTaskCommon();
michael@0 22 virtual ~TracedTaskCommon() {}
michael@0 23
michael@0 24 protected:
michael@0 25 void Init();
michael@0 26
michael@0 27 // Sets up the metadata on the current thread's TraceInfo for this task.
michael@0 28 // After Run(), ClearTraceInfo is called to reset the metadata.
michael@0 29 void SetTraceInfo();
michael@0 30 void ClearTraceInfo();
michael@0 31
michael@0 32 // Its own task Id, an unique number base on its thread Id and a last unique
michael@0 33 // task Id stored in its TraceInfo.
michael@0 34 uint64_t mTaskId;
michael@0 35
michael@0 36 uint64_t mSourceEventId;
michael@0 37 SourceEventType mSourceEventType;
michael@0 38 };
michael@0 39
michael@0 40 class TracedRunnable : public TracedTaskCommon
michael@0 41 , public nsRunnable
michael@0 42 {
michael@0 43 public:
michael@0 44 NS_DECL_NSIRUNNABLE
michael@0 45
michael@0 46 TracedRunnable(nsIRunnable* aOriginalObj);
michael@0 47
michael@0 48 private:
michael@0 49 virtual ~TracedRunnable() {}
michael@0 50
michael@0 51 nsCOMPtr<nsIRunnable> mOriginalObj;
michael@0 52 };
michael@0 53
michael@0 54 class TracedTask : public TracedTaskCommon
michael@0 55 , public Task
michael@0 56 {
michael@0 57 public:
michael@0 58 TracedTask(Task* aOriginalObj);
michael@0 59 ~TracedTask()
michael@0 60 {
michael@0 61 if (mOriginalObj) {
michael@0 62 delete mOriginalObj;
michael@0 63 mOriginalObj = nullptr;
michael@0 64 }
michael@0 65 }
michael@0 66
michael@0 67 virtual void Run();
michael@0 68
michael@0 69 private:
michael@0 70 Task* mOriginalObj;
michael@0 71 };
michael@0 72
michael@0 73 // FakeTracedTask is for tracking events that are not directly dispatched from
michael@0 74 // their parents, e.g. The timer events.
michael@0 75 class FakeTracedTask : public TracedTaskCommon
michael@0 76 {
michael@0 77 public:
michael@0 78 FakeTracedTask() : TracedTaskCommon() {}
michael@0 79 FakeTracedTask(int* aVptr);
michael@0 80 FakeTracedTask(const FakeTracedTask& aTask);
michael@0 81 void BeginFakeTracedTask();
michael@0 82 void EndFakeTracedTask();
michael@0 83 };
michael@0 84
michael@0 85 class AutoRunFakeTracedTask
michael@0 86 {
michael@0 87 public:
michael@0 88 AutoRunFakeTracedTask(FakeTracedTask* aFakeTracedTask);
michael@0 89 ~AutoRunFakeTracedTask();
michael@0 90 private:
michael@0 91 FakeTracedTask mFakeTracedTask;
michael@0 92 bool mInitialized;
michael@0 93 };
michael@0 94
michael@0 95 } // namespace tasktracer
michael@0 96 } // namespace mozilla
michael@0 97
michael@0 98 #endif

mercurial