Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/media/Tracing.cpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 2; 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 file,
5
 * You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#include "Tracing.h"
8
9
#include <inttypes.h>
10
11
#include "mozilla/TimeStamp.h"
12
13
using namespace mozilla;
14
15
uint64_t
16
AutoTracer::NowInUs()
17
0
{
18
0
  static TimeStamp base = TimeStamp::Now();
19
0
  return (TimeStamp::Now() - base).ToMicroseconds();
20
0
}
21
22
void
23
AutoTracer::PrintEvent(const char* aName,
24
                       const char* aCategory,
25
                       const char* aComment,
26
                       TracingPhase aPhase,
27
                       uint64_t aTime,
28
                       uint64_t aPID,
29
                       uint64_t aThread)
30
0
{
31
0
  mLogger.Log("{\"name\": \"%s\", \"cat\": \"%s\", \"ph\": \"%c\","
32
0
              "\"ts\": %" PRIu64 ", \"pid\": %" PRIu64 ", \"tid\":"
33
0
              " %" PRIu64 ", \"args\": { \"comment\": \"%s\"}},",
34
0
           aName, aCategory, TRACING_PHASE_STRINGS[static_cast<int>(aPhase)],
35
0
           aTime, aPID, aThread, aComment);
36
0
}
37
38
void
39
AutoTracer::PrintBudget(const char* aName,
40
                        const char* aCategory,
41
                        uint64_t aDuration,
42
                        uint64_t aPID,
43
                        uint64_t aThread,
44
                        uint64_t aFrames,
45
                        uint64_t aSampleRate)
46
0
{
47
0
  mLogger.Log("{\"name\": \"%s\", \"cat\": \"%s\", \"ph\": \"X\","
48
0
              "\"ts\": %" PRIu64 ", \"dur\": %" PRIu64 ", \"pid\": %" PRIu64 ","
49
0
              "\"tid\": %" PRIu64 ", \"args\": { \"comment\": \"%" PRIu64 "/%" PRIu64 "\"}},",
50
0
              aName, aCategory, NowInUs(), aDuration, aPID, aThread, aFrames, aSampleRate);
51
0
}
52
53
AutoTracer::AutoTracer(AsyncLogger& aLogger,
54
                       const char* aLocation,
55
                       uint64_t aPID,
56
                       uint64_t aTID,
57
                       EventType aEventType,
58
                       uint64_t aFrames,
59
                       uint64_t aSampleRate)
60
  : mLogger(aLogger)
61
  , mLocation(aLocation)
62
  , mComment(nullptr)
63
  , mEventType(aEventType)
64
  , mPID(aPID)
65
  , mTID(aTID)
66
0
{
67
0
  MOZ_ASSERT(aEventType == EventType::BUDGET);
68
0
69
0
  if (aLogger.Enabled()) {
70
0
    float durationUS = (static_cast<float>(aFrames) / aSampleRate) * 1e6;
71
0
    PrintBudget(aLocation, "perf", durationUS, mPID, mTID, aFrames, aSampleRate);
72
0
  }
73
0
}
74
75
AutoTracer::AutoTracer(AsyncLogger& aLogger,
76
                       const char* aLocation,
77
                       uint64_t aPID,
78
                       uint64_t aTID,
79
                       EventType aEventType,
80
                       const char* aComment)
81
  : mLogger(aLogger)
82
  , mLocation(aLocation)
83
  , mComment(aComment)
84
  , mEventType(aEventType)
85
  , mPID(aPID)
86
  , mTID(aTID)
87
0
{
88
0
  MOZ_ASSERT(aEventType == EventType::DURATION);
89
0
  if (aLogger.Enabled()) {
90
0
    PrintEvent(aLocation, "perf", mComment, TracingPhase::BEGIN, NowInUs(), aPID, aTID);
91
0
  }
92
0
}
93
94
AutoTracer::~AutoTracer()
95
0
{
96
0
  if (mEventType == EventType::DURATION) {
97
0
    if (mLogger.Enabled()) {
98
0
      PrintEvent(mLocation, "perf", mComment, TracingPhase::END, NowInUs(), mPID, mTID);
99
0
    }
100
0
  }
101
0
}