Bug 1708422: part 16) Rename `mozInlineSpellChecker::SpellCheckerTimeSlice` to `mozIn...
[gecko.git] / dom / media / Tracing.cpp
blob4250f132bbbb9abc25995e2e9cde6d8a37c45b36
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/. */
7 #include "Tracing.h"
9 #include <inttypes.h>
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() {
19 #ifdef TRACING
20 int cnt = gTracingStarted.fetch_add(1, std::memory_order_seq_cst);
21 if (cnt == 0) {
22 // This is a noop if the logger has not been enabled.
23 gAudioCallbackTraceLogger.Start();
25 #endif
28 void StopAudioCallbackTracing() {
29 #ifdef TRACING
30 int cnt = gTracingStarted.fetch_sub(1, std::memory_order_seq_cst);
31 if (cnt == 1) {
32 // This is a noop if the logger has not been enabled.
33 gAudioCallbackTraceLogger.Stop();
35 #endif
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,
51 uint64_t aSampleRate)
52 : mLogger(aLogger),
53 mLocation(aLocation),
54 mComment(nullptr),
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)
66 : mLogger(aLogger),
67 mLocation(aLocation),
68 mComment(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);