/
profiling.go
66 lines (59 loc) · 1.65 KB
/
profiling.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
package cmd
import (
"context"
"fmt"
"go.uber.org/zap"
"k8s.io/utils/exec"
"github.com/ShotaKitazawa/isucontinuous/pkg/config"
"github.com/ShotaKitazawa/isucontinuous/pkg/localrepo"
"github.com/ShotaKitazawa/isucontinuous/pkg/template"
"github.com/ShotaKitazawa/isucontinuous/pkg/usecases/profiling"
)
type ConfigProfiling struct {
ConfigCommon
}
func RunProfiling(conf ConfigProfiling) error {
ctx := context.Background()
logger, err := newLogger(conf.LogLevel, conf.LogFilename)
if err != nil {
return err
}
// Attach local-repo
repo, err := localrepo.AttachLocalRepo(logger, exec.New(), conf.LocalRepoPath)
if err != nil {
return err
}
// Set newProfilingersFunc
return runProfiling(conf, ctx, logger, repo, profiling.New)
}
func runProfiling(
conf ConfigProfiling, ctx context.Context, logger *zap.Logger,
repo localrepo.LocalRepoIface, newProfilingersFunc profiling.NewFunc,
) error {
logger.Info("start profiling")
defer func() { logger.Info("finish profiling") }()
// Load isucontinus.yaml
isucontinuous, err := repo.LoadConf()
if err != nil {
return err
}
// Get revision
gitRevision, err := repo.GetRevision(ctx)
if err != nil {
return fmt.Errorf("%s/.revision is not found. exec `deploy` command first", conf.LocalRepoPath)
}
// Profiling files to per host
return perHostExec(logger, ctx, isucontinuous.Hosts, []task{{
"Profiling",
func(ctx context.Context, host config.Host) error {
profilinger, err := newProfilingersFunc(logger, template.New(gitRevision), host)
if err != nil {
return err
}
if err := profilinger.Profiling(ctx, host.Profiling.Command); err != nil {
return err
}
return nil
},
}})
}