[PATCH 2/2] pstree: New applet, v6

Denys Vlasenko vda.linux at googlemail.com
Sun Dec 5 04:05:00 UTC 2010


On Friday 03 December 2010 18:01, Lauri Kasanen wrote:
> Morning.
> 
> After finally managing to understand the uhm.. nice function procps_scan, I could drop ~700 bytes from pstree. Adding the -p option (from Eric) adds back ~100 bytes.
> 
> Thus, v6 is ~600 bytes smaller than v5. I'm afraid I'm out of obvious and non-obvious size reduction targets now, though.
> 
> 
> v6:
> - shrink by removing out_int
> - size shrink by replacing read_proc with procps_scan
> 	It was possible afterall ;) but only after the separation of check_thread.
> - shrink: move thread check to procps_scan
> - wrap unicode support in out_char in ENABLE_UNICODE
> - support the -p option (Eric Lammerts)
> 
> function                                             old     new   delta
> dump_tree                                              -     802    +802
> pstree_main                                            -     449    +449
> add_proc                                               -     221    +221
> .rodata                                             8867    9023    +156
> dump_by_user                                           -     111    +111
> tree_equal                                             -     105    +105
> new_proc                                               -      83     +83
> out_newline                                            -      61     +61
> static.C                                               -      48     +48
> out_char                                               -      41     +41
> procps_scan                                         1175    1211     +36
> packed_usage                                        1034    1060     +26
> out_string                                             -      25     +25
> find_proc                                              -      24     +24
> applet_main                                           80      88      +8
> applet_names                                          61      68      +7
> applet_nameofs                                        20      22      +2
> ------------------------------------------------------------------------------
> (add/remove: 12/1 grow/shrink: 6/0 up/down: 2205/0)          Total: 2205 bytes
>    text	   data	    bss	    dec	    hex	filename
>   69257	   1522	   8384	  79163	  1353b	busybox_old
>   71819	   1522	   8384	  81725	  13f3d	busybox_unstripped
> 
> The above output includes the previous patch to libbb. For reference, v5 was "Total: 2759 bytes" on my machine.

The "do not overflow screen" code is broken.
This is what I get in a small xterm window:

# ./busybox pstree -p   |-runsv(951)---svlogd(959)
init(1)-+-dcopserver(2114)
        |-kaccess(2130)
        |-kded(2120)
        |-kdeinit(2111)-+-kio_file(2144)
        |               |-klauncher(2117)
        |               |-konsole(2529)-+-bash(2530)---
mc(2531)---3599
        |               |               |-bash(3012)---
mc(3137
        |               |               `-bash(6172)
        |               `-kwin(2134)
        |-kdesktop(2136)
        |-kicker(2138)-+-ksysguardd(2142)
        |              `-sh(10859)---firefox-bin(10860)
-+-{firef10861
        |                                             1
0862
        |                                             1
0863
        |                                             1
0864
        |                                             1
0865
        |                                             1
0867
        |                                             1
0869
        |                                             1                                                                                                                           0870
        |                                             1                                                                                                                           0871
...

IOW: screed does overflow.


out_char() gets to great pains to handle unicode, but it never actually
get called with unicode characters. So it can be simplified.

+       if (G.cur_x <= G.output_width)
+               putchar(c);
+       else if (G.cur_x == G.output_width + 1)
+               putchar('+');

I believe here you meant "G.cur_x == G.output_width - 1".


struct sym_t is not needed, since you always use the same strings.


+       if (get_terminal_width_height(1,&w,NULL) == 0)
+               G.output_width = w;

You do not need to check return value here.



Please find two patches attached. After 7.patch:

   text    data     bss     dec     hex filename
 885539     936   17192  903667   dc9f3 busybox_old
 885411     936   17192  903539   dc973 busybox_unstripped

And after 8.patch, whiuch removes unused unicode stuff:

   text    data     bss     dec     hex filename
 885411     936   17192  903539   dc973 busybox_old
 885267     936   17192  903395   dc8e3 busybox_unstripped

Cumulative:

function                                             old     new   delta
dump_tree                                              -     674    +674
pstree_main                                            -     340    +340
add_proc                                               -     208    +208
dump_by_user                                           -     133    +133
out_char                                               -     115    +115
tree_equal                                             -      88     +88
out_newline                                            -      62     +62
procps_scan                                         1207    1268     +61
new_proc                                               -      57     +57
packed_usage                                       27971   28017     +46
find_proc                                              -      24     +24
out_string                                             -      22     +22
applet_names                                        2407    2414      +7
send_tree                                            369     374      +5
applet_main                                         1396    1400      +4
applet_nameofs                                       698     700      +2
------------------------------------------------------------------------------
(add/remove: 11/0 grow/shrink: 8/4 up/down: 1853/-33)        Total: 1820 bytes
   text    data     bss     dec     hex filename
 883379     936   17192  901507   dc183 busybox_old
 885267     936   17192  903395   dc8e3 busybox_unstripped

Please take a look at the patches.
-- 
vda
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 7.patch
Type: text/x-diff
Size: 11077 bytes
Desc: not available
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20101205/e937ab7a/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 8.patch
Type: text/x-diff
Size: 2119 bytes
Desc: not available
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20101205/e937ab7a/attachment-0001.bin>


More information about the busybox mailing list