Sha256: 713919499f825ba78b48a1a7f493e972670eae8b3c6cd8aa2c2eef7a380f98cd

Contents?: true

Size: 1.83 KB

Versions: 6

Compression:

Stored size: 1.83 KB

Contents

# encoding: utf-8
# This file is distributed under New Relic's license terms.
# See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.

require './app'
require 'multiverse_helpers'

# GC instrumentation only works with REE or 1.9.x
if (defined?(RUBY_DESCRIPTION) && RUBY_DESCRIPTION =~ /Enterprise/) ||
    RUBY_VERSION >= '1.9.2'

class GcController < ApplicationController
  include Rails.application.routes.url_helpers
  def gc_action
    long_string = "01234567" * 100_000
    long_string = nil
    another_long_string = "01234567" * 100_000

    GC.start

    render :text => 'ha'
  end
end

class GCRailsInstrumentationTest < ActionController::TestCase
  tests GcController

  include MultiverseHelpers

  setup_and_teardown_agent do
    enable_gc_stats
    @controller = GcController.new
  end

  def test_records_accurate_time_for_gc_activity
    start = Time.now
    get :gc_action
    elapsed = Time.now.to_f - start.to_f

    assert_in_range(elapsed, get_call_time('GC/cumulative'))
    assert_in_range(elapsed, get_call_time('GC/cumulative', 'Controller/gc/gc_action'))
  end

  def test_records_transaction_param_for_gc_activity
    start = Time.now.to_f
    get :gc_action
    elapsed = Time.now.to_f - start

    trace = NewRelic::Agent.instance.transaction_sampler.last_sample
    assert_in_range(elapsed, trace.params[:custom_params][:gc_time])
  end

  def assert_in_range(duration, gc_time)
    assert gc_time > 0.0, "GC Time wasn't recorded!"
    assert gc_time < duration, "GC Time can't be more than elapsed!"
  end

  def get_call_time(name, scope=nil)
    NewRelic::Agent.agent.stats_engine.
      get_stats(name, true, false, scope).
      total_call_time
  end

  def enable_gc_stats
    if RUBY_DESCRIPTION =~ /Enterprise/
      GC.enable_stats
    elsif RUBY_VERSION >= '1.9.2'
      GC::Profiler.enable
    end
  end
end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
newrelic_rpm-3.6.8.168 test/multiverse/suites/rails/gc_instrumentation_test.rb
newrelic_rpm-3.6.8.164 test/multiverse/suites/rails/gc_instrumentation_test.rb
newrelic_rpm-3.6.7.159 test/multiverse/suites/rails/gc_instrumentation_test.rb
newrelic_rpm-3.6.7.159.beta test/multiverse/suites/rails/gc_instrumentation_test.rb
newrelic_rpm-3.6.7.152 test/multiverse/suites/rails/gc_instrumentation_test.rb
newrelic_rpm-3.6.6.147 test/multiverse/suites/rails/gc_instrumentation_test.rb