~vcs-imports/busybox/trunk

« back to all changes in this revision

Viewing changes to procps/nmeter.c

  • Committer: Denys Vlasenko
  • Author(s): Roger Knecht
  • Date: 2022-06-30 15:18:12 UTC
  • Revision ID: git-v1:20a4f70ecaad79bb932af09b7317a058872cd867
tree: new applet

Adds the tree program to list directories and files in a tree structure.

function                                             old     new   delta
tree_print                                             -     343    +343
scandir64                                              -     330    +330
scandir                                                -     330    +330
tree_main                                              -      86     +86
.rodata                                           105150  105228     +78
packed_usage                                       34511   34557     +46
alphasort64                                            -      31     +31
alphasort                                              -      31     +31
strcoll                                                -       5      +5
applet_names                                        2801    2806      +5
applet_main                                         1616    1620      +4
applet_suid                                          101     102      +1
applet_install_loc                                   202     203      +1
------------------------------------------------------------------------------
(add/remove: 11/0 grow/shrink: 6/0 up/down: 1291/0)          Total: 1291 bytes

Signed-off-by: Roger Knecht <rknecht@pm.me>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
 * Contact me: vda.linux@googlemail.com
7
7
 */
8
8
//config:config NMETER
9
 
//config:       bool "nmeter (12 kb)"
 
9
//config:       bool "nmeter (11 kb)"
10
10
//config:       default y
11
11
//config:       help
12
12
//config:       Prints selected system stats continuously, one line per update.
59
59
 
60
60
typedef unsigned long long ullong;
61
61
 
62
 
enum {
 
62
enum {  /* Preferably use powers of 2 */
63
63
        PROC_MIN_FILE_SIZE = 256,
64
 
        PROC_MAX_FILE_SIZE = 64 * 1024, /* 16k was a bit too small for a 128-CPU machine */
 
64
        PROC_MAX_FILE_SIZE = 16 * 1024,
65
65
};
66
66
 
67
67
typedef struct proc_file {
176
176
        close(fd);
177
177
        if (rdsz > 0) {
178
178
                if (rdsz == sz-1 && sz < PROC_MAX_FILE_SIZE) {
179
 
                        if (sz < 4 * 1024)
180
 
                                sz *= 2;
181
 
                        else
182
 
                                sz += 4 * 1024;
 
179
                        sz *= 2;
183
180
                        buf = xrealloc(buf, sz);
184
181
                        goto again;
185
182
                }
518
515
                return;
519
516
        }
520
517
 
521
 
        for (i = 0; i < 2; i++) {
 
518
        for (i=0; i<2; i++) {
522
519
                ullong old = s->old[i];
523
520
                if (data[i] < old) old = data[i];               //sanitize
524
521
                s->old[i] = data[i];
600
597
                return;
601
598
        }
602
599
 
603
 
        for (i = 0; i < 4; i++) {
 
600
        for (i=0; i<4; i++) {
604
601
                ullong old = s->old[i];
605
602
                if (data[i] < old) old = data[i];               //sanitize
606
603
                s->old[i] = data[i];
985
982
 
986
983
        xgettimeofday(&G.start);
987
984
        G.tv = G.start;
988
 
 
989
 
        // Move back start of monotonic time a bit, to syncronize fractionals of %T and %t:
990
 
        // nmeter -d500 '%6T %6t'
991
 
        // 00:00:00.000161 12:32:07.500161
992
 
        // 00:00:00.500282 12:32:08.000282
993
 
        // 00:00:01.000286 12:32:08.500286
994
 
        if (G.delta > 0)
995
 
                G.start.tv_usec -= (G.start.tv_usec % (unsigned)G.delta);
996
 
 
997
985
        while (1) {
998
986
                collect_info(first);
999
987
                put_c(G.final_char);
1008
996
                        int rem;
1009
997
                        // can be commented out, will sacrifice sleep time precision a bit
1010
998
                        xgettimeofday(&G.tv);
1011
 
 
1012
 
        // TODO: nmeter -d10000 '%6T %6t'
1013
 
        // 00:00:00.770333 12:34:44.770333
1014
 
        // 00:00:06.000088 12:34:50.000088
1015
 
        // 00:00:16.000094 12:35:00.000094
1016
 
        // 00:00:26.000275 12:35:10.000275
1017
 
        // we can't syncronize interval to start close to 10 seconds for both
1018
 
        // %T and %t (as shown above), but what if there is only %T
1019
 
        // in format string? Maybe sync _it_ instead of %t in this case?
1020
999
                        if (need_seconds)
1021
1000
                                rem = G.delta - ((ullong)G.tv.tv_sec*1000000 + G.tv.tv_usec) % G.deltanz;
1022
1001
                        else