Encapsulate process id and thread id in distinct types
Categories
(Core :: Gecko Profiler, task, P2)
Tracking
()
Tracking | Status | |
---|---|---|
firefox92 | --- | fixed |
People
(Reporter: mozbugz, Assigned: mozbugz)
References
Details
Attachments
(7 files)
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details |
Process and thread ids, as reported by profiler_current_process_id()
and profiler_current_thread_id()
, are currently stored in simple int
s, which are 32 bits on all our supported platforms.
Instead they should be encapsulated in more opaque types. Some advantages:
- Prevent type mismatches, e.g., giving a process id (or other number) to a function expecting a thread id.
- Prevent nonsensical arithmetic operations.
- Make the unspecified id more abstract, so it's more obvious and portable.
- Make conversions to/from numbers (for display or storage) more visible.
- Allow future changes of APIs using them less risky.
- Allow future changes of the ids themselves (e.g., to be able to use bigger underlying types on some platforms, or even the opaque
std::thread::id
type.)
Assignee | ||
Comment 1•3 years ago
|
||
This should indirectly help bug 1716959, to possibly avoid adding more MOZ_GECKO_PROFILER ifdefs.
Assignee | ||
Comment 2•3 years ago
|
||
The next patch will extract parts of these headers into a separate file, so it's best to do this clean-up now, to best preserve history.
- Add [[nodiscard]] to all functions that return something. (There are no cases where that returned value could really be ignored.)
- Hide scProfilerMainThreadId in a "detail" namespace, to emphasize that it's an implementation detail that the user shouldn't access directly.
- Combine tightly-nested namespaces start/end into single lines, it's more readable.
Assignee | ||
Comment 3•3 years ago
|
||
This new header isolates the process and thread functions that should be available in all builds, and in most other profiler headers.
Non-MOZ_GECKO_PROFILER implementations return ids 0 (unspecified process/thread). profiler_is_main_thread()
returns false, it's arbitrary but consistent with 0
(it makes little sense to use it there anyway.)
Depends on D120219
Assignee | ||
Comment 4•3 years ago
|
||
These classes should replace the int
type that is currently used to store process and thread ids. The next patches will start using them. Advantages:
- Prevent type mismatches, e.g., giving a process id (or other number) to a function expecting a thread id.
- Prevent nonsensical arithmetic operations.
- Make the unspecified id more abstract, so it's more obvious and portable.
- Make conversions to/from numbers (for display or storage) more visible.
- Allow future changes of APIs using them less risky.
- Allow future changes of the ids themselves (e.g., to be able to use bigger underlying types on some platforms, or even the opaque std::thread::id type.)
Depends on D120220
Assignee | ||
Comment 5•3 years ago
|
||
Depends on D120221
Assignee | ||
Comment 6•3 years ago
|
||
Depends on D120222
Assignee | ||
Comment 7•3 years ago
|
||
Depends on D120223
Assignee | ||
Comment 8•3 years ago
|
||
Depends on D120224
Comment 10•3 years ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/1ebbc3897e2e
https://hg.mozilla.org/mozilla-central/rev/d9847e47ae5c
https://hg.mozilla.org/mozilla-central/rev/b5ffc719210c
https://hg.mozilla.org/mozilla-central/rev/2ac1a3d1198e
https://hg.mozilla.org/mozilla-central/rev/5a2c9d6565f9
https://hg.mozilla.org/mozilla-central/rev/c70e8287ac4a
https://hg.mozilla.org/mozilla-central/rev/f9d10b5d09c8
Description
•