Skip to content

Commit

Permalink
Add a header to be able to use a frame profiler in cubeb
Browse files Browse the repository at this point in the history
The purpose of this header is to be swapped by cubeb users to use any
number of frame profiler (tracy/Gecko Profiler/trace_event.h, etc.).
  • Loading branch information
padenot committed Jul 21, 2022
1 parent 190652b commit 015f3c6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/cubeb_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "cubeb_log.h"
#include "cubeb_ringbuffer.h"
#include "cubeb_tracing.h"
#include <cstdarg>
#ifdef _WIN32
#include <windows.h>
Expand Down Expand Up @@ -69,6 +70,7 @@ class cubeb_async_logger {
void run()
{
std::thread([this]() {
CUBEB_REGISTER_THREAD("cubeb_log");
while (true) {
cubeb_log_message msg;
while (msg_queue.dequeue(&msg, 1)) {
Expand All @@ -87,6 +89,7 @@ class cubeb_async_logger {
} while (remainder.tv_sec || remainder.tv_nsec);
#endif
}
CUBEB_UNREGISTER_THREAD();
}).detach();
}
// Tell the underlying queue the producer thread has changed, so it does not
Expand Down
23 changes: 23 additions & 0 deletions src/cubeb_tracing.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright © 2022 Mozilla Foundation
*
* This program is made available under an ISC-style license. See the
* accompanying file LICENSE for details.
*/

#ifndef CUBEB_TRACING_H
#define CUBEB_TRACING_H

/* Empty header to allow hooking up a frame profiler. */

// To be called once on a thread to register for tracing.
#define CUBEB_REGISTER_THREAD(name)
// To be called once before a registered threads exits.
#define CUBEB_UNREGISTER_THREAD()
// Insert a tracing marker, with a particular name.
// Phase can be 'x': instant marker, start time but no duration
// 'b': beginning of a marker with a duration
// 'e': end of a marker with a duration
#define CUBEB_TRACE(name, phase)

#endif // CUBEB_TRACING_H

0 comments on commit 015f3c6

Please sign in to comment.