Skip to content

Commit 53daae4

Browse files
committed
Rename ProfileMode to Mode
1 parent d046c97 commit 53daae4

File tree

3 files changed

+21
-21
lines changed

3 files changed

+21
-21
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ go get github.com/go-perf/easypprof
3333
```go
3434
func main() {
3535
cfg := easypprof.Config{
36-
ProfileMode: easypprof.CpuMode,
37-
OutputDir: path.Join(".", "test_pprof"),
38-
FilePrefix: "my-app",
36+
Mode: easypprof.CpuMode,
37+
OutputDir: path.Join(".", "test_pprof"),
38+
FilePrefix: "my-app",
3939
}
4040
defer easypprof.Start(cfg).Stop()
4141

easypprof.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ type Config struct {
5858
// Default is false.
5959
Disable bool
6060

61-
// ProfileMode is one of cpu, goroutine, threadcreate, heap, allocs, block, mutex.
61+
// Mode is one of cpu, goroutine, threadcreate, heap, allocs, block, mutex.
6262
// Default is empty string and is treated as cpu.
63-
ProfileMode string
63+
Mode string
6464

6565
// OutputDir where profile must be saved.
6666
// Default is empty string and is treated as ".".
@@ -89,16 +89,16 @@ type Config struct {
8989

9090
// newProfiler creates new profiler based on a config.
9191
func newProfiler(cfg Config) (*Profiler, error) {
92-
if cfg.ProfileMode == "" {
93-
cfg.ProfileMode = CpuMode
92+
if cfg.Mode == "" {
93+
cfg.Mode = CpuMode
9494
}
9595

96-
switch cfg.ProfileMode {
96+
switch cfg.Mode {
9797
case CpuMode, TraceMode, HeapMode, AllocsMode, MutexMode,
9898
BlockMode, ThreadCreateMode, GoroutineMode, FgprofMode:
9999
// pass
100100
default:
101-
return nil, fmt.Errorf("unknown profile mode: %s", cfg.ProfileMode)
101+
return nil, fmt.Errorf("unknown profile mode: %s", cfg.Mode)
102102
}
103103

104104
if cfg.OutputDir == "" {
@@ -119,7 +119,7 @@ func newProfiler(cfg Config) (*Profiler, error) {
119119
prefix = cfg.FilePrefix + "_"
120120
}
121121
now := time.Now().Format("20060102-15:04:05")
122-
filename := fmt.Sprintf("%s%s_%s.pprof", prefix, cfg.ProfileMode, now)
122+
filename := fmt.Sprintf("%s%s_%s.pprof", prefix, cfg.Mode, now)
123123

124124
if err := os.MkdirAll(cfg.OutputDir, 0777); err != nil {
125125
return nil, err
@@ -131,7 +131,7 @@ func newProfiler(cfg Config) (*Profiler, error) {
131131

132132
p := &Profiler{
133133
cfg: cfg,
134-
mode: cfg.ProfileMode,
134+
mode: cfg.Mode,
135135
output: output,
136136
}
137137
return p, nil

example_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
func ExampleEasyPprof() {
1313
cfg := easypprof.Config{
1414
Disable: os.Getenv("NO_EASY_PPROF") == "true",
15-
ProfileMode: easypprof.CpuMode,
15+
Mode: easypprof.CpuMode,
1616
OutputDir: path.Join(".", "test_pprof"),
1717
FilePrefix: "my-app",
1818
UseTextFormat: false,
@@ -26,7 +26,7 @@ func ExampleEasyPprof() {
2626
}
2727

2828
func ExampleMinimalVersion() {
29-
// ProfileMode by default is easypprof.CpuMode
29+
// Mode by default is easypprof.CpuMode
3030
defer easypprof.Start(easypprof.Config{}).Stop()
3131

3232
// Output:
@@ -50,10 +50,10 @@ func ExampleWithEnv() {
5050
mode := os.Getenv("EASY_PPROF_MODE")
5151

5252
defer easypprof.Start(easypprof.Config{
53-
Disable: disable,
54-
ProfileMode: mode,
55-
OutputDir: path.Join(".", "test_pprof"),
56-
FilePrefix: "env",
53+
Disable: disable,
54+
Mode: mode,
55+
OutputDir: path.Join(".", "test_pprof"),
56+
FilePrefix: "env",
5757
}).Stop()
5858

5959
// Output:
@@ -65,10 +65,10 @@ func ExampleWithFlags() {
6565
flag.Parse()
6666

6767
defer easypprof.Start(easypprof.Config{
68-
Disable: *disable,
69-
ProfileMode: *mode,
70-
OutputDir: path.Join(".", "test_pprof"),
71-
FilePrefix: "flag",
68+
Disable: *disable,
69+
Mode: *mode,
70+
OutputDir: path.Join(".", "test_pprof"),
71+
FilePrefix: "flag",
7272
}).Stop()
7373

7474
// Output:

0 commit comments

Comments
 (0)