public
Last active

  • Download Gist
1.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
system ~/projects/jruby $ jruby -J-Xmx1024m -J-Xmx1024m -Isrc gc_stress.rb
ID Type Timestamp(sec) Before(kB) After(kB) Delta(kB) Heap(kB) GC Time(ms)
2 PS Scavenge 1.5624 48541 31837 16703 108288 7.1670000000
3 PS Scavenge 1.7100 66597 32293 34304 108672 6.8490000000
4 PS Scavenge 1.7796 66797 32429 34368 143104 6.0990000000
5 PS Scavenge 1.8868 101293 32445 68847 143104 6.2590000000
6 PS Scavenge 1.9809 101309 32509 68800 215936 5.9520000000
7 PS Scavenge 2.2277 170258 32634 137623 216256 6.6460000000
8 PS Scavenge 2.4213 170363 32643 137720 354112 0.9190000000
9 PS Scavenge 2.8693 307971 32715 275256 354240 1.2110000000
10 PS Scavenge 3.2452 308043 32763 275280 413248 0.8170000000
11 PS Scavenge 3.7313 367355 32779 334576 413376 8.7480000000
12 PS Scavenge 4.1935 367373 32861 334512 413184 1.0410000000
13 PS Scavenge 4.6492 367773 32877 334896 413376 1.3070000000
14 PS Scavenge 5.1041 367789 32909 334880 390656 0.8960000000
15 PS Scavenge 5.5400 351950 32966 318984 381952 1.0860000000
16 PS Scavenge 5.9545 336902 33038 303864 361280 1.0890000000
17 PS Scavenge 6.3475 322638 33078 289560 353472 0.8990000000
18 PS Scavenge 6.7257 309046 33070 275976 334656 1.1730000000
19 PS Scavenge 7.0855 296110 33110 263000 327680 0.8610000000
20 PS Scavenge 7.4257 283862 33142 250720 310656 1.0370000000
21 PS Scavenge 7.7522 272182 33246 238936 304256 1.0740000000
ID Type Timestamp(sec) Before(kB) After(kB) Delta(kB) Heap(kB) GC Time(ms)
22 PS Scavenge 8.0626 261150 33230 227920 288960 1.0990000000
23 PS Scavenge 8.3588 250574 33246 217328 283136 0.9310000000
24 PS Scavenge 8.6422 240544 33392 207152 269440 1.3320000000
Total run time: 8.040000 0.140000 8.180000 ( 7.364000)
gc_profiler_report.diff
Diff
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 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 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
diff --git a/src/jruby/kernel19/gc.rb b/src/jruby/kernel19/gc.rb
index 0e0c18c..1376b66 100644
--- a/src/jruby/kernel19/gc.rb
+++ b/src/jruby/kernel19/gc.rb
@@ -58,28 +58,50 @@ module GC
end
module Profiler
+ java_import javax.management.NotificationListener
+ java_import com.sun.management.GarbageCollectionNotificationInfo
+
+ HEADER = " ID Type Timestamp(sec) Before(kB) After(kB) Delta(kB) Heap(kB) GC Time(ms) "
+ FORMAT = "%5d %-20s %19.4f %13i %13i %12i %15i %20.10f"
+
+ class GCListener
+ include NotificationListener
+
+ def initialize
+ @lines = []
+ end
+
+ attr_accessor :lines
+
+ def handleNotification(notification, o)
+ lines << notification
+ end
+
+ def clear
+ lines.clear
+ end
+ end
+
def self.enabled?
@gc_beans != nil
end
def self.enable
require 'java'
- @gc_beans ||= java.lang.management.ManagementFactory.garbage_collector_mx_beans
- clear
+ @gc_listener ||= GCListener.new
+ java.lang.management.ManagementFactory.garbage_collector_mx_beans.each do |gc_bean|
+ gc_bean.add_notification_listener @gc_listener, nil, nil
+ end
end
def self.disable
- @gc_beans = nil
+ java.lang.management.ManagementFactory.garbage_collector_mx_beans.each do |gc_bean|
+ gc_bean.remove_notification_listener @gc_listener
+ end
end
def self.clear
- return unless @gc_beans
-
- time = 0
- @gc_beans.each do |gc_bean|
- time += gc_bean.collection_time
- end
- @start_time = time
+ @gc_listener.clear
end
def self.result
@@ -87,7 +109,44 @@ module GC
end
def self.report
- nil
+ disable
+
+ @gc_listener.lines.each_with_index do |line, i|
+ puts HEADER if i % 20 == 0
+
+ gc_notification = GarbageCollectionNotificationInfo.from(line.user_data)
+ gc_info = gc_notification.gc_info
+
+ mem_before = gc_info.memory_usage_before_gc
+ mem_after = gc_info.memory_usage_after_gc
+
+ after = 0
+ before = 0
+ commit = 0
+
+ mem_after.entry_set.each do |entry|
+ name = entry.key
+
+ before_usage = mem_before[name]
+ before += before_usage.used
+
+ after_usage = entry.value
+ after += after_usage.used
+
+ commit += after_usage.committed
+ end
+
+ puts sprintf(
+ FORMAT,
+ gc_info.id,
+ gc_notification.gc_name,
+ gc_info.start_time/1000000.0,
+ before / 1024,
+ after / 1024,
+ (before - after) / 1024,
+ commit / 1024,
+ gc_info.duration/1000.0)
+ end
end
def self.total_time

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.