Module: TuneMyGc

Extended by:
TuneMyGc
Included in:
TuneMyGc
Defined in:
lib/tunemygc.rb,
lib/tunemygc/cli.rb,
lib/tunemygc/agent.rb,
lib/tunemygc/spies.rb,
lib/tunemygc/syncer.rb,
lib/tunemygc/network.rb,
lib/tunemygc/railtie.rb,
lib/tunemygc/version.rb,
lib/tunemygc/interposer.rb,
lib/tunemygc/spies/base.rb,
lib/tunemygc/subscriber.rb,
lib/tunemygc/snapshotter.rb,
lib/tunemygc/spies/rspec.rb,
lib/tunemygc/spies/manual.rb,
lib/tunemygc/spies/que_job.rb,
lib/tunemygc/spies/minitest.rb,
lib/tunemygc/spies/active_job.rb,
lib/tunemygc/spies/action_controller.rb,
lib/tunemygc/spies/action_controller.rb,
ext/tunemygc/tunemygc_ext.c

Defined Under Namespace

Modules: Spies Classes: CLI, EndRequestSubscriber, Interposer, Railtie, Snapshotter, StartRequestSubscriber, Subscriber, Syncer

Constant Summary collapse

HOST =
(ENV['RUBY_GC_TUNE_HOST'] || "tunemygc.com:443").freeze
HEADERS =
{ "Content-Type" => "application/json",
"Accept" => "application/json",
"User-Agent" => "TuneMyGC #{TuneMyGc::VERSION}"}.freeze
MUTEX =
Mutex.new
NETWORK_TIMEOUT =

seconds

30
VERSION =
"1.0.39"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#interposerObject

Returns the value of attribute interposer.



11
12
13
# File 'lib/tunemygc/agent.rb', line 11

def interposer
  @interposer
end

#loggerObject

Returns the value of attribute logger.



11
12
13
# File 'lib/tunemygc/agent.rb', line 11

def logger
  @logger
end

#snapshotterObject

Returns the value of attribute snapshotter.



11
12
13
# File 'lib/tunemygc/agent.rb', line 11

def snapshotter
  @snapshotter
end

Class Method Details

.current_rssObject



122
123
124
125
# File 'ext/tunemygc/tunemygc_ext.c', line 122

static VALUE tunemygc_current_rss(VALUE mod)
{
    return SIZET2NUM(getCurrentRSS());
}

.http_clientObject



9
10
11
12
13
14
15
# File 'lib/tunemygc/network.rb', line 9

def self.http_client
  uri = URI("https://#{TuneMyGc::HOST}")
  client = Net::HTTP.new(uri.host, uri.port)
  client.use_ssl = true
  client.read_timeout = NETWORK_TIMEOUT
  client
end

.install_gc_tracepointObject

Installs the GC tracepoint and declare interest only in start of the cycle and end of sweep events



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'ext/tunemygc/tunemygc_ext.c', line 90

static VALUE tunemygc_install_gc_tracepoint(VALUE mod)
{
    rb_event_flag_t events;
    VALUE tunemygc_tracepoint = rb_ivar_get(rb_mTunemygc, id_tunemygc_tracepoint);
    if (!NIL_P(tunemygc_tracepoint)) {
        rb_tracepoint_disable(tunemygc_tracepoint);
        rb_ivar_set(rb_mTunemygc, id_tunemygc_tracepoint, Qnil);
    }
    events = RUBY_INTERNAL_EVENT_GC_START | RUBY_INTERNAL_EVENT_GC_END_SWEEP;
    tunemygc_tracepoint = rb_tracepoint_new(0, events, tunemygc_gc_hook_i, (void *)0);
    if (NIL_P(tunemygc_tracepoint)) rb_warn("Could not install GC tracepoint!");
    rb_tracepoint_enable(tunemygc_tracepoint);
    rb_ivar_set(rb_mTunemygc, id_tunemygc_tracepoint, tunemygc_tracepoint);
    return Qnil;
}

.peak_rssObject



117
118
119
120
# File 'ext/tunemygc/tunemygc_ext.c', line 117

static VALUE tunemygc_peak_rss(VALUE mod)
{
    return SIZET2NUM(getPeakRSS());
}

.rails?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/tunemygc.rb', line 11

def self.rails?
  defined?(Rails) && Rails.version >= "3.0"
end

.rails_versionObject



15
16
17
# File 'lib/tunemygc.rb', line 15

def self.rails_version
  rails? ? Rails.version : "0.0"
end

.uninstall_gc_tracepointObject

Removes a previously enabled GC tracepoint



107
108
109
110
111
112
113
114
115
# File 'ext/tunemygc/tunemygc_ext.c', line 107

static VALUE tunemygc_uninstall_gc_tracepoint(VALUE mod)
{
    VALUE tunemygc_tracepoint = rb_ivar_get(rb_mTunemygc, id_tunemygc_tracepoint);
    if (!NIL_P(tunemygc_tracepoint)) {
        rb_tracepoint_disable(tunemygc_tracepoint);
        rb_ivar_set(rb_mTunemygc, id_tunemygc_tracepoint, Qnil);
    }
    return Qnil;
}

.walltimeObject



37
38
39
40
# File 'ext/tunemygc/tunemygc_ext.c', line 37

static VALUE tunemygc_walltime(VALUE mod)
{
    return DBL2NUM(_tunemygc_walltime());
}

Instance Method Details

#bootedObject



13
14
15
# File 'lib/tunemygc/agent.rb', line 13

def booted
  TuneMyGc.interposer.install
end

#log(message) ⇒ Object



34
35
36
# File 'lib/tunemygc/agent.rb', line 34

def log(message)
  logger.info "[TuneMyGC, pid: #{Process.pid}] #{message}"
end

#processing_endedObject



21
22
23
24
# File 'lib/tunemygc/agent.rb', line 21

def processing_ended
  snapshot(:PROCESSING_ENDED)
  interposer.check_uninstall
end

#processing_startedObject



17
18
19
# File 'lib/tunemygc/agent.rb', line 17

def processing_started
  snapshot(:PROCESSING_STARTED)
end

#raw_snapshot(snapshot) ⇒ Object



30
31
32
# File 'lib/tunemygc/agent.rb', line 30

def raw_snapshot(snapshot)
  snapshotter.take_raw(snapshot)
end

#reccommendationsObject



46
47
48
49
50
51
52
53
54
# File 'lib/tunemygc/agent.rb', line 46

def reccommendations
  MUTEX.synchronize do
    require "tunemygc/syncer"
    syncer = TuneMyGc::Syncer.new
    config = syncer.sync(snapshotter)
  end
rescue Exception => e
  log "Config reccommendation error (#{e.message})"
end

#snapshot(stage, meta = nil) ⇒ Object



26
27
28
# File 'lib/tunemygc/agent.rb', line 26

def snapshot(stage, meta = nil)
  snapshotter.take(stage, meta)
end

#spyObject



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

def spy
  TuneMyGc::Spies.current
end

#spy_idObject



38
39
40
# File 'lib/tunemygc/agent.rb', line 38

def spy_id
  TuneMyGc::Spies.id
end