-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
executable file
·82 lines (74 loc) · 1.87 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
package main
import (
"flag"
"fmt"
"os"
"path/filepath"
"runtime"
"github.com/getperf/getperf2/agent"
log "github.com/sirupsen/logrus"
)
const cmdName = "getperf"
func initConfig(configFile string) (*agent.Config, error) {
hostName, err := agent.GetHostname()
log.Info("Host:", hostName)
if err != nil {
return nil, fmt.Errorf("gethost %s", err)
}
if configFile == "" {
home, err := agent.GetParentAbsPath(os.Args[0], 2)
if err != nil {
return nil, fmt.Errorf("get program path %s", err)
}
configFile = filepath.Join(home, "getperf.ini")
}
configEnv := agent.NewConfigEnvBase(hostName, cmdName, configFile)
home, err := agent.GetParentAbsPath(configFile, 1)
if err != nil {
return nil, fmt.Errorf("get parent path %s", err)
}
config := agent.NewConfig(home, configEnv)
return config, nil
}
func main() {
var (
o = flag.String("o", "", "output directory")
c = flag.String("c", "", "config file")
)
flag.Parse()
config, err := initConfig(*c)
if err != nil {
log.Fatal(err)
}
log.Info(config)
pid, err := config.ReadPid()
if err != nil {
log.Errorf("not found %s", config.PidPath)
pid = 0
}
log.Info("PID:", pid)
log.Info("OUT:", *o)
gopscmd := `gops`
if runtime.GOOS == "windows" {
gopscmd = filepath.Join(config.BinDir, `gops.exe`)
}
log.Info("GOPS:", gopscmd)
// gops memstats 3588
cmdInfo1 := &agent.CommandInfo{
CmdLine: fmt.Sprintf("%s memstats %d", gopscmd, pid),
OutPath: filepath.Join(*o, "gops_memstats.txt"),
Timeout: 10,
}
if err := cmdInfo1.ExecCommandRedirect(); err != nil {
log.Info("ERR:", err)
}
// gops 3588
cmdInfo2 := &agent.CommandInfo{
CmdLine: fmt.Sprintf("%s %d", gopscmd, pid),
OutPath: filepath.Join(*o, "gops.txt"),
Timeout: 10,
}
if err := cmdInfo2.ExecCommandRedirect(); err != nil {
log.Info("ERR:", err)
}
}