-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
cpu-profile
interactive command (#1358)
* Add cpu-profile interactive command * better doc markdown Signed-off-by: Tim Vaillancourt <[email protected]> * set block profile after isProfiling=1 Signed-off-by: Tim Vaillancourt <[email protected]> * improve test Signed-off-by: Tim Vaillancourt <[email protected]> * check isCPUProfiling later Signed-off-by: Tim Vaillancourt <[email protected]> * Cleanup Signed-off-by: Tim Vaillancourt <[email protected]> * Fix discrepancy Signed-off-by: Tim Vaillancourt <[email protected]> * move base64 to .applyServerCommand(...) Signed-off-by: Tim Vaillancourt <[email protected]> --------- Signed-off-by: Tim Vaillancourt <[email protected]> Co-authored-by: meiji163 <[email protected]>
- Loading branch information
1 parent
3aa6912
commit b1aae87
Showing
3 changed files
with
138 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package logic | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/github/gh-ost/go/base" | ||
"github.com/openark/golib/tests" | ||
) | ||
|
||
func TestServerRunCPUProfile(t *testing.T) { | ||
t.Parallel() | ||
|
||
t.Run("failed already running", func(t *testing.T) { | ||
s := &Server{isCPUProfiling: 1} | ||
profile, err := s.runCPUProfile("15ms") | ||
tests.S(t).ExpectEquals(err, ErrCPUProfilingInProgress) | ||
tests.S(t).ExpectEquals(profile, nil) | ||
}) | ||
|
||
t.Run("failed bad duration", func(t *testing.T) { | ||
s := &Server{isCPUProfiling: 0} | ||
profile, err := s.runCPUProfile("should-fail") | ||
tests.S(t).ExpectNotNil(err) | ||
tests.S(t).ExpectEquals(profile, nil) | ||
}) | ||
|
||
t.Run("failed bad option", func(t *testing.T) { | ||
s := &Server{isCPUProfiling: 0} | ||
profile, err := s.runCPUProfile("10ms,badoption") | ||
tests.S(t).ExpectEquals(err, ErrCPUProfilingBadOption) | ||
tests.S(t).ExpectEquals(profile, nil) | ||
}) | ||
|
||
t.Run("success", func(t *testing.T) { | ||
s := &Server{ | ||
isCPUProfiling: 0, | ||
migrationContext: base.NewMigrationContext(), | ||
} | ||
defaultCPUProfileDuration = time.Millisecond * 10 | ||
profile, err := s.runCPUProfile("") | ||
tests.S(t).ExpectNil(err) | ||
tests.S(t).ExpectNotEquals(profile, nil) | ||
tests.S(t).ExpectEquals(s.isCPUProfiling, int64(0)) | ||
}) | ||
|
||
t.Run("success with block", func(t *testing.T) { | ||
s := &Server{ | ||
isCPUProfiling: 0, | ||
migrationContext: base.NewMigrationContext(), | ||
} | ||
profile, err := s.runCPUProfile("10ms,block") | ||
tests.S(t).ExpectNil(err) | ||
tests.S(t).ExpectNotEquals(profile, nil) | ||
tests.S(t).ExpectEquals(s.isCPUProfiling, int64(0)) | ||
}) | ||
|
||
t.Run("success with block and gzip", func(t *testing.T) { | ||
s := &Server{ | ||
isCPUProfiling: 0, | ||
migrationContext: base.NewMigrationContext(), | ||
} | ||
profile, err := s.runCPUProfile("10ms,block,gzip") | ||
tests.S(t).ExpectNil(err) | ||
tests.S(t).ExpectNotEquals(profile, nil) | ||
tests.S(t).ExpectEquals(s.isCPUProfiling, int64(0)) | ||
}) | ||
} |