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
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef ProfilerThreadPlatformData_h
8 #define ProfilerThreadPlatformData_h
10 #include "mozilla/ProfilerUtils.h"
12 #if defined(__APPLE__)
13 # include <mach/mach_types.h>
14 #elif defined(__linux__) || defined(__ANDROID__) || defined(__FreeBSD__)
15 # include "mozilla/Maybe.h"
19 namespace mozilla::profiler
{
22 #if (defined(_MSC_VER) || defined(__MINGW32__)) && defined(MOZ_GECKO_PROFILER)
24 explicit PlatformData(ProfilerThreadId aThreadId
);
27 // Faking win32's HANDLE, because #including "windows.h" here causes trouble
28 // (e.g., it #defines `Yield` as nothing!)
29 // This type is static_check'ed against HANDLE in platform-win32.cpp.
30 using WindowsHandle
= void*;
31 WindowsHandle
ProfiledThread() const { return mProfiledThread
; }
34 WindowsHandle mProfiledThread
;
35 #elif defined(__APPLE__) && defined(MOZ_GECKO_PROFILER)
37 explicit PlatformData(ProfilerThreadId aThreadId
);
39 thread_act_t
ProfiledThread() const { return mProfiledThread
; }
42 // Note: for mProfiledThread Mach primitives are used instead of pthread's
43 // because the latter doesn't provide thread manipulation primitives
44 // required. For details, consult "Mac OS X Internals" book, Section 7.3.
45 thread_act_t mProfiledThread
;
46 #elif (defined(__linux__) || defined(__ANDROID__) || defined(__FreeBSD__)) && \
47 defined(MOZ_GECKO_PROFILER)
49 explicit PlatformData(ProfilerThreadId aThreadId
);
51 // Clock Id for this profiled thread. `Nothing` if `pthread_getcpuclockid`
52 // failed (e.g., if the system doesn't support per-thread clocks).
53 Maybe
<clockid_t
> GetClockId() const { return mClockId
; }
56 Maybe
<clockid_t
> mClockId
;
59 explicit PlatformData(ProfilerThreadId aThreadId
) {}
64 * Return the number of nanoseconds of CPU time used since thread start.
66 * @return true on success.
68 #if defined(MOZ_GECKO_PROFILER)
69 bool GetCpuTimeSinceThreadStartInNs(uint64_t* aResult
,
70 const PlatformData
& aPlatformData
);
72 static inline bool GetCpuTimeSinceThreadStartInNs(
73 uint64_t* aResult
, const PlatformData
& aPlatformData
) {
78 } // namespace mozilla::profiler
80 #endif // ProfilerThreadPlatformData_h