-
Notifications
You must be signed in to change notification settings - Fork 165
Expand file tree
/
Copy pathperf.go
More file actions
81 lines (66 loc) · 1.45 KB
/
perf.go
File metadata and controls
81 lines (66 loc) · 1.45 KB
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
/*
* Xenon
*
* Copyright 2018 The Xenon Authors.
* Code is licensed under the GPLv3.
*
*/
package cmd
import (
"encoding/json"
"fmt"
"xbase/common"
"xbase/xlog"
"github.com/spf13/cobra"
)
func quickStack(log *xlog.Log) (string, error) {
timeout := 10 * 1000 // 10s
cmds := "bash"
args := []string{
"-c",
"sudo quickstack -s -k 10 -p `pidof mysqld`",
}
cmd := common.NewLinuxCommand(log)
return cmd.RunCommandWithTimeout(timeout, cmds, args)
}
func NewPerfCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "perf <subcommand>",
Short: "perf related commands",
}
cmd.AddCommand(NewQuickStackCommand())
return cmd
}
func NewQuickStackCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "quickstack",
Short: "capture the stack of mysqld using quickstack",
Run: quickStackCommandFn,
}
cmd.AddCommand(NewQuickStackJsonCommand())
return cmd
}
func quickStackCommandFn(cmd *cobra.Command, args []string) {
outs, err := quickStack(log)
ErrorOK(err)
fmt.Printf("%v", outs)
}
func NewQuickStackJsonCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "json",
Short: "json format",
Run: quickStackJsonCommandFn,
}
return cmd
}
func quickStackJsonCommandFn(cmd *cobra.Command, args []string) {
type Status struct {
Results string `json:"status"`
}
status := &Status{}
outs, err := quickStack(log)
ErrorOK(err)
status.Results = outs
statusB, _ := json.Marshal(status)
fmt.Printf("%s", string(statusB))
}