Commit Graph

120 Commits

Author SHA1 Message Date
Arnaldo Carvalho de Melo 1ec7e4aa18 [PAHOLE]: Dwarf trivia: show number of files that include a struct
[acme@newtoy guinea_pig-2.6]$ pahole -t ../../acme/OUTPUT/qemu/net-2.6/vmlinux | sort -k2 -nr | head -5
list_head                          468
__wait_queue_head                  466
timespec                           466
rw_semaphore                       466
plist_head                         466
[acme@newtoy guinea_pig-2.6]$

Which leads to another, more non-trivia question, what if a struct
definition is included but there are no references to this function?

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-11-03 20:24:37 -03:00
Arnaldo Carvalho de Melo 784968cca1 [PFUNCT]: Add a header with the columns names
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-11-03 19:47:07 -03:00
Arnaldo Carvalho de Melo 05ca190f25 [PFUNCT]: Introduce --total_inline_stats
Top 10 inline functions expanded more than once by sum of its expansions,
columns are (name, nr expansions, sum of expansions, nr source files where
expansions ocurred):

[acme@newtoy guinea_pig-2.6]$ pfunct --total_inline_stats ../../acme/OUTPUT/qemu/net-2.6/vmlinux | grep -v ': 1 ' | sort -k3 -nr | head -10
get_current                        676   5732 155
xfrm_selector_match                  6   4778   2
__memcpy                           177   4326  89
kmalloc                            185   3991 119
__constant_c_memset                113   3556  69
__constant_c_and_count_memset      225   3161 156
prefetch                           333   2915 101
__ext3_journal_dirty_metadata       44   2810   6
skb_put                             34   2650  27
module_put                          80   2613  42
[acme@newtoy guinea_pig-2.6]$

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-11-03 16:14:25 -03:00
Arnaldo Carvalho de Melo 2124d4f375 [PFUNCT]: Improve --cu_inline_expansions_stats
Now it shows the number that each of the inline functions were expanded in an
object file:

Top 10 inline functions expanded more than once in kernel/sched.o, by total
size of inline expansions:

[acme@newtoy guinea_pig-2.6]$ pfunct --cu_inline_expansions_stats kernel/sched.o | sort -k3 -nr | grep -v ': 1 ' | head -11
kernel/sched.c: 318 10217
get_current: 38 325
finish_task_switch: 2 238
normal_prio: 2 167
__cpus_and: 14 164
find_process_by_pid: 6 152
current_thread_info: 21 149
sched_find_first_bit: 2 148
update_cpu_clock: 2 140
task_rq_unlock: 14 137
variable_test_bit: 14 121
[acme@newtoy guinea_pig-2.6]$

Now we have these options:

[acme@newtoy guinea_pig-2.6]$ pfunct --help
usage: pfunct [options] <file_name> {<function_name>}
 where:
   -c, --class=<class>               functions that have <class> pointer parameters
   -g, --goto_labels                 show number of goto labels
   -i, --show_inline_expansions      show inline expansions
   -C, --cu_inline_expansions_stats  show CU inline expansions stats
   -s, --sizes                       show size of functions
   -N, --function_name_len           show size of functions
   -p, --nr_parameters               show number or parameters
   -S, --variables                   show number of variables
   -V, --verbose                     be verbose
[acme@newtoy guinea_pig-2.6]$

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-11-03 15:22:12 -03:00
Arnaldo Carvalho de Melo dcfe27a7ef [PFUNCT]: Do per CU inline statistics
Top five object files (CU, Compilation Unit) per number of inline expansions,
vmlinux being dissected is one built for QEMU, most things as modules, that
are not being taken into account as we're only looking at vmlinux:

[acme@newtoy guinea_pig-2.6]$ pfunct -C ../../acme/OUTPUT/qemu/net-2.6/vmlinux | sort -k2 -nr | head -5 | cut -c40-
net/ipv4/tcp_input.c: 274 20655
fs/buffer.c: 272 4597
kernel/sched.c: 214 3549
kernel/signal.c: 196 2730
fs/ext3/inode.c: 191 7961
[acme@newtoy guinea_pig-2.6]$

Top five object files (CU, Compilation Unit) per total size of inline expansions:

[acme@newtoy guinea_pig-2.6]$ pfunct -C ../../acme/OUTPUT/qemu/net-2.6/vmlinux | sort -k3 -nr | head -5 | cut -c40-
net/ipv4/tcp_input.c: 274 20655
net/xfrm/xfrm_policy.c: 173 11511
kernel/module.c: 95 10826
drivers/char/vt.c: 91 10050
net/xfrm/xfrm_user.c: 150 9682
[acme@newtoy guinea_pig-2.6]$

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-11-03 14:38:43 -03:00
Johannes Berg 0330fb5d34 Corrects a few problems because dwarf libs use 64-bit types and we didn't.
Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-11-03 14:32:32 -03:00
Arnaldo Carvalho de Melo a42afe1acf [CLASSES]: Add support for DW_TAG_inlined_subroutine
Output of pfunct using this information (all for a make allyesconfig build):

Top 5 functions by size of inlined functions in net/ipv4:

[acme@newtoy guinea_pig-2.6]$ pfunct -I net/ipv4/built-in.o | sort -k3 -nr | head -5
ip_route_input: 19 7086
tcp_ack: 33 6415
do_ip_vs_set_ctl: 23 4193
q931_help: 8 3822
ip_defrag: 19 3318
[acme@newtoy guinea_pig-2.6]$

And by number of inline expansions:

[acme@newtoy guinea_pig-2.6]$ pfunct -I net/ipv4/built-in.o | sort -k2 -nr | head -5
dump_packet: 35 905
tcp_v4_rcv: 34 1773
tcp_recvmsg: 34 928
tcp_ack: 33 6415
tcp_rcv_established: 31 1195
[acme@newtoy guinea_pig-2.6]$

And the list of expansions on a specific function:

[acme@newtoy guinea_pig-2.6]$ pfunct -i net/ipv4/built-in.o tcp_v4_rcv
/* net/ipv4/tcp_ipv4.c:1054 */
int tcp_v4_rcv(struct sk_buff * skb);
/* size: 2189, variables: 8, goto labels: 6, inline expansions: 34 (1773 bytes) */

/* inline expansions in tcp_v4_rcv:
current_thread_info: 8
pskb_may_pull: 36
pskb_may_pull: 29
tcp_v4_checksum_init: 139
__fswab32: 2
__fswab32: 2
inet_iif: 12
__inet_lookup: 292
__fswab16: 20
inet_ehashfn: 25
inet_ehash_bucket: 18
prefetch: 4
prefetch: 4
prefetch: 4
sock_hold: 4
xfrm4_policy_check: 59
nf_reset: 66
sk_filter: 135
__skb_trim: 20
get_softnet_dma: 68
tcp_prequeue: 257
sk_add_backlog: 40
sock_put: 27
xfrm4_policy_check: 46
tcp_checksum_complete: 29
current_thread_info: 8
sock_put: 20
xfrm4_policy_check: 50
tcp_checksum_complete: 29
current_thread_info: 8
inet_iif: 9
inet_lookup_listener: 36
inet_twsk_put: 114
tcp_v4_timewait_ack: 153
*/
[acme@newtoy guinea_pig-2.6]$

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-11-03 12:41:19 -03:00
Arnaldo Carvalho de Melo 7896f67c95 [CLASSES]: Initial support for DW_TAG_lexical_block
For now we just discard it so that all the variables in a function can be
accounted, but the right thing, as said in the comment added in this cset is to
have a list of lexical blocks, each with a list of its variables so that we can
find the biggest stack usage in functions.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-11-02 15:53:39 -03:00
Arnaldo Carvalho de Melo 97385598a6 [CLASSES]: Use strdup for the ->name members
Reducing the memory footprint, but more has to be done, such as to take
advantage of the strings table when handling indirect strings.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-11-02 13:48:35 -03:00
Arnaldo Carvalho de Melo 6b82eae556 [PAHOLE]: getopt support
With some of the options in pfunct, such as:

[acme@newtoy guinea_pig-2.6]$ pahole --sizes kernel/sched.o | sort -k2 -nr | head -5
pglist_data: 3456
task_struct: 2704
rq: 2480
mmu_gather: 2040
zone: 1664
[acme@newtoy guinea_pig-2.6]$

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-11-02 13:47:37 -03:00
Arnaldo Carvalho de Melo 683428ee16 [PFUNCT]: Add missing 'else'
And update the --help output.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-11-01 18:08:54 -03:00
Arnaldo Carvalho de Melo 800429032e [PFUNCT]: Implement --function_name_len
[acme@newtoy net-2.6]$ pfunct --function_name_len vmlinux | sort -k 2 -nr | head -5
attribute_container_add_class_device_adapter: 44
wait_for_completion_interruptible_timeout: 41
sparse_memory_present_with_active_regions: 41
attribute_container_classdev_to_container: 41
percpu_pagelist_fraction_sysctl_handler: 39
[acme@newtoy net-2.6]$

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-11-01 10:42:18 -03:00
Arnaldo Carvalho de Melo 09bb5df8aa [PFUNCT]: Implement --nr_parameters
[acme@newtoy net-2.6]$ pfunct --nr_parameters vmlinux | sort -k 2 -nr | head -5
__ide_add_setting: 13
ide_add_setting: 12
fib_dump_info: 12
__blockdev_direct_IO: 10
vma_merge: 9
[acme@newtoy net-2.6]$

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-11-01 10:34:42 -03:00
Arnaldo Carvalho de Melo 4a6117a912 [PFUNCT]: Introduce --help
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-11-01 10:29:31 -03:00
Arnaldo Carvalho de Melo eff5348081 Handle the DW_TAG_variable and DW_TAG_label tags, now we can do:
[acme@newtoy net-2.6]$ pfunct --variables vmlinux | sort -k 2 -nr | head -5
do_task_stat: 29
load_elf_binary: 28
elf_core_dump: 23
ext3_new_blocks: 21
sys_unshare: 19
[acme@newtoy net-2.6]$

And:

[acme@newtoy net-2.6]$ pfunct --goto_labels vmlinux | sort -k 2 -nr | head -5
copy_process: 16
sys_unshare: 10
device_add: 9
class_device_add: 8
tcp_sendmsg: 7
[acme@newtoy net-2.6]$

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-11-01 10:18:01 -03:00
Arnaldo Carvalho de Melo 5aaca80de6 [CLASSES]: Rework the find_by routines
So that we can find all the cus for some specific class
(cus__find_class_by_name), or traverse all the CUs (cus__for_each_cu),
etc.

Now we don't look at just the first CU in multi-CU files (vmlinux, etc).

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-10-31 17:23:16 -03:00
Arnaldo Carvalho de Melo 0ca9826e36 Introduce struct cu, i.e. a per compilation unit struct that holds the list of
types for each CU, for now when working on multi-CU files (vmlinux, any binary
with more than one object file linked) we look only at the first CU when
looking for a specific class or function name, this will be fixed in the
upcoming csets, but doesn't affect the case when we don't specify a class or
function name, where all the CU's are traversed.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-10-31 16:12:42 -03:00
Arnaldo Carvalho de Melo 19189046aa Use : as separator for decl_file:decl_line, suggested by martin
on irc 8)

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-10-30 15:24:32 -03:00
Arnaldo Carvalho de Melo 8f1d76d93a [PFUNCT]: Implement --size in pfunct
[acme@newtoy net-2.6]$ pfunct --size net/ipv4/netfilter/ip_conntrack.ko | sort -k 2 -nr | head -5
tcp_packet: 3349
ip_conntrack_in: 1146
icmp_error: 874
ip_conntrack_expect_related: 804
__ip_conntrack_confirm: 586
[acme@newtoy net-2.6]$

'nuff said :-)

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-10-30 15:15:09 -03:00
Arnaldo Carvalho de Melo 042c51dc1f Support DW_AT_low_pc and DW_AT_high_pc, now pfunct is able to do this:
[acme@newtoy net-2.6]$ pfunct kernel/sched.o schedule
/* /pub/scm/linux/kernel/git/acme/net-2.6/kernel/sched.c 3317 */
void schedule(void);
/* size: 1492 */

Cute, huh? :-)

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-10-30 14:22:39 -03:00
Arnaldo Carvalho de Melo f204c370ed Move the attr functions that are needed only by class__new or class_member__new
to where they are needed.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-10-30 13:37:04 -03:00
Arnaldo Carvalho de Melo 3dfd363868 Add getopt support in pfunct, options implemented should be self explaining,
except for --classes, that asks that all non-inlined functions that receive as
one of its parameter a pointer to the specified class be printed, just the name
if --verbose is not used, or its complete prototype and where it is in the
source code:

[acme@newtoy net-2.6]$ pfunct --verbose --class=inode fs/ext3/built-in.o
/* /pub/scm/linux/kernel/git/acme/net-2.6/fs/ext3/balloc.c 606 */
void ext3_free_blocks(handle_t * handle, struct inode * inode, ext3_fsblk_t block, long unsigned int count);

/* /pub/scm/linux/kernel/git/acme/net-2.6/fs/ext3/balloc.c 1404 */
ext3_fsblk_t ext3_new_blocks(handle_t * handle, struct inode * inode, ext3_fsblk_t goal, long unsigned int * count, int * errp);

/* /pub/scm/linux/kernel/git/acme/net-2.6/fs/ext3/balloc.c 1668 */
ext3_fsblk_t ext3_new_block(handle_t * handle, struct inode * inode, ext3_fsblk_t goal, int * errp);

/* /pub/scm/linux/kernel/git/acme/net-2.6/fs/ext3/balloc.c 346 */
void ext3_init_block_alloc_info(struct inode * inode);

/* /pub/scm/linux/kernel/git/acme/net-2.6/fs/ext3/balloc.c 388 */
void ext3_discard_reservation(struct inode * inode);

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-10-29 00:41:48 -03:00
Arnaldo Carvalho de Melo 6b32c8362b Introduce classes__for_each, that receives an iterator function and a cookie,
so that one can traverse all the classes loaded by classes__load.

Also export classes__find_by_id().

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-10-28 23:55:56 -03:00
Arnaldo Carvalho de Melo 67b12e237c Support DW_AT_inline, that only makes sense on functions, where now we
see that the function was indeed inlined:

[acme@newtoy net-2.6]$ pfunct kernel/sched.o task_running
/* /pub/scm/linux/kernel/git/acme/net-2.6/kernel/sched.c 304 */
inline int task_running(struct rq * rq, struct task_struct * p);

[acme@newtoy net-2.6]$

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-10-28 21:40:35 -03:00
Arnaldo Carvalho de Melo d23a3a6e64 Print the decl file and line at class__print, not at class__print_struct, that
way we get it for free for the upcoming types, as class__print_function got
now.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-10-28 19:13:27 -03:00
Arnaldo Carvalho de Melo e038f068b1 New dwarf: pfunct, see it in action:
[acme@newtoy net-2.6]$ pfunct ~acme/work/atag/atag | grep LRMI
void * LRMI_alloc_real(int size);
void LRMI_free_real(void * m);
int LRMI_init(void);
void set_regs(struct LRMI_regs * r);
void get_regs(struct LRMI_regs * r);
int LRMI_call(struct LRMI_regs * r);
int LRMI_int(int i, struct LRMI_regs * r);
[acme@newtoy net-2.6]$

[acme@newtoy net-2.6]$ pfunct kernel/sched.o task_running
int task_running(struct rq * rq, struct task_struct * p);
[acme@newtoy net-2.6]$

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-10-28 19:07:45 -03:00
Arnaldo Carvalho de Melo d0df41c935 Support DW_TAG_formal_parameter, that gets into the struct class members list,
i.e. the list of parameters of a function (DW_TAG_subprogram).

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-10-28 19:04:40 -03:00
Arnaldo Carvalho de Melo f9ed05bd42 Initial implementation of class__print_function, now to get the list
of DW_AT_formal_parameters and then print it.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-10-28 18:49:27 -03:00
Arnaldo Carvalho de Melo e61005ee82 Only structs have holes, not, for instance, DW_AT_subprogram entries,
aka functions.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-10-28 18:37:38 -03:00
Arnaldo Carvalho de Melo 35e87417f9 Move the classes methods out of pahole.c and into classes.c,
that will be used by other new dwarves 8)

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-10-28 18:22:42 -03:00
Arnaldo Carvalho de Melo f4cc126c11 Separate finding the holes from printing the class, so that we are able to
print just the structs with holes, that indeed is what we do now if no class
name is passed.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-10-28 18:10:47 -03:00
Arnaldo Carvalho de Melo 01f021b2a7 Prefix the functions that create the classes list with "classes__",
in preparation to moving them to a library.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-10-28 14:16:29 -03:00
Arnaldo Carvalho de Melo 06672633cb Move the top level dwarf traversal of the CUs to a new function,
classes__load().

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-10-28 14:08:46 -03:00
Arnaldo Carvalho de Melo 13ec307479 Move the global 'bf' buffer to the only place still using it.
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-10-28 13:51:34 -03:00
Arnaldo Carvalho de Melo 3593eb45a6 Move the class and class_member structs to a new header file,
classes.h.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-10-28 13:45:59 -03:00
Arnaldo Carvalho de Melo 5c3d14ac09 Renane class__print to class__print_struct and make class__print
call it if the class ->tag is DW_TAG_structure_type, and do a basic
print for the other tags.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-10-28 13:37:20 -03:00
Arnaldo Carvalho de Melo 7f5ce05961 Initialize struct class->name in the constructor if no name was
informed.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-10-28 13:16:59 -03:00
Arnaldo Carvalho de Melo 23cc5e41cb Get the file and line where the classes were declared and use it
in the printout.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-10-28 09:52:08 -03:00
Arnaldo Carvalho de Melo 98295e3fd2 Improve attr_numeric to handle more form types, convering DW_AT_type,
etc, so ditch attr_type().

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-10-27 17:51:18 -03:00
Arnaldo Carvalho de Melo 7dbb993d8b Rename attr_unsigned to attr_numeric, simplifying it to not require a
Dwarf_Attribute to work on, as we just return a integer and it handles more
than just unsigned ints.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-10-27 15:04:18 -03:00
Arnaldo Carvalho de Melo 0c707643d7 Print the number of holes
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-10-26 03:31:58 -03:00
Arnaldo Carvalho de Melo d36e7147f0 Stop using libdwarf from SGI, use the one in elfutils instead, the code got
much cleaner and now uses what seems to be a better maintained DWARF library
that hopefully works well on 64bit platforms, well see.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-10-26 03:06:32 -03:00
Arnaldo Carvalho de Melo e5e7c6fc8b Initialize nr_entries in class__new
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-10-25 15:21:34 -03:00
Arnaldo Carvalho de Melo 17025a38f2 Handle multi CU (Compile Unit) files, like vmlinux :-)
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-10-25 14:33:59 -03:00
Arnaldo Carvalho de Melo aac0259cc0 Use return for consistency in main.
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-10-25 14:03:44 -03:00
Arnaldo Carvalho de Melo 3acc236241 Support void pointers, i.e. DW_TAG_pointer_type with no DW_AT_type.
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-10-25 13:47:54 -03:00
Arnaldo Carvalho de Melo 4881c2f0d2 Add a .gitignore file
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-10-25 13:32:07 -03:00
Arnaldo Carvalho de Melo 134120b796 Ditch the program_name variable, use "pahole" directly
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-10-25 13:29:38 -03:00
Arnaldo Carvalho de Melo e01a32fddc Remove leftover check_error variable.
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-10-25 13:20:18 -03:00
Arnaldo Carvalho de Melo 2338691b42 Show the sum of the members sizeof only if there are holes, and if so print the
sum of all holes too.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-10-25 13:18:43 -03:00