Module: Fiveruns::Tuneup

Extended by:
AssetTags, Environment, Instrumentation::Utilities, Runs, Schema, Urls
Defined in:
lib/fiveruns/tuneup.rb,
lib/fiveruns/tuneup/runs.rb,
lib/fiveruns/tuneup/step.rb,
lib/fiveruns/tuneup/urls.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, Urls 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?

Methods included from Urls

collector_url, frontend_url

Class Attribute Details

.collectingObject



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

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

.runningObject

Returns the value of attribute running.



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

def running
  @running
end

.trendObject (readonly)

Returns the value of attribute trend.



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

def trend
  @trend
end

Class Method Details

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

Yields:



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

def config(&block)
  yield configuration
end

.configurationObject



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

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

.log(level, text) ⇒ Object



108
109
110
111
112
# File 'lib/fiveruns/tuneup.rb', line 108

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

.loggerObject



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

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



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
87
# File 'lib/fiveruns/tuneup.rb', line 57

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)


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

def recording?
  @running && @collecting
end

.run(controller, request) ⇒ Object



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

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



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

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