-
Notifications
You must be signed in to change notification settings - Fork 3
/
measure.c
92 lines (71 loc) · 1.92 KB
/
measure.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
/*
*
* Copyright (C) Cyclades Corporation, 1999-1999. All rights reserved.
*
*
* measure.c
* Activity measure
*
* History
* 08/17/1999 V.1.0.0 Initial revision
*
*/
# include <sys/types.h>
# include <sys/param.h>
# include <sys/times.h>
# define _TSR_MEASURE_
#include "inc/cyclades-ser-cli.h"
#include "inc/system.h"
#include "inc/tsrmeasure.h"
# ifdef TSR_MEASURE
/*
* Internal Variables
*/
static int progst;
static int progend;
void
start_measure(void)
{
struct tms ts;
progst = times(&ts);
}
void
cpu_measure(int all)
{
struct tms ts;
int usr, sys, tot, pru, prs, prt, msecu, msecs, msect, secs;
progend = times(&ts);
usr = (int) ts.tms_utime;
sys = (int) ts.tms_stime;
tot = progend - progst;
pru = usr * 100 / tot;
prs = sys * 100 / tot;
prt = pru + prs;
msecu = 1000 * usr / HZ;
msecs = 1000 * sys / HZ;
msect = msecu + msecs;
printf("%s: \n\
%5d ms (%2d%%) user, %5d ms (%2d%%) sys, %5d ms (%3d%%) total\n", Idmsg, msecu, pru, msecs, prs, msect, prt);
if (all) {
secs = tot / HZ;
if (secs == 0)
secs = 1;
if (devreads == 0)
devreads = 1;
if (devwrites == 0)
devwrites = 1;
if (netreads == 0)
netreads = 1;
if (netwrites == 0)
netwrites = 1;
printf("%s:\n\
devrds : %6d (%6d null) , %3d reads/sec, %.2f bytes/read)\n\
devwrs : %6d (%6d null) , %3d writes/sec, %.2f bytes/write)\n", Idmsg, devreads, devnreads, devreads / secs, (double) devrbytes / devreads, devwrites, devnwrites, devwrites / secs, (double) devwbytes / devwrites);
printf("%s:\n\
netrds : %6d (%6d null) , %3d reads/sec, %.2f bytes/read)\n\
netwrs : %6d (%6d null) , %3d writes/sec, %.2f bytes/write)\n", Idmsg, netreads, netnreads, netreads / secs, (double) netrbytes / netreads, netwrites, netnwrites, netwrites / secs, (double) netwbytes / netwrites);
printf("%s:\n\
scheds : %6d (%3d scheds/sec)\n", Idmsg, ioscheds, ioscheds / secs);
}
}
# endif