module NewRelic::Agent::StatsEngine::GCProfiler

Constants

GCSnapshot
GC_OTHER
GC_ROLLUP
GC_WEB

Public Class Methods

gc_metric_name() click to toggle source
# File lib/new_relic/agent/stats_engine/gc_profiler.rb, line 60
def self.gc_metric_name
  if NewRelic::Agent::Transaction.recording_web_transaction?
    GC_WEB
  else
    GC_OTHER
  end
end
init() click to toggle source
# File lib/new_relic/agent/stats_engine/gc_profiler.rb, line 11
def self.init
  @initialized ||= nil
  return @profiler if @initialized
  @profiler = if RailsBenchProfiler.enabled?
    RailsBenchProfiler.new
  elsif CoreGCProfiler.enabled?
    CoreGCProfiler.new
  end
  @initialized = true
  @profiler
end
record_delta(start_snapshot, end_snapshot) click to toggle source
# File lib/new_relic/agent/stats_engine/gc_profiler.rb, line 37
def self.record_delta(start_snapshot, end_snapshot)
  if @profiler && start_snapshot && end_snapshot
    elapsed_gc_time_s = end_snapshot.gc_time_s - start_snapshot.gc_time_s
    num_calls         = end_snapshot.gc_call_count - start_snapshot.gc_call_count
    record_gc_metric(num_calls, elapsed_gc_time_s)

    @profiler.reset
    elapsed_gc_time_s
  end
end
record_gc_metric(call_count, elapsed) click to toggle source
# File lib/new_relic/agent/stats_engine/gc_profiler.rb, line 48
def self.record_gc_metric(call_count, elapsed) #THREAD_LOCAL_ACCESS
  NewRelic::Agent.agent.stats_engine.tl_record_scoped_and_unscoped_metrics(gc_metric_name, GC_ROLLUP) do |stats|
    stats.call_count           += call_count
    stats.total_call_time      += elapsed
    stats.total_exclusive_time += elapsed
  end
end
reset() click to toggle source
# File lib/new_relic/agent/stats_engine/gc_profiler.rb, line 23
def self.reset
  @profiler    = nil
  @initialized = nil
end
take_snapshot() click to toggle source
# File lib/new_relic/agent/stats_engine/gc_profiler.rb, line 28
def self.take_snapshot
  init
  if @profiler
    GCSnapshot.new(@profiler.call_time_s, @profiler.call_count)
  else
    nil
  end
end