-
Notifications
You must be signed in to change notification settings - Fork 113
/
showprocs.c
2952 lines (2483 loc) · 78.1 KB
/
showprocs.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
** ATOP - System & Process Monitor
**
** The program 'atop' offers the possibility to view the activity of
** the system on system-level as well as cgroupess-level.
**
** This source-file contains the Linux-specific functions to calculate
** figures to be visualized on process/thread level and cgroup level.
** ==========================================================================
** Author: JC van Winkel - AT Computing, Nijmegen, Holland
** E-mail: [email protected]
** Date: November 2009
**
** Process level
** --------------------------------------------------------------------------
** Author: Gerlof Langeveld
** E-mail: [email protected]
** Date: January 2024
**
** Additions for cgroups
** --------------------------------------------------------------------------
**
** This program is free software; you can redistribute it and/or modify it
** under the terms of the GNU General Public License as published by the
** Free Software Foundation; either version 2, or (at your option) any
** later version.
**
** This program is distributed in the hope that it will be useful, but
** WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
** See the GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
** --------------------------------------------------------------------------
*/
#include <sys/types.h>
#include <sys/param.h>
#include <sys/stat.h>
#include <signal.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdarg.h>
#include <curses.h>
#include <regex.h>
#include "atop.h"
#include "photoproc.h"
#include "photosyst.h"
#include "cgroups.h"
#include "showgeneric.h"
#include "showlinux.h"
static void format_bandw(char *, count_t);
static void gettotwidth(detail_printpair *, int *, int *, int *);
static int *getspacings(detail_printpair *);
char *procprt_TID_ae(struct tstat *, int, int);
char *procprt_PID_a(struct tstat *, int, int);
char *procprt_PID_e(struct tstat *, int, int);
char *procprt_PPID_a(struct tstat *, int, int);
char *procprt_PPID_e(struct tstat *, int, int);
char *procprt_VPID_a(struct tstat *, int, int);
char *procprt_VPID_e(struct tstat *, int, int);
char *procprt_CTID_a(struct tstat *, int, int);
char *procprt_CTID_e(struct tstat *, int, int);
char *procprt_CID_a(struct tstat *, int, int);
char *procprt_CID_e(struct tstat *, int, int);
char *procprt_SYSCPU_ae(struct tstat *, int, int);
char *procprt_USRCPU_ae(struct tstat *, int, int);
char *procprt_VGROW_a(struct tstat *, int, int);
char *procprt_VGROW_e(struct tstat *, int, int);
char *procprt_RGROW_a(struct tstat *, int, int);
char *procprt_RGROW_e(struct tstat *, int, int);
char *procprt_MINFLT_ae(struct tstat *, int, int);
char *procprt_MAJFLT_ae(struct tstat *, int, int);
char *procprt_VSTEXT_a(struct tstat *, int, int);
char *procprt_VSTEXT_e(struct tstat *, int, int);
char *procprt_VSIZE_a(struct tstat *, int, int);
char *procprt_VSIZE_e(struct tstat *, int, int);
char *procprt_RSIZE_a(struct tstat *, int, int);
char *procprt_RSIZE_e(struct tstat *, int, int);
char *procprt_PSIZE_a(struct tstat *, int, int);
char *procprt_PSIZE_e(struct tstat *, int, int);
char *procprt_VSLIBS_a(struct tstat *, int, int);
char *procprt_VSLIBS_e(struct tstat *, int, int);
char *procprt_VDATA_a(struct tstat *, int, int);
char *procprt_VDATA_e(struct tstat *, int, int);
char *procprt_VSTACK_a(struct tstat *, int, int);
char *procprt_VSTACK_e(struct tstat *, int, int);
char *procprt_SWAPSZ_a(struct tstat *, int, int);
char *procprt_SWAPSZ_e(struct tstat *, int, int);
char *procprt_LOCKSZ_a(struct tstat *, int, int);
char *procprt_LOCKSZ_e(struct tstat *, int, int);
char *procprt_CMD_a(struct tstat *, int, int);
char *procprt_CMD_e(struct tstat *, int, int);
char *procprt_RUID_ae(struct tstat *, int, int);
char *procprt_EUID_a(struct tstat *, int, int);
char *procprt_EUID_e(struct tstat *, int, int);
char *procprt_SUID_a(struct tstat *, int, int);
char *procprt_SUID_e(struct tstat *, int, int);
char *procprt_FSUID_a(struct tstat *, int, int);
char *procprt_FSUID_e(struct tstat *, int, int);
char *procprt_RGID_ae(struct tstat *, int, int);
char *procprt_EGID_a(struct tstat *, int, int);
char *procprt_EGID_e(struct tstat *, int, int);
char *procprt_SGID_a(struct tstat *, int, int);
char *procprt_SGID_e(struct tstat *, int, int);
char *procprt_FSGID_a(struct tstat *, int, int);
char *procprt_FSGID_e(struct tstat *, int, int);
char *procprt_STDATE_ae(struct tstat *, int, int);
char *procprt_STTIME_ae(struct tstat *, int, int);
char *procprt_ENDATE_a(struct tstat *, int, int);
char *procprt_ENDATE_e(struct tstat *, int, int);
char *procprt_ENTIME_a(struct tstat *, int, int);
char *procprt_ENTIME_e(struct tstat *, int, int);
char *procprt_THR_a(struct tstat *, int, int);
char *procprt_THR_e(struct tstat *, int, int);
char *procprt_TRUN_a(struct tstat *, int, int);
char *procprt_TRUN_e(struct tstat *, int, int);
char *procprt_TSLPI_a(struct tstat *, int, int);
char *procprt_TSLPI_e(struct tstat *, int, int);
char *procprt_TSLPU_a(struct tstat *, int, int);
char *procprt_TSLPU_e(struct tstat *, int, int);
char *procprt_TIDLE_a(struct tstat *, int, int);
char *procprt_TIDLE_e(struct tstat *, int, int);
char *procprt_POLI_a(struct tstat *, int, int);
char *procprt_POLI_e(struct tstat *, int, int);
char *procprt_NICE_a(struct tstat *, int, int);
char *procprt_NICE_e(struct tstat *, int, int);
char *procprt_PRI_a(struct tstat *, int, int);
char *procprt_PRI_e(struct tstat *, int, int);
char *procprt_RTPR_a(struct tstat *, int, int);
char *procprt_RTPR_e(struct tstat *, int, int);
char *procprt_CURCPU_a(struct tstat *, int, int);
char *procprt_CURCPU_e(struct tstat *, int, int);
char *procprt_ST_a(struct tstat *, int, int);
char *procprt_ST_e(struct tstat *, int, int);
char *procprt_EXC_a(struct tstat *, int, int);
char *procprt_EXC_e(struct tstat *, int, int);
char *procprt_S_a(struct tstat *, int, int);
char *procprt_S_e(struct tstat *, int, int);
char *procprt_COMMAND_LINE_ae(struct tstat *, int, int);
char *procprt_NPROCS_ae(struct tstat *, int, int);
char *procprt_RDDSK_a(struct tstat *, int, int);
char *procprt_RDDSK_e(struct tstat *, int, int);
char *procprt_WRDSK_a(struct tstat *, int, int);
char *procprt_WRDSK_e(struct tstat *, int, int);
char *procprt_CWRDSK_a(struct tstat *, int, int);
char *procprt_WCANCEL_a(struct tstat *, int, int);
char *procprt_WCANCEL_e(struct tstat *, int, int);
char *procprt_BANDWI_a(struct tstat *, int, int);
char *procprt_BANDWI_e(struct tstat *, int, int);
char *procprt_BANDWO_a(struct tstat *, int, int);
char *procprt_BANDWO_e(struct tstat *, int, int);
char *procprt_GPULIST_ae(struct tstat *, int, int);
char *procprt_GPUMEMNOW_ae(struct tstat *, int, int);
char *procprt_GPUMEMAVG_ae(struct tstat *, int, int);
char *procprt_GPUGPUBUSY_ae(struct tstat *, int, int);
char *procprt_GPUMEMBUSY_ae(struct tstat *, int, int);
char *procprt_WCHAN_a(struct tstat *, int, int);
char *procprt_WCHAN_e(struct tstat *, int, int);
char *procprt_RUNDELAY_a(struct tstat *, int, int);
char *procprt_RUNDELAY_e(struct tstat *, int, int);
char *procprt_BLKDELAY_a(struct tstat *, int, int);
char *procprt_BLKDELAY_e(struct tstat *, int, int);
char *procprt_NVCSW_a(struct tstat *, int, int);
char *procprt_NVCSW_e(struct tstat *, int, int);
char *procprt_NIVCSW_a(struct tstat *, int, int);
char *procprt_NIVCSW_e(struct tstat *, int, int);
char *procprt_SORTITEM_ae(struct tstat *, int, int);
char *cgroup_CGROUP_PATH(struct cgchainer *, struct tstat *,
int, int, count_t, int, int *);
char *cgroup_CGRNPROCS(struct cgchainer *, struct tstat *,
int, int, count_t, int, int *);
char *cgroup_CGRNPROCSB(struct cgchainer *, struct tstat *,
int, int, count_t, int, int *);
char *cgroup_CGRCPUBUSY(struct cgchainer *, struct tstat *,
int, int, count_t, int, int *);
char *cgroup_CGRCPUPSI(struct cgchainer *, struct tstat *,
int, int, count_t, int, int *);
char *cgroup_CGRCPUWGT(struct cgchainer *, struct tstat *,
int, int, count_t, int, int *);
char *cgroup_CGRCPUMAX(struct cgchainer *, struct tstat *,
int, int, count_t, int, int *);
char *cgroup_CGRMEMORY(struct cgchainer *, struct tstat *,
int, int, count_t, int, int *);
char *cgroup_CGRMEMPSI(struct cgchainer *, struct tstat *,
int, int, count_t, int, int *);
char *cgroup_CGRMEMMAX(struct cgchainer *, struct tstat *,
int, int, count_t, int, int *);
char *cgroup_CGRSWPMAX(struct cgchainer *, struct tstat *,
int, int, count_t, int, int *);
char *cgroup_CGRDISKIO(struct cgchainer *, struct tstat *,
int, int, count_t, int, int *);
char *cgroup_CGRDSKPSI(struct cgchainer *, struct tstat *,
int, int, count_t, int, int *);
char *cgroup_CGRDSKWGT(struct cgchainer *, struct tstat *,
int, int, count_t, int, int *);
char *cgroup_CGRPID(struct cgchainer *, struct tstat *,
int, int, count_t, int, int *);
char *cgroup_CGRCMD(struct cgchainer *, struct tstat *,
int, int, count_t, int, int *);
static char *columnhead[] = {
[MSORTCPU]= "CPU", [MSORTMEM]= "MEM",
[MSORTDSK]= "DSK", [MSORTNET]= "NET",
[MSORTGPU]= "GPU",
};
/***************************************************************/
static int *colspacings; // ugly static var,
// but saves a lot of recomputations
// points to table with intercolumn
// spacings
static detail_printpair newelems[MAXITEMS];
// ugly static var,
// but saves a lot of recomputations
// contains the actual list of items to
// be printed
/***************************************************************/
/*
* gettotwidth: calculate the sum of widths and number of columns
* Also copys the detail_printpair elements to the static array newelems
* for later removal of lower priority elements.
* Params:
* elemptr: the array of what to print
* nitems: (ref) returns the number of printitems in the array
* sumwidth: (ref) returns the total width of the printitems in the array
* varwidth: (ref) returns the number of variable width items in the array
*/
static void
gettotwidth(detail_printpair *elemptr, int *nitems, int *sumwidth, int* varwidth)
{
int i;
int col;
int varw=0;
for (i=0, col=0; elemptr[i].pf!=0; ++i)
{
col += (elemptr[i].pf->varwidth ? 0 : elemptr[i].pf->width);
varw += elemptr[i].pf->varwidth;
newelems[i]=elemptr[i]; // copy element
}
newelems[i].pf=0;
*nitems=i;
*sumwidth=col;
*varwidth=varw;
}
/***************************************************************/
/*
* getspacings: determine how much extra space there is for
* inter-column space.
* returns an int array this number of spaces to add after each column
* also removes items from the newelems array if the available width
* is lower than what is needed. The lowest priority columns are
* removed first.
*
* Note: this function is only to be called when screen is true.
*/
static int *
getspacings(detail_printpair *elemptr)
{
static int spacings[MAXITEMS];
int col=0;
int nitems;
int varwidth=0;
int j;
int maxw=screen ? COLS : linelen; // for non screen: 80 columns max
// get width etc; copy elemptr array to static newelms
gettotwidth(elemptr, &nitems, &col, &varwidth);
/* cases:
* 1) nitems==1: just one column, no spacing needed. Done
*
* 2) total width is more than COLS: remove low prio columns
* 2a) a varwidth column: no spacing needed
* 2b) total width is less than COLS: compute inter spacing
*/
if (nitems==1) // no inter column spacing if 1 column
{
spacings[0]=0;
return spacings;
}
// Check if available width is less than required.
// If so, delete columns to make things fit
// space required:
// width + (nitems-1) * 1 space + 12 for a varwidth column.
while (col + nitems-1+ 12*varwidth > maxw)
{
int lowestprio=999999;
int lowestprio_index=-1;
int i;
for (i=0; i<nitems; ++i)
{
if (newelems[i].prio < lowestprio)
{
lowestprio=newelems[i].prio;
lowestprio_index=i;
}
}
// lowest priority item found, remove from newelems;
col -= newelems[lowestprio_index].pf->width;
varwidth -= newelems[lowestprio_index].pf->varwidth;
memmove(newelems+lowestprio_index,
newelems+lowestprio_index+1,
(nitems-lowestprio_index)* sizeof(detail_printpair));
// also copies final 0 entry
nitems--;
}
/* if there is a var width column, handle that separately */
if (varwidth)
{
for (j=0; j<nitems; ++j)
{
spacings[j]=1;
if (elemptr[j].pf->varwidth)
{
elemptr[j].pf->width=maxw-col-(nitems-1);
// only nitems-1 in-between spaces
// needed
}
}
return spacings;
}
// avoid division by 0
if (nitems==1)
{
spacings[0]=0;
return spacings;
}
/* fixed columns, spread whitespace over columns */
double over=(0.0+maxw-col)/(nitems-1);
double todo=over;
for (j=0; j<nitems-1; ++j) // last column gets no space appended
{
spacings[j]=(int)todo+0.5;
todo-=spacings[j];
todo+=over;
}
spacings[j]=0;
return spacings;
}
/*
* showprochead: show header line for processes.
* if in interactive mode, also add a page numer
* if in interactive mode, columns are aligned to fill out rows
*/
void
showprochead(detail_printpair* elemptr, int curlist, int totlist,
char showorder, char autosort)
{
detail_printpair curelem;
char *chead="";
char *autoindic="";
int order=showorder;
int col=0;
int align;
char pagindic[10];
int pagindiclen;
int n=0;
int bufsz;
int maxw=screen ? COLS : linelen; // for non screen: 80 columns max
colspacings=getspacings(elemptr);
bufsz=maxw+1;
elemptr=newelems; // point to adjusted array
char buf[bufsz+2]; // long live dynamically sized auto arrays...
if (!screen)
printg("\n");
while ((curelem=*elemptr).pf!=0)
{
int widen = 0;
if (curelem.pf->head==0) // empty header==special: SORTITEM
{
chead = columnhead[order];
autoindic = autosort ? "A" : " ";
widen = procprt_SORTITEM.width-3;
}
else
{
chead=curelem.pf->head;
autoindic="";
}
if (screen)
{
col += sprintf(buf+col, "%*s%s%*s",
widen, autoindic, chead, colspacings[n], "");
}
else
{
col += sprintf(buf+col, "%s%s ", autoindic, chead);
}
elemptr++;
n++;
}
if (screen) // add page number, eat from last header if needed...
{
pagindiclen=sprintf(pagindic,"%d/%d", curlist, totlist);
align=COLS-col-pagindiclen; // extra spaces needed
if (align >= 0) // align by adding spaces
{
sprintf(buf+col, "%*s", align+pagindiclen, pagindic);
}
else if (col+align >= 0)
{ // align by removing from the right
sprintf(buf+col+align, "%s", pagindic);
}
}
printg("%s", buf);
if (!screen)
printg("\n");
}
/***************************************************************/
/*
* showprocline: show line for processes.
* if in interactive mode, columns are aligned to fill out rows
* params:
* elemptr: pointer to array of print definition structs ptrs
* curstat: the process to print
* perc: the sort order used
* nsecs: number of seconds elapsed between previous and this sample
* avgval: is averaging out per second needed?
*/
void
showprocline(detail_printpair* elemptr, struct tstat *curstat,
double perc, int nsecs, int avgval)
{
detail_printpair curelem;
elemptr=newelems; // point to static array
int n=0;
if (screen && threadview)
{
if (usecolors && !curstat->gen.isproc)
{
attron(COLOR_PAIR(FGCOLORTHR));
}
else
{
if (!usecolors && curstat->gen.isproc)
attron(A_BOLD);
}
}
while ((curelem=*elemptr).pf!=0)
{
// what to print? SORTITEM, or active process or
// exited process?
if (curelem.pf->head==0) // empty string=sortitem
{
printg("%*.0lf%%", procprt_SORTITEM.width-1, perc);
}
else if (curstat->gen.state != 'E') // active process
{
printg("%s", curelem.pf->doactiveconvert(curstat,
avgval, nsecs));
}
else // exited process
{
printg("%s", curelem.pf->doexitconvert(curstat,
avgval, nsecs));
}
if (screen)
{
printg("%*s",colspacings[n], "");
}
else
{
printg(" ");
}
elemptr++;
n++;
}
if (screen && threadview)
{
if (usecolors && !curstat->gen.isproc)
{
attroff(COLOR_PAIR(FGCOLORTHR));
}
else
{
if (!usecolors && curstat->gen.isproc)
attroff(A_BOLD);
}
}
if (!screen)
{
printg("\n");
}
}
/***************************************************************/
/* Generic functions to translate UID or GID number into a */
/* string of 8 characters, to be stored in strbuf with a */
/* of maximum 9 bytes. */
/* When no translation is wanted (-I flag) or when the */
/* name is longer than 8, a string representation of the */
/* UID or GID number is returned. */
/***************************************************************/
static void
uid2str(uid_t uid, char *strbuf)
{
char *username;
if (!idnamesuppress && (username = uid2name(uid)) && strlen(username) <= 8)
snprintf(strbuf, 9, "%-8.8s", username);
else
snprintf(strbuf, 9, "%-8d", uid);
}
static void
gid2str(gid_t gid, char *strbuf)
{
char *grpname;
if (!idnamesuppress && (grpname = gid2name(gid)) && strlen(grpname) <= 8)
snprintf(strbuf, 9, "%-8.8s", grpname);
else
snprintf(strbuf, 9, "%-8d", gid);
}
/*******************************************************************/
/* PROCESS PRINT FUNCTIONS */
/***************************************************************/
char *
procprt_NOTAVAIL_4(struct tstat *curstat, int avgval, int nsecs)
{
return " ?";
}
char *
procprt_NOTAVAIL_5(struct tstat *curstat, int avgval, int nsecs)
{
return " ?";
}
char *
procprt_NOTAVAIL_6(struct tstat *curstat, int avgval, int nsecs)
{
return " ?";
}
char *
procprt_NOTAVAIL_7(struct tstat *curstat, int avgval, int nsecs)
{
return " ?";
}
/***************************************************************/
char *
procprt_TID_ae(struct tstat *curstat, int avgval, int nsecs)
{
static char buf[64];
if (curstat->gen.isproc)
sprintf(buf, "%*s", procprt_TID.width, "-");
else
sprintf(buf, "%*d", procprt_TID.width, curstat->gen.pid);
return buf;
}
detail_printdef procprt_TID =
{ "TID", "TID", procprt_TID_ae, procprt_TID_ae, ' ', 5}; //DYNAMIC WIDTH!
/***************************************************************/
char *
procprt_PID_a(struct tstat *curstat, int avgval, int nsecs)
{
static char buf[64];
sprintf(buf, "%*d", procprt_PID.width, curstat->gen.tgid);
return buf;
}
char *
procprt_PID_e(struct tstat *curstat, int avgval, int nsecs)
{
static char buf[64];
if (curstat->gen.pid == 0)
sprintf(buf, "%*s", procprt_PID.width, "?");
else
sprintf(buf, "%*d", procprt_PID.width, curstat->gen.tgid);
return buf;
}
detail_printdef procprt_PID =
{ "PID", "PID", procprt_PID_a, procprt_PID_e, ' ', 5}; //DYNAMIC WIDTH!
/***************************************************************/
char *
procprt_PPID_a(struct tstat *curstat, int avgval, int nsecs)
{
static char buf[64];
sprintf(buf, "%*d", procprt_PPID.width, curstat->gen.ppid);
return buf;
}
char *
procprt_PPID_e(struct tstat *curstat, int avgval, int nsecs)
{
static char buf[64];
if (curstat->gen.ppid)
sprintf(buf, "%*d", procprt_PPID.width, curstat->gen.ppid);
else
sprintf(buf, "%*s", procprt_PPID.width, "-");
return buf;
}
detail_printdef procprt_PPID =
{ "PPID", "PPID", procprt_PPID_a, procprt_PPID_e, ' ', 5}; //DYNAMIC WIDTH!
/***************************************************************/
char *
procprt_VPID_a(struct tstat *curstat, int avgval, int nsecs)
{
static char buf[64];
sprintf(buf, "%*d", procprt_VPID.width, curstat->gen.vpid);
return buf;
}
char *
procprt_VPID_e(struct tstat *curstat, int avgval, int nsecs)
{
static char buf[64];
sprintf(buf, "%*s", procprt_VPID.width, "-");
return buf;
}
detail_printdef procprt_VPID =
{ "VPID", "VPID", procprt_VPID_a, procprt_VPID_e, ' ', 5}; //DYNAMIC WIDTH!
/***************************************************************/
char *
procprt_CTID_a(struct tstat *curstat, int avgval, int nsecs)
{
static char buf[32];
sprintf(buf, "%5d", curstat->gen.ctid);
return buf;
}
char *
procprt_CTID_e(struct tstat *curstat, int avgval, int nsecs)
{
return " -";
}
detail_printdef procprt_CTID =
{ " CTID", "CTID", procprt_CTID_a, procprt_CTID_e, ' ', 5};
/***************************************************************/
char *
procprt_CID_a(struct tstat *curstat, int avgval, int nsecs)
{
static char buf[64];
if (curstat->gen.utsname[0])
sprintf(buf, "%-15s", curstat->gen.utsname);
else
sprintf(buf, "%-15s", "host-----------");
return buf;
}
char *
procprt_CID_e(struct tstat *curstat, int avgval, int nsecs)
{
static char buf[64];
if (curstat->gen.utsname[0])
sprintf(buf, "%-15s", curstat->gen.utsname);
else
sprintf(buf, "%-15s", "?");
return buf;
}
detail_printdef procprt_CID =
{ "CID/POD ", "CID", procprt_CID_a, procprt_CID_e, ' ', 15};
/***************************************************************/
char *
procprt_SYSCPU_ae(struct tstat *curstat, int avgval, int nsecs)
{
static char buf[10];
val2cpustr(curstat->cpu.stime*1000/hertz, buf);
return buf;
}
detail_printdef procprt_SYSCPU =
{ "SYSCPU", "SYSCPU", procprt_SYSCPU_ae, procprt_SYSCPU_ae, ' ', 6};
/***************************************************************/
char *
procprt_USRCPU_ae(struct tstat *curstat, int avgval, int nsecs)
{
static char buf[10];
val2cpustr(curstat->cpu.utime*1000/hertz, buf);
return buf;
}
detail_printdef procprt_USRCPU =
{ "USRCPU", "USRCPU", procprt_USRCPU_ae, procprt_USRCPU_ae, ' ', 6};
/***************************************************************/
char *
procprt_VGROW_a(struct tstat *curstat, int avgval, int nsecs)
{
static char buf[10];
val2memstr(curstat->mem.vgrow*1024, buf, BFORMAT, 0, 0);
return buf;
}
char *
procprt_VGROW_e(struct tstat *curstat, int avgval, int nsecs)
{
return " 0K";
}
detail_printdef procprt_VGROW =
{ " VGROW", "VGROW", procprt_VGROW_a, procprt_VGROW_e, ' ', 6};
/***************************************************************/
char *
procprt_RGROW_a(struct tstat *curstat, int avgval, int nsecs)
{
static char buf[10];
val2memstr(curstat->mem.rgrow*1024, buf, BFORMAT, 0, 0);
return buf;
}
char *
procprt_RGROW_e(struct tstat *curstat, int avgval, int nsecs)
{
return " 0K";
}
detail_printdef procprt_RGROW =
{ " RGROW", "RGROW", procprt_RGROW_a, procprt_RGROW_e, ' ', 6};
/***************************************************************/
char *
procprt_MINFLT_ae(struct tstat *curstat, int avgval, int nsecs)
{
static char buf[10];
val2valstr(curstat->mem.minflt, buf, 6, avgval, nsecs);
return buf;
}
detail_printdef procprt_MINFLT =
{ "MINFLT", "MINFLT", procprt_MINFLT_ae, procprt_MINFLT_ae, ' ', 6};
/***************************************************************/
char *
procprt_MAJFLT_ae(struct tstat *curstat, int avgval, int nsecs)
{
static char buf[10];
val2valstr(curstat->mem.majflt, buf, 6, avgval, nsecs);
return buf;
}
detail_printdef procprt_MAJFLT =
{ "MAJFLT", "MAJFLT", procprt_MAJFLT_ae, procprt_MAJFLT_ae, ' ', 6};
/***************************************************************/
char *
procprt_VSTEXT_a(struct tstat *curstat, int avgval, int nsecs)
{
static char buf[10];
val2memstr(curstat->mem.vexec*1024, buf, BFORMAT, 0, 0);
return buf;
}
char *
procprt_VSTEXT_e(struct tstat *curstat, int avgval, int nsecs)
{
return " 0K";
}
detail_printdef procprt_VSTEXT =
{ "VSTEXT", "VSTEXT", procprt_VSTEXT_a, procprt_VSTEXT_e, ' ', 6};
/***************************************************************/
char *
procprt_VSIZE_a(struct tstat *curstat, int avgval, int nsecs)
{
static char buf[10];
val2memstr(curstat->mem.vmem*1024, buf, BFORMAT, 0, 0);
return buf;
}
char *
procprt_VSIZE_e(struct tstat *curstat, int avgval, int nsecs)
{
return " 0K";
}
detail_printdef procprt_VSIZE =
{ " VSIZE", "VSIZE", procprt_VSIZE_a, procprt_VSIZE_e, ' ', 6};
/***************************************************************/
char *
procprt_RSIZE_a(struct tstat *curstat, int avgval, int nsecs)
{
static char buf[10];
val2memstr(curstat->mem.rmem*1024, buf, BFORMAT, 0, 0);
return buf;
}
char *
procprt_RSIZE_e(struct tstat *curstat, int avgval, int nsecs)
{
return " 0K";
}
detail_printdef procprt_RSIZE =
{ " RSIZE", "RSIZE", procprt_RSIZE_a, procprt_RSIZE_e, ' ', 6};
/***************************************************************/
char *
procprt_PSIZE_a(struct tstat *curstat, int avgval, int nsecs)
{
static char buf[10];
if (curstat->mem.pmem == (unsigned long long)-1LL)
return " ?K";
val2memstr(curstat->mem.pmem*1024, buf, BFORMAT, 0, 0);
return buf;
}
char *
procprt_PSIZE_e(struct tstat *curstat, int avgval, int nsecs)
{
return " 0K";
}
detail_printdef procprt_PSIZE =
{ " PSIZE", "PSIZE", procprt_PSIZE_a, procprt_PSIZE_e, ' ', 6};
/***************************************************************/
char *
procprt_VSLIBS_a(struct tstat *curstat, int avgval, int nsecs)
{
static char buf[10];
val2memstr(curstat->mem.vlibs*1024, buf, BFORMAT, 0, 0);
return buf;
}
char *
procprt_VSLIBS_e(struct tstat *curstat, int avgval, int nsecs)
{
return " 0K";
}
detail_printdef procprt_VSLIBS =
{ "VSLIBS", "VSLIBS", procprt_VSLIBS_a, procprt_VSLIBS_e, ' ', 6};
/***************************************************************/
char *
procprt_VDATA_a(struct tstat *curstat, int avgval, int nsecs)
{
static char buf[10];
val2memstr(curstat->mem.vdata*1024, buf, BFORMAT, 0, 0);
return buf;
}
char *
procprt_VDATA_e(struct tstat *curstat, int avgval, int nsecs)
{
return " 0K";
}
detail_printdef procprt_VDATA =
{ " VDATA", "VDATA", procprt_VDATA_a, procprt_VDATA_e, ' ', 6};
/***************************************************************/
char *
procprt_VSTACK_a(struct tstat *curstat, int avgval, int nsecs)
{
static char buf[10];
val2memstr(curstat->mem.vstack*1024, buf, BFORMAT, 0, 0);
return buf;
}
char *
procprt_VSTACK_e(struct tstat *curstat, int avgval, int nsecs)
{
return " 0K";
}
detail_printdef procprt_VSTACK =
{ "VSTACK", "VSTACK", procprt_VSTACK_a, procprt_VSTACK_e, ' ', 6};
/***************************************************************/
char *
procprt_SWAPSZ_a(struct tstat *curstat, int avgval, int nsecs)
{
static char buf[10];
val2memstr(curstat->mem.vswap*1024, buf, BFORMAT, 0, 0);
return buf;
}
char *
procprt_SWAPSZ_e(struct tstat *curstat, int avgval, int nsecs)
{
return " 0K";
}
detail_printdef procprt_SWAPSZ =
{ "SWAPSZ", "SWAPSZ", procprt_SWAPSZ_a, procprt_SWAPSZ_e, ' ', 6};
/***************************************************************/
char *
procprt_LOCKSZ_a(struct tstat *curstat, int avgval, int nsecs)
{
static char buf[10];
val2memstr(curstat->mem.vlock*1024, buf, KBFORMAT, 0, 0);
return buf;
}
char *
procprt_LOCKSZ_e(struct tstat *curstat, int avgval, int nsecs)
{
return " 0K";
}
detail_printdef procprt_LOCKSZ =
{ "LOCKSZ", "LOCKSZ", procprt_LOCKSZ_a, procprt_LOCKSZ_e, ' ', 6};
/***************************************************************/
char *
procprt_CMD_a(struct tstat *curstat, int avgval, int nsecs)
{
static char buf[15];
sprintf(buf, "%-14.14s", curstat->gen.name);
return buf;
}
char *
procprt_CMD_e(struct tstat *curstat, int avgval, int nsecs)
{
static char buf[15]="<";
char helpbuf[15];
sprintf(helpbuf, "<%.12s>", curstat->gen.name);
sprintf(buf, "%-14.14s", helpbuf);
return buf;
}
detail_printdef procprt_CMD =
{ "CMD ", "CMD", procprt_CMD_a, procprt_CMD_e, ' ', 14};
/***************************************************************/
char *