Closed Bug 1721110 Opened 3 years ago Closed 3 years ago

Encapsulate process id and thread id in distinct types

Categories

(Core :: Gecko Profiler, task, P2)

task

Tracking

()

RESOLVED FIXED
92 Branch
Tracking Status
firefox92 --- fixed

People

(Reporter: mozbugz, Assigned: mozbugz)

References

Details

Attachments

(7 files)

Process and thread ids, as reported by profiler_current_process_id() and profiler_current_thread_id(), are currently stored in simple ints, 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.)

This should indirectly help bug 1716959, to possibly avoid adding more MOZ_GECKO_PROFILER ifdefs.

Blocks: 1716959

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.

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

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

Pushed by gsquelart@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/1ebbc3897e2e {,Base}ProfilerState.h improvements: Sprinkle nodiscard's and more - r=florian https://hg.mozilla.org/integration/autoland/rev/d9847e47ae5c {,Base}ProfilerUtils.h with process&thread functions taken from {,Base}ProfilerState.h - r=florian https://hg.mozilla.org/integration/autoland/rev/b5ffc719210c Introduce BaseProfilerProcessId and BaseProfilerThreadId - r=florian https://hg.mozilla.org/integration/autoland/rev/2ac1a3d1198e baseprofiler::profiler_current_process_id() now returns BaseProfilerProcessId - r=florian https://hg.mozilla.org/integration/autoland/rev/5a2c9d6565f9 profiler_current_process_id() now returns ProfilerProcessId - r=florian https://hg.mozilla.org/integration/autoland/rev/c70e8287ac4a baseprofiler::profiler_current_thread_id() now returns BaseProfilerThreadId - r=florian https://hg.mozilla.org/integration/autoland/rev/f9d10b5d09c8 profiler_current_thread_id() now returns ProfilerThreadId - r=florian
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: