Class: Datadog::Profiling::Exporter
- Inherits:
-
Object
- Object
- Datadog::Profiling::Exporter
- Defined in:
- lib/datadog/profiling/exporter.rb
Overview
Exports profiling data gathered by the multiple recorders in a ‘Flush`.
@ivoanjo: Note that the recorder that gathers pprof data is special, since we use its start/finish/empty? to decide if there’s data to flush, as well as the timestamp for that data. I could’ve made the whole design more generic, but I’m unsure if we’ll ever have more than a handful of recorders, so I’ve decided to make it specific until we actually need to support more recorders.
Constant Summary collapse
- PROFILE_DURATION_THRESHOLD_SECONDS =
Profiles with duration less than this will not be reported
1
Instance Method Summary collapse
- #can_flush? ⇒ Boolean
- #flush ⇒ Object
-
#initialize(pprof_recorder:, code_provenance_collector:, minimum_duration_seconds: PROFILE_DURATION_THRESHOLD_SECONDS, time_provider: Time) ⇒ Exporter
constructor
A new instance of Exporter.
- #reset_after_fork ⇒ Object
Constructor Details
#initialize(pprof_recorder:, code_provenance_collector:, minimum_duration_seconds: PROFILE_DURATION_THRESHOLD_SECONDS, time_provider: Time) ⇒ Exporter
Returns a new instance of Exporter.
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/datadog/profiling/exporter.rb', line 29 def initialize( pprof_recorder:, code_provenance_collector:, minimum_duration_seconds: PROFILE_DURATION_THRESHOLD_SECONDS, time_provider: Time ) @pprof_recorder = pprof_recorder @code_provenance_collector = code_provenance_collector @minimum_duration_seconds = minimum_duration_seconds @time_provider = time_provider @last_flush_finish_at = nil @created_at = time_provider.now.utc end |
Instance Method Details
#can_flush? ⇒ Boolean
67 68 69 |
# File 'lib/datadog/profiling/exporter.rb', line 67 def can_flush? !duration_below_threshold?(last_flush_finish_at || created_at, time_provider.now.utc) end |
#flush ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/datadog/profiling/exporter.rb', line 43 def flush start, finish, uncompressed_pprof = pprof_recorder.serialize @last_flush_finish_at = finish return if uncompressed_pprof.nil? # We don't want to report empty profiles if duration_below_threshold?(start, finish) Datadog.logger.debug('Skipped exporting profiling events as profile duration is below minimum') return end uncompressed_code_provenance = code_provenance_collector.refresh.generate_json if code_provenance_collector Flush.new( start: start, finish: finish, pprof_file_name: Datadog::Profiling::Ext::Transport::HTTP::PPROF_DEFAULT_FILENAME, pprof_data: uncompressed_pprof.to_s, code_provenance_file_name: Datadog::Profiling::Ext::Transport::HTTP::CODE_PROVENANCE_FILENAME, code_provenance_data: uncompressed_code_provenance, tags_as_array: Datadog::Profiling::TagBuilder.call(settings: Datadog.configuration).to_a, ) end |
#reset_after_fork ⇒ Object
71 72 73 74 |
# File 'lib/datadog/profiling/exporter.rb', line 71 def reset_after_fork @last_flush_finish_at = time_provider.now.utc nil end |