-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
82 lines (65 loc) · 1.81 KB
/
main.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
76
77
78
79
80
81
82
// Author: Sean Hamilton <skhamilt@eng.ucsd.edu>
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"os/user"
"fmt"
"log"
"os"
"flag"
"sync"
"syscall"
"time"
"github.com/RedShamilton/cyclictest-go/types"
)
var wg sync.WaitGroup
var running = true
var histogram = false
var histfile *os.File
var params []types.TaskParameters
func main() {
var err error
// Check to ensure this is being run as root
u,_ := user.Current()
if u.Uid != "0" {
fmt.Fprintln(os.Stderr, "cyclictest must be run as root")
os.Exit(int(syscall.EPERM))
}
var numLoops uint
flag.UintVar(&numLoops, "l", 1000, "number of `loops`")
var priority int
flag.IntVar(&priority, "p", 0, "priority for highest `priority` task")
var numTasks uint
flag.UintVar(&numTasks, "t", 1, "number of `tasks`")
var distance time.Duration
flag.DurationVar(&distance,"d", 500*time.Microsecond, "`distance` of task intervals")
var interval time.Duration
flag.DurationVar(&interval,"i", 1000*time.Microsecond, "base `interval` of task")
var histfilename string
flag.StringVar(&histfilename, "H", "", "dump a latency histogram to `file` after the run")
flag.Parse()
//TODO: check for valid ranges of flags
// Should we print out histogram data?
if histfilename != "" {
histogram = true
histfile, err = os.Create(histfilename)
if err != nil {
log.Fatal(err)
}
}
wg.Add(int(numTasks))
nextInterval := interval
nextPrio := priority
params = make([]types.TaskParameters, numTasks)
for i := uint(0); i < numTasks; i++ {
params[i].Init(i,nextInterval,int32(nextPrio),new(types.TaskStatistics))
nextPrio -= 1
nextInterval += distance
go worker(¶ms[i], numLoops)
}
wg.Wait()
for i := uint(0); i < numTasks; i++ {
params[i].PrintResults()
}
}