Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/docshell/base/timeline/TimelineMarker.cpp
Line
Count
Source (jump to first uncovered line)
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 "TimelineMarker.h"
8
9
namespace mozilla {
10
11
TimelineMarker::TimelineMarker(const char* aName,
12
                               MarkerTracingType aTracingType,
13
                               MarkerStackRequest aStackRequest)
14
  : AbstractTimelineMarker(aName, aTracingType)
15
0
{
16
0
  CaptureStackIfNecessary(aTracingType, aStackRequest);
17
0
}
18
19
TimelineMarker::TimelineMarker(const char* aName,
20
                               const TimeStamp& aTime,
21
                               MarkerTracingType aTracingType,
22
                               MarkerStackRequest aStackRequest)
23
  : AbstractTimelineMarker(aName, aTime, aTracingType)
24
0
{
25
0
  CaptureStackIfNecessary(aTracingType, aStackRequest);
26
0
}
27
28
void
29
TimelineMarker::AddDetails(JSContext* aCx, dom::ProfileTimelineMarker& aMarker)
30
0
{
31
0
  if (GetTracingType() == MarkerTracingType::START) {
32
0
    aMarker.mProcessType.Construct(GetProcessType());
33
0
    aMarker.mIsOffMainThread.Construct(IsOffMainThread());
34
0
  }
35
0
}
36
37
JSObject*
38
TimelineMarker::GetStack()
39
0
{
40
0
  if (mStackTrace.initialized()) {
41
0
    return mStackTrace;
42
0
  }
43
0
  return nullptr;
44
0
}
45
46
void
47
TimelineMarker::CaptureStack()
48
0
{
49
0
  JSContext* ctx = nsContentUtils::GetCurrentJSContext();
50
0
  if (ctx) {
51
0
    JS::RootedObject stack(ctx);
52
0
    if (JS::CaptureCurrentStack(ctx, &stack)) {
53
0
      mStackTrace.init(ctx, stack.get());
54
0
    } else {
55
0
      JS_ClearPendingException(ctx);
56
0
    }
57
0
  }
58
0
}
59
60
void
61
TimelineMarker::CaptureStackIfNecessary(MarkerTracingType aTracingType,
62
                                        MarkerStackRequest aStackRequest)
63
0
{
64
0
  if ((aTracingType == MarkerTracingType::START ||
65
0
      aTracingType == MarkerTracingType::TIMESTAMP) &&
66
0
      aStackRequest != MarkerStackRequest::NO_STACK) {
67
0
    CaptureStack();
68
0
  }
69
0
}
70
71
} // namespace mozilla