generated from LgoLgo/.github
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcpusched.go
75 lines (63 loc) · 1.36 KB
/
cpusched.go
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
package main
import (
"flag"
"fmt"
"github.com/LgoLgo/cpusched/core"
)
var (
n *int
total *int64
resol *int64
help *bool
worker *bool
id *int
)
func init() {
// Initialize parameters
n = flag.Int("n", 1, "Number of processes to run simultaneously")
total = flag.Int64("total", 5000, "Total runtime of the program (in milliseconds)")
resol = flag.Int64("resol", 1000, "Interval for collecting statistics (in milliseconds)")
help = flag.Bool("h", false, "Display help information")
// Flags for worker mode
worker = flag.Bool("worker", false, "Run in worker mode")
id = flag.Int("id", 0, "Worker ID")
}
func main() {
// Parse parameters
flag.Parse()
// Display help information
if *help {
helpInfo()
return
}
// Check if running in worker mode
if *worker {
processor := &core.Processor{}
processor.WorkerMain(*id, *total, *resol)
return
}
// Initialize processor
processor := core.Processor{
N: *n,
Total: *total,
Resol: *resol,
}
// Check parameters
err := processor.Check()
if err != nil {
fmt.Println(err)
return
}
// Execute
err = processor.Execute()
if err != nil {
fmt.Println(err)
return
}
}
func helpInfo() {
fmt.Println("Usage:")
fmt.Println(" This program runs multiple processes simultaneously and periodically collects statistics.")
fmt.Println("\nParameters:")
flag.PrintDefaults()
}