Class: PmdTester::JfrSummary

Inherits:
Object
  • Object
show all
Defined in:
lib/pmdtester/jfr_summary.rb

Overview

This class reads a jfr recording and extract a summary

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeJfrSummary

Returns a new instance of JfrSummary.



10
11
12
13
14
15
16
# File 'lib/pmdtester/jfr_summary.rb', line 10

def initialize
  @execution_time = 0
  @max_heap_memory = 0
  @max_cpu_load = 0
  @avg_cpu_load = 0
  @recording_path = ''
end

Instance Attribute Details

#avg_cpu_loadObject

Returns the value of attribute avg_cpu_load.



8
9
10
# File 'lib/pmdtester/jfr_summary.rb', line 8

def avg_cpu_load
  @avg_cpu_load
end

#execution_timeObject

Returns the value of attribute execution_time.



8
9
10
# File 'lib/pmdtester/jfr_summary.rb', line 8

def execution_time
  @execution_time
end

#max_cpu_loadObject

Returns the value of attribute max_cpu_load.



8
9
10
# File 'lib/pmdtester/jfr_summary.rb', line 8

def max_cpu_load
  @max_cpu_load
end

#max_heap_memoryObject

Returns the value of attribute max_heap_memory.



8
9
10
# File 'lib/pmdtester/jfr_summary.rb', line 8

def max_heap_memory
  @max_heap_memory
end

#recording_pathObject

Returns the value of attribute recording_path.



8
9
10
# File 'lib/pmdtester/jfr_summary.rb', line 8

def recording_path
  @recording_path
end

Class Method Details

.from_h(hash) ⇒ Object



59
60
61
62
63
64
65
66
67
# File 'lib/pmdtester/jfr_summary.rb', line 59

def self.from_h(hash)
  jfr_summary = JfrSummary.new
  jfr_summary.execution_time = hash[:execution_time] || 0
  jfr_summary.max_heap_memory = hash[:max_heap_memory] || 0
  jfr_summary.max_cpu_load = hash[:max_cpu_load] || 0
  jfr_summary.avg_cpu_load = hash[:avg_cpu_load] || 0
  jfr_summary.recording_path = hash[:recording_path] || ''
  jfr_summary
end

Instance Method Details

#load(jfr_recording) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/pmdtester/jfr_summary.rb', line 18

def load(jfr_recording)
  @recording_path = jfr_recording
  start_time = get_start_time(jfr_recording)
  end_time = get_end_time(jfr_recording)
  @execution_time = end_time - start_time

  gc_heap_summary = get_gc_heap_summary(jfr_recording)
  unless gc_heap_summary.empty?
    @max_heap_memory = gc_heap_summary.map do |e|
      e.dig(:values, :heapUsed)
    end.max
  end

  cpu_load = get_cpu_load(jfr_recording)
  unless cpu_load.empty?
    @max_cpu_load = cpu_load.map { |e| e.dig(:values, :jvmUser) }.max
    @avg_cpu_load = cpu_load.map { |e| e.dig(:values, :jvmUser) }.sum / cpu_load.size
  end

  self
end

#to_hObject



40
41
42
43
44
45
46
47
48
# File 'lib/pmdtester/jfr_summary.rb', line 40

def to_h
  {
    execution_time: @execution_time,
    max_heap_memory: @max_heap_memory,
    max_cpu_load: @max_cpu_load,
    avg_cpu_load: @avg_cpu_load,
    recording_path: @recording_path
  }
end

#to_h_for_liquidObject



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

def to_h_for_liquid
  {
    'execution_time' => PmdReportDetail.convert_seconds(@execution_time),
    'max_heap_memory' => format_memory(@max_heap_memory),
    'max_cpu_load' => format_percentage(@max_cpu_load),
    'avg_cpu_load' => format_percentage(@avg_cpu_load)
  }
end