mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-29 15:52:07 +00:00
Bug 1646266 - Marker option: MarkerThreadId - r=gregtatum
This marker option captures a given thread id. If left unspecified (by default construction) during the add-marker call, the current thread id will be used then. Differential Revision: https://phabricator.services.mozilla.com/D87244
This commit is contained in:
parent
959178815b
commit
c2665d4e9d
@ -22,6 +22,11 @@
|
||||
# include <type_traits>
|
||||
# include <utility>
|
||||
|
||||
namespace mozilla::baseprofiler {
|
||||
// Implemented in platform.cpp
|
||||
MFBT_API int profiler_current_thread_id();
|
||||
} // namespace mozilla::baseprofiler
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
// Return a NotNull<const CHAR*> pointing at the literal empty string `""`.
|
||||
@ -250,6 +255,30 @@ MOZ_PROFILING_CATEGORY_LIST(CATEGORY_ENUM_BEGIN_CATEGORY,
|
||||
# undef CATEGORY_ENUM_END_CATEGORY
|
||||
} // namespace baseprofiler::category
|
||||
|
||||
// This marker option captures a given thread id.
|
||||
// If left unspecified (by default construction) during the add-marker call, the
|
||||
// current thread id will be used then.
|
||||
class MarkerThreadId {
|
||||
public:
|
||||
// Default constructor, keeps the thread id unspecified.
|
||||
constexpr MarkerThreadId() = default;
|
||||
|
||||
// Constructor from a given thread id.
|
||||
constexpr explicit MarkerThreadId(int aThreadId) : mThreadId(aThreadId) {}
|
||||
|
||||
// Use the current thread's id.
|
||||
static MarkerThreadId CurrentThread() {
|
||||
return MarkerThreadId(baseprofiler::profiler_current_thread_id());
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr int ThreadId() const { return mThreadId; }
|
||||
|
||||
[[nodiscard]] constexpr bool IsUnspecified() const { return mThreadId == 0; }
|
||||
|
||||
private:
|
||||
int mThreadId = 0;
|
||||
};
|
||||
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // MOZ_GECKO_PROFILER
|
||||
|
Loading…
Reference in New Issue
Block a user