Module: AppPerfRpm

Defined in:
lib/app_perf_rpm.rb,
lib/app_perf_rpm/span.rb,
lib/app_perf_rpm/utils.rb,
lib/app_perf_rpm/logger.rb,
lib/app_perf_rpm/tracer.rb,
lib/app_perf_rpm/worker.rb,
lib/app_perf_rpm/railtie.rb,
lib/app_perf_rpm/backtrace.rb,
lib/app_perf_rpm/aggregator.rb,
lib/app_perf_rpm/dispatcher.rb,
lib/app_perf_rpm/middleware.rb,
lib/app_perf_rpm/introspector.rb,
lib/app_perf_rpm/configuration.rb,
lib/app_perf_rpm/instrumentation.rb,
lib/app_perf_rpm/instruments/rack.rb,
lib/app_perf_rpm/instruments/sequel.rb,
lib/app_perf_rpm/instruments/faraday.rb,
lib/app_perf_rpm/instruments/sidekiq.rb,
lib/app_perf_rpm/instruments/sinatra.rb,
lib/app_perf_rpm/instruments/typhoeus.rb,
lib/app_perf_rpm/instruments/active_record.rb,
lib/app_perf_rpm/instruments/emque_consuming.rb,
lib/app_perf_rpm/instruments/rack_middleware.rb,
lib/app_perf_rpm/instruments/action_controller.rb,
lib/app_perf_rpm/instruments/activerecord_import.rb,
lib/app_perf_rpm/instruments/active_record/adapters/mysql2.rb,
lib/app_perf_rpm/instruments/active_record/adapters/sqlite3.rb,
lib/app_perf_rpm/instruments/active_record/adapters/postgresql.rb

Defined Under Namespace

Modules: Instruments, Utils Classes: Aggregator, Backtrace, Configuration, Dispatcher, Instrumentation, Introspector, Logger, Middleware, Railtie, SidekiqClient, SidekiqServer, Span, Tracer, Worker

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject



21
22
23
# File 'lib/app_perf_rpm.rb', line 21

def configuration
  @configuration ||= Configuration.new
end

.loggerObject

Returns the value of attribute logger.



5
6
7
# File 'lib/app_perf_rpm/logger.rb', line 5

def logger
  @logger
end

Class Method Details

.configure {|configuration| ... } ⇒ Object

Yields:



25
26
27
# File 'lib/app_perf_rpm.rb', line 25

def configure
  yield(configuration)
end

.disable_agent?Boolean

Returns:

  • (Boolean)


113
114
115
116
117
118
119
120
121
# File 'lib/app_perf_rpm.rb', line 113

def disable_agent?
  if configuration.agent_disabled
    true
  elsif Introspector.agentable?
    false
  else
    true
  end
end

.floor_time(t, sec = 1) ⇒ Object



109
110
111
# File 'lib/app_perf_rpm.rb', line 109

def floor_time(t, sec = 1)
  Time.at((t.to_f / sec).floor * sec)
end

.hostObject



89
90
91
# File 'lib/app_perf_rpm.rb', line 89

def host
  @host ||= Socket.gethostname
end

.loadObject



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/app_perf_rpm.rb', line 29

def load
  #Oj.mimic_JSON
  unless disable_agent?
    AppPerfRpm::Instrumentation.load
    @worker = ::AppPerfRpm::Worker.new

    if @worker.start
      @worker_running = true
      AppPerfRpm.tracing_on
    end
  end
end

.mutexObject



46
47
48
# File 'lib/app_perf_rpm.rb', line 46

def mutex
  @mutex ||= Mutex.new
end

.round_time(t, sec = 1) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/app_perf_rpm.rb', line 93

def round_time(t, sec = 1)
  t = Time.parse(t.to_s)

  down = t - (t.to_i % sec)
  up = down + sec

  difference_down = t - down
  difference_up = up - t

  if (difference_down < difference_up)
    return down
  else
    return up
  end
end

.store(event) ⇒ Object



50
51
52
53
54
55
# File 'lib/app_perf_rpm.rb', line 50

def store(event)
  if @worker_running && tracing?
    @worker.save(event)
  end
  event
end

.tracing?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/app_perf_rpm.rb', line 75

def tracing?
  @tracing
end

.tracing_offObject



68
69
70
71
72
73
# File 'lib/app_perf_rpm.rb', line 68

def tracing_off
  mutex.synchronize do
    AppPerfRpm.logger.debug "Disabling tracing."
    @tracing = false
  end
end

.tracing_onObject



57
58
59
60
61
62
63
64
65
66
# File 'lib/app_perf_rpm.rb', line 57

def tracing_on
  if @without_tracing_enabled
    AppPerfRpm.logger.debug "Not turning tracing on due to without tracing mode."
    return
  end
  mutex.synchronize do
    AppPerfRpm.logger.debug "Enabling tracing."
    @tracing = true
  end
end

.without_tracingObject



79
80
81
82
83
84
85
86
87
# File 'lib/app_perf_rpm.rb', line 79

def without_tracing
  @previously_tracing = AppPerfRpm.tracing?
  @without_tracing_enabled = true
  AppPerfRpm.tracing_off
  yield if block_given?
  @without_tracing_enabled = false
ensure
  AppPerfRpm.tracing_on if @previously_tracing
end

.workerObject



42
43
44
# File 'lib/app_perf_rpm.rb', line 42

def worker
  @worker
end