Class: TravisProfilerFormatter

Inherits:
XCPretty::Formatter
  • Object
show all
Defined in:
lib/travis_profiler_formatter.rb

Instance Method Summary collapse

Constructor Details

#initialize(use_unicode, colorize) ⇒ TravisProfilerFormatter

Returns a new instance of TravisProfilerFormatter.



3
4
5
6
7
8
# File 'lib/travis_profiler_formatter.rb', line 3

def initialize(use_unicode, colorize)
  super(use_unicode, colorize)
  @compilation_phases = []
  @current_compilation_phase = []
  @compilation_phase_end_times = []
end

Instance Method Details

#calculate_compile_timesObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/travis_profiler_formatter.rb', line 65

def calculate_compile_times
  compile_times = []
  @compilation_phases.each_with_index do | compilation_phase, i |
    compilation_phase.each_with_index do | compilation, j |
      if j < (compilation_phase.count - 1) && compilation[:file_name]
        compile_times.push({
          :file_path => compilation[:file_path],
          :file_name => compilation[:file_name],
          :compile_time => compilation_phase[j+1][:start_time].to_f - compilation[:start_time].to_f
        })
      elsif j == compilation_phase.count - 1 && compilation[:file_name]
        compile_times.push({
          :file_path => compilation[:file_path],
          :file_name => compilation[:file_name],
          :compile_time => @compilation_phase_end_times[i].to_f - compilation[:start_time].to_f
        })
      end
    end
  end

  return compile_times
end

#close_fold(text) ⇒ Object



99
100
101
102
# File 'lib/travis_profiler_formatter.rb', line 99

def close_fold(text)
  print "travis_fold:end:#{text}\r"
  @open_fold = nil
end

#format_analyze_target(target, project, configuration) ⇒ Object



109
110
111
112
# File 'lib/travis_profiler_formatter.rb', line 109

def format_analyze_target(target, project, configuration)
  open_fold("Analyze")
  super
end

#format_build_target(target, project, configuration) ⇒ Object



104
105
106
107
# File 'lib/travis_profiler_formatter.rb', line 104

def format_build_target(target, project, configuration)
  open_fold("Build")
  super
end

#format_clean_target(target, project, configuration) ⇒ Object



114
115
116
117
# File 'lib/travis_profiler_formatter.rb', line 114

def format_clean_target(target, project, configuration)
  open_fold("Clean")
  super
end

#format_compile(file_name, file_path) ⇒ Object

For each file that we compile, track the current timestamp



11
12
13
14
# File 'lib/travis_profiler_formatter.rb', line 11

def format_compile(file_name, file_path)
  mark_compilation(file_path, file_name)
  EMPTY;
end

#format_compile_command(compiler_command, file_path) ⇒ Object



16
17
18
19
# File 'lib/travis_profiler_formatter.rb', line 16

def format_compile_command(compiler_command, file_path)
  mark_compilation(file_path, nil)
  EMPTY;
end

#format_linking(file, build_variant, arch) ⇒ Object

Every time we enter the linking phase, we wrap up a compilation phase Store statistics for the current phase and set up for a new phase



23
24
25
26
# File 'lib/travis_profiler_formatter.rb', line 23

def format_linking(file, build_variant, arch)
  start_new_compilation_phase
  EMPTY;
end

#format_phase_success(phase_name) ⇒ Object

When the build succeeded, we can generate our statistics and print them to the console



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/travis_profiler_formatter.rb', line 29

def format_phase_success(phase_name)
  unless @current_compilation_phase.empty?
    start_new_compilation_phase
  end

  if phase_name == "BUILD"
    compile_times = calculate_compile_times
    compile_times.sort_by { | compilation |
      compilation[:compile_time]
    }.each do | compilation |
      puts "[#{format("%.4f", compilation[:compile_time])}] #{compilation[:file_path]}"
    end

    total_time = compile_times.reduce(0) { | acc, compilation |
      acc + compilation[:compile_time]
    }
    puts "-----"
    puts "[#{format("%.4f", total_time)}] Total compilation time"
  end
  EMPTY;
end

#format_test_run_finished(name, time) ⇒ Object



124
125
126
127
# File 'lib/travis_profiler_formatter.rb', line 124

def format_test_run_finished(name, time)
  close_fold("Tests-#{scrub(name)}")
  super
end

#format_test_run_started(name) ⇒ Object



119
120
121
122
# File 'lib/travis_profiler_formatter.rb', line 119

def format_test_run_started(name)
  open_fold("Tests-#{scrub(name)}")
  super
end

#mark_compilation(file_path, file_name) ⇒ Object



51
52
53
54
55
56
57
# File 'lib/travis_profiler_formatter.rb', line 51

def mark_compilation(file_path, file_name)
  @current_compilation_phase.push({
    :start_time => Time.now,
    :file_path => file_path,
    :file_name => file_name
  })
end

#open_fold(text) ⇒ Object



92
93
94
95
96
97
# File 'lib/travis_profiler_formatter.rb', line 92

def open_fold(text)
  return if text == @open_fold
  close_fold(@open_fold) if @open_fold
  print "travis_fold:start:#{text}\r"
  @open_fold = text
end

#scrub(text) ⇒ Object



129
130
131
# File 'lib/travis_profiler_formatter.rb', line 129

def scrub(text)
  text.gsub(/\s/,"_").split(".").first
end

#start_new_compilation_phaseObject



59
60
61
62
63
# File 'lib/travis_profiler_formatter.rb', line 59

def start_new_compilation_phase
  @compilation_phase_end_times.push(Time.now)
  @compilation_phases.push(@current_compilation_phase)
  @current_compilation_phase = []
end