/
misc_main.go
79 lines (63 loc) · 1.63 KB
/
misc_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
package miscmanager
import (
"encoding/json"
"io/ioutil"
"math/rand"
"time"
"github.com/colinzuo/tunip/pkg/logp"
)
// Manager def
type Manager struct {
logger *logp.Logger
config *Config
dispatchChan chan WorkerRequest
freeWorkerChan chan chan interface{}
doneChan chan bool
timeLongForm string
}
// ParseConfig parse config
func ParseConfig(configPath string) (*Config, error) {
logger := logp.NewLogger(ModuleName)
content, err := ioutil.ReadFile(configPath)
if err != nil {
logger.Errorf("read config %s failed, %s", configPath, err)
return nil, err
}
var config Config
err = json.Unmarshal(content, &config)
if err != nil {
logger.Errorf("parse config %s failed, %s", configPath, err)
return nil, err
}
return &config, nil
}
// Run function to start
func Run(configPath string) {
logger := logp.NewLogger(ModuleName)
var config *Config
config, err := ParseConfig(configPath)
if err != nil {
logger.Panicf("ParseConfig: failed with %s", err)
}
logger.Infof("config %s, content: %+v", configPath, config)
manager := Manager{logger: logger, config: config,
timeLongForm: "2006-01-02T15:04:05.000-07:00"}
manager.Work()
}
// Work work according to config
func (m *Manager) Work() {
logger := m.logger
config := m.config
jsonRsp, _ := json.MarshalIndent(config, "", " ")
logger.Infof("Enter with config: %s", string(jsonRsp))
rand.Seed((int64)(time.Now().Second()))
if config.PerfTest != nil && config.PerfTest.Enabled {
m.perfTest()
}
if config.ViperTest != nil && config.ViperTest.Enabled {
m.viperTest()
}
if config.CpuBusyTest != nil && config.CpuBusyTest.Enabled {
m.cpuBusyTest()
}
}