Module: Datadog::Profiling::SequenceTracker
- Extended by:
- Core::Utils::Forking
- Defined in:
- lib/datadog/profiling/sequence_tracker.rb
Overview
Used to generate the ‘profile_seq` tag, which effectively counts how many profiles we’ve attempted to report from a given runtime-id.
Note that the above implies a few things:
-
The sequence number only gets incremented when we decide to report a profile and create a ‘Flush` for it
-
The ‘SequenceTracker` must live across profiler reconfigurations and resets, since no matter how many profiler instances get created due to reconfiguration, the runtime-id is still the same, so the sequence number should be kept and not restarted from 0
-
The ‘SequenceTracker` must be reset after a fork, since the runtime-id will change, and we want to start counting from 0 again
This is why this module is implemented as a singleton that we reuse, not as an instance that we recreate.
Note that this module is not thread-safe, so it’s up to the callers to make sure it’s only used by a single thread at a time (which is what the ‘Profiling::Exporter`) is doing.
Class Method Summary collapse
Methods included from Core::Utils::Forking
after_fork!, extended, fork_pid, forked?, included, update_fork_pid!
Class Method Details
.get_next ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/datadog/profiling/sequence_tracker.rb', line 27 def get_next reset! unless defined?(@sequence_number) after_fork! { reset! } next_seq = @sequence_number @sequence_number += 1 next_seq end |