-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcpuselfwatcher.d
49 lines (46 loc) · 1.09 KB
/
cpuselfwatcher.d
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
/+dub.sdl:
name "cpuselfwatcher"
dependency "resusage" path="../"
+/
import std.stdio;
import core.thread;
import core.time;
import std.parallelism;
import std.getopt;
import std.exception;
import resusage.cpu;
void work()
{
for (size_t i=0; i<size_t.max; ++i) {
}
}
int main(string[] args)
{
ushort threads = 1;
getopt(args, "threads", "Count of threads to run", &threads);
if (!threads) {
stderr.writeln("thread count must be not zero");
return 1;
}
if (threads > totalCPUs) {
stderr.writefln("thread count should not exceed total number of CPU (%s)", totalCPUs);
return 1;
}
auto cpuWatcher = new ProcessCPUWatcher();
typeof(task!work())[] tasks;
for (ushort i = 1; i<threads; ++i)
{
auto workTask = task!work();
workTask.executeInNewThread();
tasks ~= workTask;
}
for (size_t i=0; i<size_t.max; ++i) {
if (i && (i % 2^^28) == 0) {
writefln("%s%%", cpuWatcher.current());
}
}
for (size_t i=0; i<tasks.length; ++i) {
tasks[i].yieldForce;
}
return 0;
}