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/. */
11 using namespace mozilla
;
13 using TracingPhase
= mozilla::AsyncLogger::TracingPhase
;
15 mozilla::AsyncLogger gAudioCallbackTraceLogger
;
16 static std::atomic
<int> gTracingStarted(0);
18 void StartAudioCallbackTracing() {
19 #ifdef MOZ_REAL_TIME_TRACING
20 int cnt
= gTracingStarted
.fetch_add(1, std::memory_order_seq_cst
);
22 // This is a noop if the logger has not been enabled.
23 gAudioCallbackTraceLogger
.Start();
28 void StopAudioCallbackTracing() {
29 #ifdef MOZ_REAL_TIME_TRACING
30 int cnt
= gTracingStarted
.fetch_sub(1, std::memory_order_seq_cst
);
32 // This is a noop if the logger has not been enabled.
33 gAudioCallbackTraceLogger
.Stop();
38 void AutoTracer::PrintEvent(const char* aName
, const char* aCategory
,
39 const char* aComment
, TracingPhase aPhase
) {
40 #ifdef MOZ_REAL_TIME_TRACING
41 mLogger
.Log(aName
, aCategory
, aComment
, aPhase
);
45 void AutoTracer::PrintBudget(const char* aName
, const char* aCategory
,
46 uint64_t aDuration
, uint64_t aFrames
,
47 uint64_t aSampleRate
) {
48 #ifdef MOZ_REAL_TIME_TRACING
49 mLogger
.LogDuration(aName
, aCategory
, aDuration
, aFrames
, aSampleRate
);
53 AutoTracer::AutoTracer(AsyncLogger
& aLogger
, const char* aLocation
,
54 EventType aEventType
, uint64_t aFrames
,
59 mEventType(aEventType
) {
60 MOZ_ASSERT(aEventType
== EventType::BUDGET
);
62 if (aLogger
.Enabled()) {
63 float durationUS
= (static_cast<float>(aFrames
) / aSampleRate
) * 1e6
;
64 PrintBudget(aLocation
, "perf", durationUS
, aFrames
, aSampleRate
);
68 AutoTracer::AutoTracer(AsyncLogger
& aLogger
, const char* aLocation
,
69 EventType aEventType
, const char* aComment
)
73 mEventType(aEventType
) {
74 MOZ_ASSERT(aEventType
== EventType::DURATION
);
75 if (aLogger
.Enabled()) {
76 PrintEvent(aLocation
, "perf", mComment
, AsyncLogger::TracingPhase::BEGIN
);
80 AutoTracer::~AutoTracer() {
81 if (mEventType
== EventType::DURATION
) {
82 if (mLogger
.Enabled()) {
83 PrintEvent(mLocation
, "perf", mComment
, AsyncLogger::TracingPhase::END
);