-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.c
63 lines (51 loc) · 1.13 KB
/
util.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
#include "util.h"
#include "queue.h"
#include "main.h"
#include <stdlib.h>
#include <stdio.h>
#ifdef _WIN32
# include <windows.h>
#else
# include <unistd.h>
# include <pthread.h>
#endif
void
wait_random_time (void)
{
volatile size_t i;
size_t max_i = (2 << 15) + rand() % (2 << 15);
for (i = 0; i < max_i; ++i);
}
extern volatile struct element queue[];
extern size_t head_r;
extern size_t head_w;
void
monitor (void)
{
long long int window[10] = { 0 };
size_t n = 0;
size_t last = 0;
while (1)
{
size_t processed;
double throughput;
size_t filled;
int i;
int r = head_r;
processed = queue[r].id - last;
last = queue[r].id;
window[n++] = processed;
n %= 10;
throughput = 0;
for (i = 0; i < 10; ++i)
throughput += window[i];
throughput /= MONITOR_INTERVAL / 100000.0;
filled = (head_r - head_w) % QUEUE_CAPACITY;
printf("filled %zu; avail: %zu; current: %zu (%.2f/s)\n", filled, QUEUE_CAPACITY - filled, queue[head_r].id, throughput);
#ifdef _WIN32
Sleep(MONITOR_INTERVAL / 1000);
#else
usleep(MONITOR_INTERVAL);
#endif
}
}