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