Skip to content

Commit f38f417

Browse files
Merge pull request #4 from kishaningithub/add-profiling
Add profiling and update documentation
2 parents d7bfc03 + eb9e455 commit f38f417

File tree

5 files changed

+23
-4
lines changed

5 files changed

+23
-4
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,7 @@ tools/
2626
assets.go
2727

2828
# Deps
29-
vendor/*
29+
vendor/*
30+
31+
# Pprof files
32+
*.pprof

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ Command line random text generator
1313
```bash
1414
$ randomtext -h
1515
Usage of randomtext:
16+
-profile string
17+
Type of profile - cpu,mem
1618
-size string
17-
Size of generated random text in KB, MB, GB, TB (default "1MB")
19+
Size of generated random text in KB, MB, GB, TB (default "1MB")
1820
-type string
19-
Type of text to be generated - chars, words, zeros (default "chars")
21+
Type of text to be generated - chars, words, zeros (default "chars")
2022
```
2123

2224
### Examples

cmd/randomtext/main.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"flag"
66
"fmt"
77
"github.com/kishaningithub/randomtext"
8+
"github.com/pkg/profile"
89
"os"
910
"regexp"
1011
"strconv"
@@ -14,7 +15,15 @@ import (
1415
func main() {
1516
sizePtr := flag.String("size", "1MB", "Size of generated random text in KB, MB, GB, TB")
1617
typePtr := flag.String("type", "chars", "Type of text to be generated - chars, words, zeros")
18+
profileTypePtr := flag.String("profile", "", "Type of profile - cpu,mem")
1719
flag.Parse()
20+
profileType := *profileTypePtr
21+
switch profileType {
22+
case "cpu":
23+
defer profile.Start(profile.ProfilePath(".")).Stop()
24+
case "mem":
25+
defer profile.Start(profile.ProfilePath("."), profile.MemProfile).Stop()
26+
}
1827
sizeInBytes, err := parseSize(strings.ToLower(*sizePtr))
1928
handleErr(err)
2029
generator, err := parseType(strings.ToLower(*typePtr))

go.mod

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ module github.com/kishaningithub/randomtext
22

33
go 1.17
44

5-
require github.com/stretchr/testify v1.7.0
5+
require (
6+
github.com/pkg/profile v1.6.0
7+
github.com/stretchr/testify v1.7.0
8+
)
69

710
require (
811
github.com/davecgh/go-spew v1.1.0 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
22
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3+
github.com/pkg/profile v1.6.0 h1:hUDfIISABYI59DyeB3OTay/HxSRwTQ8rB/H83k6r5dM=
4+
github.com/pkg/profile v1.6.0/go.mod h1:qBsxPvzyUincmltOk6iyRVxHYg4adc0OFOv72ZdLa18=
35
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
46
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
57
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=

0 commit comments

Comments
 (0)