Class: Origen::Application::Statistics

Inherits:
Object
  • Object
show all
Defined in:
lib/origen/application/statistics.rb

Overview

Responsible for keeping track of all stats collected during a run

Defined Under Namespace

Classes: Pattern

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Statistics

Returns a new instance of Statistics.

[View source]

21
22
23
24
25
# File 'lib/origen/application/statistics.rb', line 21

def initialize(options)
  @options = options
  @patterns = {}
  reset_global_stats
end

Instance Attribute Details

#changed_filesObject

Returns the value of attribute changed_files.


5
6
7
# File 'lib/origen/application/statistics.rb', line 5

def changed_files
  @changed_files
end

#changed_patternsObject

Returns the value of attribute changed_patterns.


7
8
9
# File 'lib/origen/application/statistics.rb', line 7

def changed_patterns
  @changed_patterns
end

#completed_filesObject

Returns the value of attribute completed_files.


5
6
7
# File 'lib/origen/application/statistics.rb', line 5

def completed_files
  @completed_files
end

#completed_patternsObject

Returns the value of attribute completed_patterns.


7
8
9
# File 'lib/origen/application/statistics.rb', line 7

def completed_patterns
  @completed_patterns
end

#errorsObject

Returns the value of attribute errors.


9
10
11
# File 'lib/origen/application/statistics.rb', line 9

def errors
  @errors
end

#failed_filesObject

Returns the value of attribute failed_files.


5
6
7
# File 'lib/origen/application/statistics.rb', line 5

def failed_files
  @failed_files
end

#failed_patternsObject

Returns the value of attribute failed_patterns.


7
8
9
# File 'lib/origen/application/statistics.rb', line 7

def failed_patterns
  @failed_patterns
end

#missing_filesObject

Returns the value of attribute missing_files.


5
6
7
# File 'lib/origen/application/statistics.rb', line 5

def missing_files
  @missing_files
end

#missing_patternsObject

Returns the value of attribute missing_patterns.


7
8
9
# File 'lib/origen/application/statistics.rb', line 7

def missing_patterns
  @missing_patterns
end

#new_filesObject

Returns the value of attribute new_files.


5
6
7
# File 'lib/origen/application/statistics.rb', line 5

def new_files
  @new_files
end

#new_patternsObject

Returns the value of attribute new_patterns.


7
8
9
# File 'lib/origen/application/statistics.rb', line 7

def new_patterns
  @new_patterns
end

#total_cyclesObject

Returns the value of attribute total_cycles.


9
10
11
# File 'lib/origen/application/statistics.rb', line 9

def total_cycles
  @total_cycles
end

#total_durationObject

Returns the value of attribute total_duration.


9
10
11
# File 'lib/origen/application/statistics.rb', line 9

def total_duration
  @total_duration
end

#total_vectorsObject

Returns the value of attribute total_vectors.


9
10
11
# File 'lib/origen/application/statistics.rb', line 9

def total_vectors
  @total_vectors
end

Instance Method Details

#add_cycle(x = 1) ⇒ Object

[View source]

128
129
130
# File 'lib/origen/application/statistics.rb', line 128

def add_cycle(x = 1)
  current_pattern.cycles += x
end

#add_time_in_ns(x) ⇒ Object

[View source]

132
133
134
# File 'lib/origen/application/statistics.rb', line 132

def add_time_in_ns(x)
  current_pattern.duration += x
end

#add_vector(x = 1) ⇒ Object

[View source]

124
125
126
# File 'lib/origen/application/statistics.rb', line 124

def add_vector(x = 1)
  current_pattern.vectors += x
end

#clean_run?Boolean

Returns:

  • (Boolean)
[View source]

109
110
111
112
113
114
# File 'lib/origen/application/statistics.rb', line 109

def clean_run?
  @changed_files == 0 && @changed_patterns == 0 &&
    @new_files == 0 && @new_patterns == 0 &&
    @failed_files == 0 && @failed_patterns == 0 &&
    @errors == 0
end

#collect_for_pattern(key) ⇒ Object

[View source]

136
137
138
139
140
# File 'lib/origen/application/statistics.rb', line 136

def collect_for_pattern(key)
  @pattern_key = key
  yield
  @pattern_key = nil
end

#current_patternObject

[View source]

142
143
144
# File 'lib/origen/application/statistics.rb', line 142

def current_pattern
  pattern(@pattern_key)
end

#execution_time_for(key) ⇒ Object

[View source]

158
159
160
# File 'lib/origen/application/statistics.rb', line 158

def execution_time_for(key)
  pattern(key).duration.to_f / 1_000_000_000
end

#number_of_cycles_for(key) ⇒ Object

[View source]

154
155
156
# File 'lib/origen/application/statistics.rb', line 154

def number_of_cycles_for(key)
  pattern(key).vectors
end

#number_of_vectors_for(key) ⇒ Object

[View source]

150
151
152
# File 'lib/origen/application/statistics.rb', line 150

def number_of_vectors_for(key)
  pattern(key).vectors
end

#pattern(key) ⇒ Object

[View source]

146
147
148
# File 'lib/origen/application/statistics.rb', line 146

def pattern(key)
  @patterns[key] ||= Pattern.new
end
[View source]

50
51
52
53
54
55
56
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
88
89
90
91
# File 'lib/origen/application/statistics.rb', line 50

def print_summary
  method = clean_run? ? :success : :info
  if @completed_patterns > 0 || @failed_patterns > 0
    Origen.log.send method, "Total patterns:   #{@completed_patterns}"
    Origen.log.send method, "Total vectors:    #{@total_vectors}"
    Origen.log.send method, 'Total duration:   %.6f' % @total_duration
    Origen.log.send method, "New patterns:     #{@new_patterns}"
    if @changed_patterns > 0
      Origen.log.warn "Changed patterns: #{@changed_patterns}"
    else
      Origen.log.send method, "Changed patterns: #{@changed_patterns}"
    end
    Origen.log.error "FAILED patterns:  #{@failed_patterns}" if @failed_patterns > 0
    Origen.log.info
  end
  if @completed_files > 0 || @failed_files > 0
    Origen.log.send method, "Total files:      #{@completed_files}"
    Origen.log.send method, "New files:        #{@new_files}"
    Origen.log.send method, "Changed files:    #{@changed_files}"
    Origen.log.error "FAILED files:     #{@failed_files}" if @failed_files > 0
    Origen.log.info
  end
  if @errors > 0
    Origen.log.error "ERRORS:           #{@errors}"
  end

  if @changed_files > 0 || @changed_patterns > 0
    changes = true
    Origen.log.info 'To accept all of these changes run:'
    Origen.log.info '  origen save changed'
  end
  if @new_files > 0 || @new_patterns > 0
    news = true
    Origen.log.info 'To save all of these new files as the reference version run:'
    Origen.log.info '  origen save new'
  end
  if changes && news
    Origen.log.info 'To save both new and changed files run:'
    Origen.log.info '  origen save all'
  end
  Origen.log.info '**********************************************************************'
end

#record_failed_patternObject

[View source]

116
117
118
# File 'lib/origen/application/statistics.rb', line 116

def record_failed_pattern
  @failed_patterns += 1
end

#record_missing_patternObject

[View source]

120
121
122
# File 'lib/origen/application/statistics.rb', line 120

def record_missing_pattern
  @missing_patterns += 1
end

#record_pattern_completion(key) ⇒ Object

[View source]

162
163
164
165
166
167
# File 'lib/origen/application/statistics.rb', line 162

def record_pattern_completion(key)
  @completed_patterns += 1
  @total_vectors += number_of_vectors_for(key)
  @total_cycles += number_of_cycles_for(key)
  @total_duration += execution_time_for(key)
end

#report_failObject

[View source]

180
181
182
183
184
185
186
187
188
189
# File 'lib/origen/application/statistics.rb', line 180

def report_fail
  Origen.log.error ''
  Origen.log.error '    FFFFFF     AA       II   LL'
  Origen.log.error '    FF        AAAA      II   LL'
  Origen.log.error '    FFFFF    AA  AA     II   LL'
  Origen.log.error '    FF      AAAAAAAA    II   LL'
  Origen.log.error '    FF     AA      AA   II   LL'
  Origen.log.error '    FF    AA        AA  II   LLLLLL'
  Origen.log.error ''
end

#report_passObject

[View source]

169
170
171
172
173
174
175
176
177
178
# File 'lib/origen/application/statistics.rb', line 169

def report_pass
  Origen.log.success ''
  Origen.log.success '    PPPPP      AA        SSSS    SSSS'
  Origen.log.success '    PP  PP    AAAA      SS  SS  SS  SS'
  Origen.log.success '    PPPPP    AA  AA      SS      SS'
  Origen.log.success '    PP      AAAAAAAA       SS      SS'
  Origen.log.success '    PP     AA      AA   SS  SS  SS  SS'
  Origen.log.success '    PP    AA        AA   SSSS    SSSS'
  Origen.log.success ''
end

#reset_global_statsObject

[View source]

27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/origen/application/statistics.rb', line 27

def reset_global_stats
  @completed_files = 0
  @failed_files = 0
  @missing_files = 0
  @new_files = 0
  @changed_files = 0

  @completed_patterns = 0
  @failed_patterns = 0
  @missing_patterns = 0
  @new_patterns = 0
  @changed_patterns = 0

  @total_vectors = 0
  @total_cycles = 0
  @total_duration = 0

  @errors = 0
end

#reset_pattern_statsObject

[View source]

47
48
# File 'lib/origen/application/statistics.rb', line 47

def reset_pattern_stats
end

#summary_textObject

[View source]

93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/origen/application/statistics.rb', line 93

def summary_text
  <<-END
    Total patterns:   #{@completed_patterns}
    New patterns:     #{@new_patterns}
    Changed patterns: #{@changed_patterns}
    FAILED patterns:  #{@failed_patterns}

    Total files:      #{@completed_files}
    New files:        #{@new_files}
    Changed files:    #{@changed_files}
    FAILED files:     #{@failed_files}

    ERRORS:           #{@errors}
  END
end