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/delayed_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
KAMIZE_SYNC_TIMEOUT =

seconds

35
NETWORK_ERRORS =
[ Timeout::Error, Errno::ETIMEDOUT, Errno::EINVAL, Errno::ECONNRESET, Errno::ECONNREFUSED,
EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError, IOError ]
VERSION =
"1.0.67"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#interposerObject

Returns the value of attribute interposer.



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

def interposer
  @interposer
end

#loggerObject

Returns the value of attribute logger.



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

def logger
  @logger
end

#snapshotterObject

Returns the value of attribute snapshotter.



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

def snapshotter
  @snapshotter
end

Class Method Details

.current_rssObject



127
128
129
130
# File 'ext/tunemygc/tunemygc_ext.c', line 127

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

.enabled?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/tunemygc.rb', line 23

def self.enabled?
  ENV["RUBY_GC_TUNE"] && ENV["RUBY_GC_TUNE"] != ""
end

.http_clientObject



22
23
24
25
26
27
28
# File 'lib/tunemygc/network.rb', line 22

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



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'ext/tunemygc/tunemygc_ext.c', line 95

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



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

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

.run_silently?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/tunemygc.rb', line 19

def self.run_silently?
  !ENV['RUBY_GC_TUNE_VERBOSE'].nil? && ENV['RUBY_GC_TUNE_VERBOSE'].to_i == 0
end

.uninstall_gc_tracepointObject

Removes a previously enabled GC tracepoint



112
113
114
115
116
117
118
119
120
# File 'ext/tunemygc/tunemygc_ext.c', line 112

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



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

def booted
  TuneMyGc.interposer.install
end

#count_objectsObject



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

def count_objects
  ObjectSpace.count_objects.merge(:memsize => ObjectSpace.memsize_of_all)
end

#log(message) ⇒ Object



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

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

#processing_ended(meta = nil) ⇒ Object



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

def processing_ended(meta = nil)
  snapshot(:PROCESSING_ENDED, meta)
  interposer.check_uninstall
end

#processing_started(meta = nil) ⇒ Object



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

def processing_started(meta = nil)
  snapshot(:PROCESSING_STARTED, meta)
end

#raw_snapshot(snapshot) ⇒ Object



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

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

#recommendationsObject



55
56
57
58
59
60
61
62
63
# File 'lib/tunemygc/agent.rb', line 55

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

#snapshot(stage, meta = nil) ⇒ Object



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

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

#spiesObject



51
52
53
# File 'lib/tunemygc/agent.rb', line 51

def spies
  TuneMyGc::Spies.current
end

#spy_idsObject



47
48
49
# File 'lib/tunemygc/agent.rb', line 47

def spy_ids
  TuneMyGc::Spies.ids
end

#terminatedObject



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

def terminated
  snapshot(:TERMINATED, count_objects)
end