Class: PerformanceTester::CsvLogger
- Inherits:
-
Logger
- Object
- Logger
- PerformanceTester::CsvLogger
show all
- Defined in:
- lib/performance_tester/csv_logger.rb
Overview
Writes or appends csv data to the filesystem
Instance Attribute Summary
Attributes inherited from Logger
#options, #outcome, #run_name
Instance Method Summary
collapse
Methods inherited from Logger
#initialize
Instance Method Details
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/performance_tester/csv_logger.rb', line 29
def
[
'Run name',
'Run datetime',
'Host alias',
'Path',
'Content type',
'Elapsed time'
]
end
|
#log ⇒ Object
11
12
13
14
15
16
17
18
|
# File 'lib/performance_tester/csv_logger.rb', line 11
def log
with_csv do |csv|
outcome.requests.each do |request|
csv << request_line(request)
end
csv << total_line
end
end
|
#path ⇒ Object
7
8
9
|
# File 'lib/performance_tester/csv_logger.rb', line 7
def path
options.fetch(:path) { 'performance_test.csv' }
end
|
#request_line(request) ⇒ Object
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/performance_tester/csv_logger.rb', line 40
def request_line(request)
[
run_name,
outcome.started_at,
request.host_alias,
request.path,
request.content_type,
request.time_elapsed
]
end
|
#total_line ⇒ Object
51
52
53
|
# File 'lib/performance_tester/csv_logger.rb', line 51
def total_line
[run_name, outcome.started_at, '', '', '', outcome.total_time_elapsed]
end
|
#with_csv ⇒ Object
20
21
22
23
24
25
26
27
|
# File 'lib/performance_tester/csv_logger.rb', line 20
def with_csv
append = File.exists?(path)
flags = append ? 'ab' : 'wb'
CSV.open(path, flags) do |csv|
csv << unless append
yield csv
end
end
|