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