Class: Fiveruns::Dash::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/fiveruns/dash/session.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ Session

Returns a new instance of Session.



6
7
8
9
10
11
# File 'lib/fiveruns/dash/session.rb', line 6

def initialize(configuration)
  @configuration = configuration
  # eager create the host data in the main thread
  # as it is dangerous to load in the reporter thread
  Fiveruns::Dash.host
end

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



5
6
7
# File 'lib/fiveruns/dash/session.rb', line 5

def configuration
  @configuration
end

#reporterObject (readonly)

Returns the value of attribute reporter.



5
6
7
# File 'lib/fiveruns/dash/session.rb', line 5

def reporter
  @reporter
end

Instance Method Details

#add_exception(exception, sample = nil) ⇒ Object



31
32
33
# File 'lib/fiveruns/dash/session.rb', line 31

def add_exception(exception, sample=nil)
  exception_recorder.record(exception, sample)
end

#dataObject



59
60
61
62
63
64
65
66
# File 'lib/fiveruns/dash/session.rb', line 59

def data
  real_data = configuration.metrics.map { |metric| metric.data }.compact
  virtual_data = configuration.metrics.map { |metric| metric.calculate(real_data) }.compact
  # Return any metrics which are not abstract and should be sent to the server
  metric_payload = (real_data + virtual_data).find_all { |data| !data[:abstract] }
  #puts "Sending #{metric_payload.map { |met| [met[:name], met[:values].size] }.inspect} metrics"
  metric_payload
end

#exception_dataObject



68
69
70
# File 'lib/fiveruns/dash/session.rb', line 68

def exception_data
  exception_recorder.data
end

#exception_recorderObject



72
73
74
# File 'lib/fiveruns/dash/session.rb', line 72

def exception_recorder
  @exception_recorder ||= ExceptionRecorder.new(self)
end

#exceptionsObject



18
19
20
# File 'lib/fiveruns/dash/session.rb', line 18

def exceptions
  @exceptions ||= []
end

#infoObject



35
36
37
38
39
40
# File 'lib/fiveruns/dash/session.rb', line 35

def info
  {
    :recipes => ,
    :metric_infos => 
  }
end

#metric_metadataObject



48
49
50
51
52
# File 'lib/fiveruns/dash/session.rb', line 48

def 
  configuration.metrics.inject([]) do |metrics, metric|
    metrics << metric.info
  end
end

#recipe_metadataObject



42
43
44
45
46
# File 'lib/fiveruns/dash/session.rb', line 42

def 
  configuration.recipes.inject([]) do |recipes, recipe|
    recipes << recipe.info
  end
end

#resetObject



54
55
56
57
# File 'lib/fiveruns/dash/session.rb', line 54

def reset
  exception_recorder.reset
  configuration.metrics.each { |m| m.reset }
end

#start(background = true, &block) ⇒ Object



13
14
15
16
# File 'lib/fiveruns/dash/session.rb', line 13

def start(background = true, &block)
  Fiveruns::Dash.logger.info "Starting Dash #{Fiveruns::Dash::Util.version_info}"
  reporter.start(background, &block)
end

#trace(name) ⇒ Object

Trace and send metric collection



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

def trace(name)
  Thread.current[:trace] = ::Fiveruns::Dash::Trace.new(name)
  result = yield
  reporter.send_trace(Thread.current[:trace])
  Thread.current[:trace] = nil
  result
end