-
Notifications
You must be signed in to change notification settings - Fork 21
/
mudstat.c
178 lines (154 loc) · 4.28 KB
/
mudstat.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
/*
* mudstat.c
*
* Keep hundreth of a second statistics
*/
#include <sys/types.h>
#include <sys/time.h>
#include <sys/times.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "config.h"
#include "lint.h"
#define MUDSTAT
#include "mudstat.h"
#ifdef RUSAGE /* Defined in config.h */
#include <sys/resource.h>
#endif
int num_move, /* Number of move_object() */
num_mcall, /* Number of calls to master ob */
num_fileread, /* Number of file reads */
num_filewrite, /* Number of file writes */
num_compile; /* Number of compiles */
static long mch_t1;
static struct tms tms1;
static int num_pr = 0,
ms_eval_lim, /* Low limit for logging eval cost */
ms_time_lim, /* Low limit for logging eval time */
ms_active = 0; /* True if logging active */
static void mark_millitime(void);
extern int s_flag;
/*
* Set active / inactive and parameters
*/
void
mudstatus_set(int active, int eval_lim, int time_lim)
{
float tifl = time_lim / 100.0;
FILE *mstat;
ms_active = active;
if (active)
{
s_flag = 1;
if ((mstat = fopen(MUDSTAT_FILE, "a")) != NULL)
{
(void)fprintf(mstat,"\n%-35s (%5.2f) %8d\n",
"------ ON, Limits:", tifl, eval_lim);
(void)fclose(mstat);
}
}
else
{
if (s_flag && ((mstat = fopen(MUDSTAT_FILE,"a")) != NULL))
{
(void)fprintf(mstat,"\n%-35s\n", "------ OFF");
(void)fclose(mstat);
}
s_flag = 0;
}
ms_eval_lim = ((eval_lim >= 0) ? eval_lim : MUDSTAT_LOGEVAL);
ms_time_lim = ((time_lim >= 0) ? time_lim : MUDSTAT_LOGTIME);
}
/*
* Mark current millitime
*/
static void
mark_millitime()
{
#ifdef RUSAGE
static struct rusage rus;
if (getrusage(RUSAGE_SELF, &rus) >= 0)
{
/* Time in millisecs
*/
mch_t1 = rus.ru_utime.tv_sec * 1000 + rus.ru_utime.tv_usec / 1000 +
rus.ru_stime.tv_sec * 1000 + rus.ru_stime.tv_usec / 1000;
}
#endif
(void)times(&tms1);
}
/*
* Get millitime passed (actual real time)
*/
int
get_millitime()
{
float mtime;
static struct tms tms2;
(void)times(&tms2);
mtime = (tms2.tms_utime - tms1.tms_utime +
tms2.tms_stime - tms1.tms_stime) / 60.0;
return (int)(mtime * 100.0);
}
#ifdef RUSAGE
/*
* Get millitime passed (process time)
*/
int
get_processtime()
{
static struct rusage rus;
long mch_t2;
if (getrusage(RUSAGE_SELF, &rus) >= 0)
{
/* Time in millisecs
*/
mch_t2 = rus.ru_utime.tv_sec * 1000 + rus.ru_utime.tv_usec / 1000 +
rus.ru_stime.tv_sec * 1000 + rus.ru_stime.tv_usec / 1000;
} else
return 0;
return (int)(mch_t2 - mch_t1);
}
#else
int get_processtime() { return 0; }
#endif
void
reset_mudstatus()
{
mark_millitime();
num_move = 0;
num_mcall = 0;
num_fileread = 0;
num_filewrite = 0;
num_compile = 0;
}
void
print_mudstatus(char *activity, int eval, int timem, int tiproc)
{
FILE *mstat;
float tifl, tifl2;
if (!ms_active)
return;
if (timem < ms_time_lim && eval < ms_eval_lim)
return;
tifl = timem / 100.0;
tifl2 = tiproc / 1000.0;
if ((mstat = fopen(MUDSTAT_FILE,"a")) != NULL)
{
if (!num_pr)
(void)fprintf(mstat,"\n%-35s (%11s) %8s %3s %3s %3s %3s %3s\n",
"Activity", "time:cpu", "evalcost", "cp", "mc",
"rd", "wr", "mv");
num_pr = (num_pr + 1) % 10;
if (strlen(activity) < 35U)
(void)fprintf(mstat,"%-35s (%5.2f:%5.2f) %8d %3d %3d %3d %3d %3d\n",
activity, tifl, tifl2, eval, num_compile, num_mcall,
num_fileread, num_filewrite, num_move);
else
(void)fprintf(mstat,"%s\n%-35s (%5.2f:%5.2f) %8d %3d %3d %3d %3d %3d\n",
activity, "", tifl, tifl2, eval, num_compile, num_mcall,
num_fileread, num_filewrite, num_move);
(void)fclose(mstat);
}
}