1*387f9dfdSAndroid Build Coastguard WorkerDemonstrations of ugc. 2*387f9dfdSAndroid Build Coastguard Worker 3*387f9dfdSAndroid Build Coastguard Worker 4*387f9dfdSAndroid Build Coastguard Workerugc traces garbage collection events in high-level languages, including Java, 5*387f9dfdSAndroid Build Coastguard WorkerPython, Ruby, and Node. Each GC event is printed with some additional 6*387f9dfdSAndroid Build Coastguard Workerinformation provided by that language's runtime, if available. The duration of 7*387f9dfdSAndroid Build Coastguard Workerthe GC event is also provided. 8*387f9dfdSAndroid Build Coastguard Worker 9*387f9dfdSAndroid Build Coastguard WorkerFor example, to trace all garbage collection events in a specific Node process: 10*387f9dfdSAndroid Build Coastguard Worker 11*387f9dfdSAndroid Build Coastguard Worker# ugc $(pidof node) 12*387f9dfdSAndroid Build Coastguard WorkerTracing garbage collections in node process 30012... Ctrl-C to quit. 13*387f9dfdSAndroid Build Coastguard WorkerSTART TIME (us) DESCRIPTION 14*387f9dfdSAndroid Build Coastguard Worker1.500 1181.00 GC scavenge 15*387f9dfdSAndroid Build Coastguard Worker1.505 1704.00 GC scavenge 16*387f9dfdSAndroid Build Coastguard Worker1.509 1534.00 GC scavenge 17*387f9dfdSAndroid Build Coastguard Worker1.515 1953.00 GC scavenge 18*387f9dfdSAndroid Build Coastguard Worker1.519 2155.00 GC scavenge 19*387f9dfdSAndroid Build Coastguard Worker1.525 2055.00 GC scavenge 20*387f9dfdSAndroid Build Coastguard Worker1.530 2164.00 GC scavenge 21*387f9dfdSAndroid Build Coastguard Worker1.536 2170.00 GC scavenge 22*387f9dfdSAndroid Build Coastguard Worker1.541 2237.00 GC scavenge 23*387f9dfdSAndroid Build Coastguard Worker1.547 1982.00 GC scavenge 24*387f9dfdSAndroid Build Coastguard Worker1.551 2333.00 GC scavenge 25*387f9dfdSAndroid Build Coastguard Worker1.557 2043.00 GC scavenge 26*387f9dfdSAndroid Build Coastguard Worker1.561 2028.00 GC scavenge 27*387f9dfdSAndroid Build Coastguard Worker1.573 3650.00 GC scavenge 28*387f9dfdSAndroid Build Coastguard Worker1.580 4443.00 GC scavenge 29*387f9dfdSAndroid Build Coastguard Worker1.604 6236.00 GC scavenge 30*387f9dfdSAndroid Build Coastguard Worker1.615 8324.00 GC scavenge 31*387f9dfdSAndroid Build Coastguard Worker1.659 11249.00 GC scavenge 32*387f9dfdSAndroid Build Coastguard Worker1.678 16084.00 GC scavenge 33*387f9dfdSAndroid Build Coastguard Worker1.747 15250.00 GC scavenge 34*387f9dfdSAndroid Build Coastguard Worker1.937 191.00 GC incremental mark 35*387f9dfdSAndroid Build Coastguard Worker2.001 63120.00 GC mark-sweep-compact 36*387f9dfdSAndroid Build Coastguard Worker3.185 153.00 GC incremental mark 37*387f9dfdSAndroid Build Coastguard Worker3.207 20847.00 GC mark-sweep-compact 38*387f9dfdSAndroid Build Coastguard Worker^C 39*387f9dfdSAndroid Build Coastguard Worker 40*387f9dfdSAndroid Build Coastguard WorkerThe above output shows some fairly long GCs, notably around 2 seconds in there 41*387f9dfdSAndroid Build Coastguard Workeris a collection that takes over 60ms (mark-sweep-compact). 42*387f9dfdSAndroid Build Coastguard Worker 43*387f9dfdSAndroid Build Coastguard WorkerOccasionally, it might be useful to filter out collections that are very short, 44*387f9dfdSAndroid Build Coastguard Workeror display only collections that have a specific description. The -M and -F 45*387f9dfdSAndroid Build Coastguard Workerswitches can be useful for this: 46*387f9dfdSAndroid Build Coastguard Worker 47*387f9dfdSAndroid Build Coastguard Worker# ugc -F Tenured $(pidof java) 48*387f9dfdSAndroid Build Coastguard WorkerTracing garbage collections in java process 29907... Ctrl-C to quit. 49*387f9dfdSAndroid Build Coastguard WorkerSTART TIME (us) DESCRIPTION 50*387f9dfdSAndroid Build Coastguard Worker0.360 4309.00 MarkSweepCompact Tenured Gen used=287528->287528 max=173408256->173408256 51*387f9dfdSAndroid Build Coastguard Worker2.459 4232.00 MarkSweepCompact Tenured Gen used=287528->287528 max=173408256->173408256 52*387f9dfdSAndroid Build Coastguard Worker4.648 4139.00 MarkSweepCompact Tenured Gen used=287528->287528 max=173408256->173408256 53*387f9dfdSAndroid Build Coastguard Worker^C 54*387f9dfdSAndroid Build Coastguard Worker 55*387f9dfdSAndroid Build Coastguard Worker# ugc -M 1 $(pidof java) 56*387f9dfdSAndroid Build Coastguard WorkerTracing garbage collections in java process 29907... Ctrl-C to quit. 57*387f9dfdSAndroid Build Coastguard WorkerSTART TIME (us) DESCRIPTION 58*387f9dfdSAndroid Build Coastguard Worker0.160 3715.00 MarkSweepCompact Code Cache used=287528->3209472 max=173408256->251658240 59*387f9dfdSAndroid Build Coastguard Worker0.160 3975.00 MarkSweepCompact Metaspace used=287528->3092104 max=173408256->18446744073709551615 60*387f9dfdSAndroid Build Coastguard Worker0.160 4058.00 MarkSweepCompact Compressed Class Space used=287528->266840 max=173408256->1073741824 61*387f9dfdSAndroid Build Coastguard Worker0.160 4110.00 MarkSweepCompact Eden Space used=287528->0 max=173408256->69337088 62*387f9dfdSAndroid Build Coastguard Worker0.160 4159.00 MarkSweepCompact Survivor Space used=287528->0 max=173408256->8650752 63*387f9dfdSAndroid Build Coastguard Worker0.160 4207.00 MarkSweepCompact Tenured Gen used=287528->287528 max=173408256->173408256 64*387f9dfdSAndroid Build Coastguard Worker0.160 4289.00 used=0->0 max=0->0 65*387f9dfdSAndroid Build Coastguard Worker^C 66*387f9dfdSAndroid Build Coastguard Worker 67*387f9dfdSAndroid Build Coastguard Worker 68*387f9dfdSAndroid Build Coastguard WorkerUSAGE message: 69*387f9dfdSAndroid Build Coastguard Worker 70*387f9dfdSAndroid Build Coastguard Worker# ugc -h 71*387f9dfdSAndroid Build Coastguard Workerusage: ugc.py [-h] [-l {java,python,ruby,node}] [-v] [-m] [-M MINIMUM] 72*387f9dfdSAndroid Build Coastguard Worker [-F FILTER] 73*387f9dfdSAndroid Build Coastguard Worker pid 74*387f9dfdSAndroid Build Coastguard Worker 75*387f9dfdSAndroid Build Coastguard WorkerSummarize garbage collection events in high-level languages. 76*387f9dfdSAndroid Build Coastguard Worker 77*387f9dfdSAndroid Build Coastguard Workerpositional arguments: 78*387f9dfdSAndroid Build Coastguard Worker pid process id to attach to 79*387f9dfdSAndroid Build Coastguard Worker 80*387f9dfdSAndroid Build Coastguard Workeroptional arguments: 81*387f9dfdSAndroid Build Coastguard Worker -h, --help show this help message and exit 82*387f9dfdSAndroid Build Coastguard Worker -l {java,python,ruby,node}, --language {java,python,ruby,node} 83*387f9dfdSAndroid Build Coastguard Worker language to trace 84*387f9dfdSAndroid Build Coastguard Worker -v, --verbose verbose mode: print the BPF program (for debugging 85*387f9dfdSAndroid Build Coastguard Worker purposes) 86*387f9dfdSAndroid Build Coastguard Worker -m, --milliseconds report times in milliseconds (default is microseconds) 87*387f9dfdSAndroid Build Coastguard Worker -M MINIMUM, --minimum MINIMUM 88*387f9dfdSAndroid Build Coastguard Worker display only GCs longer than this many milliseconds 89*387f9dfdSAndroid Build Coastguard Worker -F FILTER, --filter FILTER 90*387f9dfdSAndroid Build Coastguard Worker display only GCs whose description contains this text 91*387f9dfdSAndroid Build Coastguard Worker 92*387f9dfdSAndroid Build Coastguard Workerexamples: 93*387f9dfdSAndroid Build Coastguard Worker ./ugc -l java 185 # trace Java GCs in process 185 94*387f9dfdSAndroid Build Coastguard Worker ./ugc -l ruby 1344 -m # trace Ruby GCs reporting in ms 95*387f9dfdSAndroid Build Coastguard Worker ./ugc -M 10 -l java 185 # trace only Java GCs longer than 10ms 96