xref: /aosp_15_r20/external/bcc/tools/lib/uobjnew_example.txt (revision 387f9dfdfa2baef462e92476d413c7bc2470293e)
1*387f9dfdSAndroid Build Coastguard WorkerDemonstrations of uobjnew.
2*387f9dfdSAndroid Build Coastguard Worker
3*387f9dfdSAndroid Build Coastguard Worker
4*387f9dfdSAndroid Build Coastguard Workeruobjnew summarizes new object allocation events and prints out statistics on
5*387f9dfdSAndroid Build Coastguard Workerwhich object type has been allocated frequently, and how many bytes of that
6*387f9dfdSAndroid Build Coastguard Workertype have been allocated. This helps diagnose common allocation paths, which
7*387f9dfdSAndroid Build Coastguard Workercan in turn cause heavy garbage collection.
8*387f9dfdSAndroid Build Coastguard Worker
9*387f9dfdSAndroid Build Coastguard WorkerFor example, trace Ruby object allocations when running some simple commands
10*387f9dfdSAndroid Build Coastguard Workerin irb (the Ruby REPL):
11*387f9dfdSAndroid Build Coastguard Worker
12*387f9dfdSAndroid Build Coastguard Worker# ./uobjnew -l ruby 27245
13*387f9dfdSAndroid Build Coastguard WorkerTracing allocations in process 27245 (language: ruby)... Ctrl-C to quit.
14*387f9dfdSAndroid Build Coastguard Worker
15*387f9dfdSAndroid Build Coastguard WorkerTYPE                           # ALLOCS      # BYTES
16*387f9dfdSAndroid Build Coastguard WorkerNameError                             1            0
17*387f9dfdSAndroid Build Coastguard WorkerRubyToken::TkSPACE                    1            0
18*387f9dfdSAndroid Build Coastguard WorkerRubyToken::TkSTRING                   1            0
19*387f9dfdSAndroid Build Coastguard WorkerString                                7            0
20*387f9dfdSAndroid Build Coastguard WorkerRubyToken::TkNL                       2            0
21*387f9dfdSAndroid Build Coastguard WorkerRubyToken::TkIDENTIFIER               2            0
22*387f9dfdSAndroid Build Coastguard Workerarray                                55          129
23*387f9dfdSAndroid Build Coastguard Workerstring                              344         1348
24*387f9dfdSAndroid Build Coastguard Worker^C
25*387f9dfdSAndroid Build Coastguard Worker
26*387f9dfdSAndroid Build Coastguard Worker
27*387f9dfdSAndroid Build Coastguard WorkerPlain C/C++ allocations (through "malloc") are also supported. We can't report
28*387f9dfdSAndroid Build Coastguard Workerthe type being allocated, but we can report the object sizes at least. Also,
29*387f9dfdSAndroid Build Coastguard Workerprint only the top 10 rows by number of bytes allocated:
30*387f9dfdSAndroid Build Coastguard Worker
31*387f9dfdSAndroid Build Coastguard Worker# ./uobjnew -S 10 -l c 27245
32*387f9dfdSAndroid Build Coastguard WorkerTracing allocations in process 27245 (language: c)... Ctrl-C to quit.
33*387f9dfdSAndroid Build Coastguard Worker
34*387f9dfdSAndroid Build Coastguard WorkerTYPE                           # ALLOCS      # BYTES
35*387f9dfdSAndroid Build Coastguard Workerblock size 64                        22         1408
36*387f9dfdSAndroid Build Coastguard Workerblock size 992                        2         1984
37*387f9dfdSAndroid Build Coastguard Workerblock size 32                        68         2176
38*387f9dfdSAndroid Build Coastguard Workerblock size 48                        48         2304
39*387f9dfdSAndroid Build Coastguard Workerblock size 944                        4         3776
40*387f9dfdSAndroid Build Coastguard Workerblock size 1104                       4         4416
41*387f9dfdSAndroid Build Coastguard Workerblock size 160                       32         5120
42*387f9dfdSAndroid Build Coastguard Workerblock size 535                       15         8025
43*387f9dfdSAndroid Build Coastguard Workerblock size 128                      112        14336
44*387f9dfdSAndroid Build Coastguard Workerblock size 80                       569        45520
45*387f9dfdSAndroid Build Coastguard Worker^C
46*387f9dfdSAndroid Build Coastguard Worker
47*387f9dfdSAndroid Build Coastguard Worker
48*387f9dfdSAndroid Build Coastguard WorkerUSAGE message:
49*387f9dfdSAndroid Build Coastguard Worker
50*387f9dfdSAndroid Build Coastguard Worker# ./uobjnew -h
51*387f9dfdSAndroid Build Coastguard Workerusage: uobjnew.py [-h] [-l {c,java,ruby,tcl}] [-C TOP_COUNT] [-S TOP_SIZE] [-v]
52*387f9dfdSAndroid Build Coastguard Worker                  pid [interval]
53*387f9dfdSAndroid Build Coastguard Worker
54*387f9dfdSAndroid Build Coastguard WorkerSummarize object allocations in high-level languages.
55*387f9dfdSAndroid Build Coastguard Worker
56*387f9dfdSAndroid Build Coastguard Workerpositional arguments:
57*387f9dfdSAndroid Build Coastguard Worker  pid                   process id to attach to
58*387f9dfdSAndroid Build Coastguard Worker  interval              print every specified number of seconds
59*387f9dfdSAndroid Build Coastguard Worker
60*387f9dfdSAndroid Build Coastguard Workeroptional arguments:
61*387f9dfdSAndroid Build Coastguard Worker  -h, --help            show this help message and exit
62*387f9dfdSAndroid Build Coastguard Worker  -l {c,java,ruby,tcl}, --language {c,java,ruby,tcl}
63*387f9dfdSAndroid Build Coastguard Worker                        language to trace
64*387f9dfdSAndroid Build Coastguard Worker  -C TOP_COUNT, --top-count TOP_COUNT
65*387f9dfdSAndroid Build Coastguard Worker                        number of most frequently allocated types to print
66*387f9dfdSAndroid Build Coastguard Worker  -S TOP_SIZE, --top-size TOP_SIZE
67*387f9dfdSAndroid Build Coastguard Worker                        number of largest types by allocated bytes to print
68*387f9dfdSAndroid Build Coastguard Worker  -v, --verbose         verbose mode: print the BPF program (for debugging
69*387f9dfdSAndroid Build Coastguard Worker                        purposes)
70*387f9dfdSAndroid Build Coastguard Worker
71*387f9dfdSAndroid Build Coastguard Workerexamples:
72*387f9dfdSAndroid Build Coastguard Worker    ./uobjnew -l java 145         # summarize Java allocations in process 145
73*387f9dfdSAndroid Build Coastguard Worker    ./uobjnew -l c 2020 1         # grab malloc() sizes and print every second
74*387f9dfdSAndroid Build Coastguard Worker    ./uobjnew -l ruby 6712 -C 10  # top 10 Ruby types by number of allocations
75*387f9dfdSAndroid Build Coastguard Worker    ./uobjnew -l ruby 6712 -S 10  # top 10 Ruby types by total size
76