Module: Fiveruns::Tuneup

Extended by:
AssetTags, Environment, Instrumentation::Utilities, Runs, Schema
Defined in:
lib/fiveruns/tuneup.rb,
lib/fiveruns/tuneup/runs.rb,
lib/fiveruns/tuneup/step.rb,
lib/fiveruns/tuneup/schema.rb,
lib/fiveruns/tuneup/routing.rb,
lib/fiveruns/tuneup/version.rb,
lib/fiveruns/tuneup/multipart.rb,
lib/fiveruns/tuneup/asset_tags.rb,
lib/fiveruns/tuneup/environment.rb,
lib/fiveruns/tuneup/configuration.rb,
lib/fiveruns/tuneup/instrumentation/utilities.rb,
lib/fiveruns/tuneup/instrumentation/cgi/session.rb,
lib/fiveruns/tuneup/instrumentation/action_view/base.rb,
lib/fiveruns/tuneup/instrumentation/active_record/base.rb,
lib/fiveruns/tuneup/instrumentation/action_controller/base.rb,
lib/fiveruns/tuneup/instrumentation/action_view/partial_template.rb

Defined Under Namespace

Modules: AssetTags, CustomMethods, Environment, Instrumentation, Routing, Runs, Schema Classes: Configuration, Multipart, RootStep, Step, Version

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from Schema

add_schema_for, schemas

Methods included from Environment

application_name, environment, rails_env, rails_version

Methods included from Instrumentation::Utilities

add_custom_methods, custom_methods, exclude, exclusion_stack, handle_exclusions_in, instrument, instrument_action_methods, instrument_custom_methods, instrument_filters, stack, step, stopwatch

Methods included from Runs

last_filename_for_run_uri, last_run, load_from_file, retrieve_run, run_dir

Methods included from AssetTags

add_asset_tags_to, add_content_length, insert_prototype, show_for?

Class Attribute Details

.collectingObject



48
49
50
51
52
53
54
# File 'lib/fiveruns/tuneup.rb', line 48

def collecting
  if defined?(@collecting)
    @collecting
  else
    @collecting = true
  end
end

.runningObject

Returns the value of attribute running.



20
21
22
# File 'lib/fiveruns/tuneup.rb', line 20

def running
  @running
end

.trendObject (readonly)

Returns the value of attribute trend.



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

def trend
  @trend
end

Class Method Details

.config {|configuration| ... } ⇒ Object

Yields:



40
41
42
# File 'lib/fiveruns/tuneup.rb', line 40

def config(&block)
  yield configuration
end

.configurationObject



44
45
46
# File 'lib/fiveruns/tuneup.rb', line 44

def configuration
  @configuration ||= ::Fiveruns::Tuneup::Configuration.new
end

.log(level, text) ⇒ Object



105
106
107
108
109
# File 'lib/fiveruns/tuneup.rb', line 105

def log(level, text)
  message = log_format % text
  logger.send(level, message)
  STDERR.puts message if level == :error
end

.loggerObject



23
24
25
26
27
28
# File 'lib/fiveruns/tuneup.rb', line 23

def logger
  @logger ||= returning Logger.new(log_file) do |l|
    RAILS_DEFAULT_LOGGER.info(log_format % "Logging in #{log_file}")
    l.level = Logger::INFO
  end
end

.record(controller, request) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/fiveruns/tuneup.rb', line 56

def record(controller, request)
  if recording?
    @stack = [Fiveruns::Tuneup::RootStep.new]
    @trend = nil
    @environment = environment
    yield
    log :info, "Persisting for #{request.url} using stub #{stub(request.url)}"
    data = @stack.shift
    persist(generate_run_id(request.url, data.time), @environment, schemas, data)
  elsif !@running
    # Plugin displaying the data
    # TODO: Support targeted selection (for historical run)
    if request.parameters['uri']
      last_id = last_run_id_for(request.parameters['uri'])
      log :info, "Retrieved last run id of #{last_id} for #{request.parameters['uri']} using stub #{stub(request.parameters['uri'])}"
      if last_id && (data = retrieve_run(last_id))
        @stack = [data]
        @trend = trend_for(last_id)
      else
        log :debug, "No stack found"
        clear_stack
      end
    else
      clear_stack
    end
    yield
  else
    yield
  end
  clear_stack
end

.recording?Boolean

Returns:

  • (Boolean)


88
89
90
# File 'lib/fiveruns/tuneup.rb', line 88

def recording?
  @running && @collecting
end

.run(controller, request) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/fiveruns/tuneup.rb', line 30

def run(controller, request)
  @running = (!controller.is_a?(TuneupController) && !request.xhr?)
  result = nil
  record controller, request do
    result = yield
  end
  @running = false
  result
end

.startObject



92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/fiveruns/tuneup.rb', line 92

def start
  if supports_rails?
    load_configuration_file
    if configuration.instrument?
      yield
      install_instrumentation
      log :info, "Started."
    else
      log :warn, "Not configured to run in #{RAILS_ENV} environment, aborting."
    end
  end
end