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("AudioCallbackTracing");
16 static std::atomic
<int> gTracingStarted(0);
18 void StartAudioCallbackTracing() {
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() {
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 mLogger
.Log(aName
, aCategory
, aComment
, aPhase
);
43 void AutoTracer::PrintBudget(const char* aName
, const char* aCategory
,
44 uint64_t aDuration
, uint64_t aFrames
,
45 uint64_t aSampleRate
) {
46 mLogger
.LogDuration(aName
, aCategory
, aDuration
, aFrames
, aSampleRate
);
49 AutoTracer::AutoTracer(AsyncLogger
& aLogger
, const char* aLocation
,
50 EventType aEventType
, uint64_t aFrames
,
55 mEventType(aEventType
) {
56 MOZ_ASSERT(aEventType
== EventType::BUDGET
);
58 if (aLogger
.Enabled()) {
59 float durationUS
= (static_cast<float>(aFrames
) / aSampleRate
) * 1e6
;
60 PrintBudget(aLocation
, "perf", durationUS
, aFrames
, aSampleRate
);
64 AutoTracer::AutoTracer(AsyncLogger
& aLogger
, const char* aLocation
,
65 EventType aEventType
, const char* aComment
)
69 mEventType(aEventType
) {
70 MOZ_ASSERT(aEventType
== EventType::DURATION
);
71 if (aLogger
.Enabled()) {
72 PrintEvent(aLocation
, "perf", mComment
, AsyncLogger::TracingPhase::BEGIN
);
76 AutoTracer::~AutoTracer() {
77 if (mEventType
== EventType::DURATION
) {
78 if (mLogger
.Enabled()) {
79 PrintEvent(mLocation
, "perf", mComment
, AsyncLogger::TracingPhase::END
);