Class: ParallelTests::FineGrainTest::RuntimeLogger
- Inherits:
-
Object
- Object
- ParallelTests::FineGrainTest::RuntimeLogger
- Defined in:
- lib/parallel_tests/fine_grain_test/runtime_logger.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(file_name = ENV['FINE_GRAIN_TEST_RUNTIME_LOGGER']) ⇒ RuntimeLogger
constructor
A new instance of RuntimeLogger.
- #log_runtime(test_case) ⇒ Object
- #reset ⇒ Object
- #runtimes ⇒ Object
Constructor Details
#initialize(file_name = ENV['FINE_GRAIN_TEST_RUNTIME_LOGGER']) ⇒ RuntimeLogger
Returns a new instance of RuntimeLogger.
23 24 25 |
# File 'lib/parallel_tests/fine_grain_test/runtime_logger.rb', line 23 def initialize(file_name = ENV['FINE_GRAIN_TEST_RUNTIME_LOGGER']) @file_name = file_name end |
Class Method Details
.delta ⇒ Object
16 17 18 19 20 |
# File 'lib/parallel_tests/fine_grain_test/runtime_logger.rb', line 16 def delta before = now.to_f yield now.to_f - before end |
.now ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/parallel_tests/fine_grain_test/runtime_logger.rb', line 8 def now if Time.respond_to?(:now_without_mock_time) # Timecop Time.now_without_mock_time else Time.now end end |
Instance Method Details
#log_runtime(test_case) ⇒ Object
50 51 52 53 54 55 |
# File 'lib/parallel_tests/fine_grain_test/runtime_logger.rb', line 50 def log_runtime(test_case) result = nil time = self.class.delta { result = yield } log(test_case, time) result end |
#reset ⇒ Object
27 28 29 30 31 32 |
# File 'lib/parallel_tests/fine_grain_test/runtime_logger.rb', line 27 def reset lock do |f| f.pos = 0 f.truncate(0) end end |
#runtimes ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/parallel_tests/fine_grain_test/runtime_logger.rb', line 34 def runtimes times = {} lock do |f| lines = f.read.split(/\n/) lines.each do |line| time, test_case = line.split(/ /, 2) next unless time and test_case time = time.to_f test_case = TestCase.decode(test_case) times[test_case] = time end end times end |