AutoTimelineMarker.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #include "AutoTimelineMarker.h"
  6. #include "TimelineConsumers.h"
  7. #include "MainThreadUtils.h"
  8. namespace mozilla {
  9. AutoTimelineMarker::AutoTimelineMarker(nsIDocShell* aDocShell, const char* aName
  10. MOZ_GUARD_OBJECT_NOTIFIER_PARAM_IN_IMPL)
  11. : mName(aName)
  12. , mDocShell(nullptr)
  13. {
  14. MOZ_GUARD_OBJECT_NOTIFIER_INIT;
  15. MOZ_ASSERT(NS_IsMainThread());
  16. if (!aDocShell) {
  17. return;
  18. }
  19. RefPtr<TimelineConsumers> timelines = TimelineConsumers::Get();
  20. if (!timelines || !timelines->HasConsumer(aDocShell)) {
  21. return;
  22. }
  23. mDocShell = aDocShell;
  24. timelines->AddMarkerForDocShell(mDocShell, mName, MarkerTracingType::START);
  25. }
  26. AutoTimelineMarker::~AutoTimelineMarker()
  27. {
  28. MOZ_ASSERT(NS_IsMainThread());
  29. if (!mDocShell) {
  30. return;
  31. }
  32. RefPtr<TimelineConsumers> timelines = TimelineConsumers::Get();
  33. if (!timelines || !timelines->HasConsumer(mDocShell)) {
  34. return;
  35. }
  36. timelines->AddMarkerForDocShell(mDocShell, mName, MarkerTracingType::END);
  37. }
  38. } // namespace mozilla