tools/profiler/TracedTaskCommon.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/tools/profiler/TracedTaskCommon.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,98 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim:set ts=2 sw=2 sts=2 et cindent: */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#ifndef TRACED_TASK_COMMON_H
    1.11 +#define TRACED_TASK_COMMON_H
    1.12 +
    1.13 +#include "base/task.h"
    1.14 +#include "GeckoTaskTracer.h"
    1.15 +#include "nsCOMPtr.h"
    1.16 +#include "nsThreadUtils.h"
    1.17 +
    1.18 +namespace mozilla {
    1.19 +namespace tasktracer {
    1.20 +
    1.21 +class TracedTaskCommon
    1.22 +{
    1.23 +public:
    1.24 +  TracedTaskCommon();
    1.25 +  virtual ~TracedTaskCommon() {}
    1.26 +
    1.27 +protected:
    1.28 +  void Init();
    1.29 +
    1.30 +  // Sets up the metadata on the current thread's TraceInfo for this task.
    1.31 +  // After Run(), ClearTraceInfo is called to reset the metadata.
    1.32 +  void SetTraceInfo();
    1.33 +  void ClearTraceInfo();
    1.34 +
    1.35 +  // Its own task Id, an unique number base on its thread Id and a last unique
    1.36 +  // task Id stored in its TraceInfo.
    1.37 +  uint64_t mTaskId;
    1.38 +
    1.39 +  uint64_t mSourceEventId;
    1.40 +  SourceEventType mSourceEventType;
    1.41 +};
    1.42 +
    1.43 +class TracedRunnable : public TracedTaskCommon
    1.44 +                     , public nsRunnable
    1.45 +{
    1.46 +public:
    1.47 +  NS_DECL_NSIRUNNABLE
    1.48 +
    1.49 +  TracedRunnable(nsIRunnable* aOriginalObj);
    1.50 +
    1.51 +private:
    1.52 +  virtual ~TracedRunnable() {}
    1.53 +
    1.54 +  nsCOMPtr<nsIRunnable> mOriginalObj;
    1.55 +};
    1.56 +
    1.57 +class TracedTask : public TracedTaskCommon
    1.58 +                 , public Task
    1.59 +{
    1.60 +public:
    1.61 +  TracedTask(Task* aOriginalObj);
    1.62 +  ~TracedTask()
    1.63 +  {
    1.64 +    if (mOriginalObj) {
    1.65 +      delete mOriginalObj;
    1.66 +      mOriginalObj = nullptr;
    1.67 +    }
    1.68 +  }
    1.69 +
    1.70 +  virtual void Run();
    1.71 +
    1.72 +private:
    1.73 +  Task* mOriginalObj;
    1.74 +};
    1.75 +
    1.76 +// FakeTracedTask is for tracking events that are not directly dispatched from
    1.77 +// their parents, e.g. The timer events.
    1.78 +class FakeTracedTask : public TracedTaskCommon
    1.79 +{
    1.80 +public:
    1.81 +  FakeTracedTask() : TracedTaskCommon() {}
    1.82 +  FakeTracedTask(int* aVptr);
    1.83 +  FakeTracedTask(const FakeTracedTask& aTask);
    1.84 +  void BeginFakeTracedTask();
    1.85 +  void EndFakeTracedTask();
    1.86 +};
    1.87 +
    1.88 +class AutoRunFakeTracedTask
    1.89 +{
    1.90 +public:
    1.91 +  AutoRunFakeTracedTask(FakeTracedTask* aFakeTracedTask);
    1.92 +  ~AutoRunFakeTracedTask();
    1.93 +private:
    1.94 +  FakeTracedTask mFakeTracedTask;
    1.95 +  bool mInitialized;
    1.96 +};
    1.97 +
    1.98 +} // namespace tasktracer
    1.99 +} // namespace mozilla
   1.100 +
   1.101 +#endif

mercurial