Skip to content

Commit

Permalink
Merge pull request #4 from kishaningithub/add-profiling
Browse files Browse the repository at this point in the history
Add profiling and update documentation
  • Loading branch information
kishaningithub authored Oct 30, 2021
2 parents d7bfc03 + eb9e455 commit f38f417
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@ tools/
assets.go

# Deps
vendor/*
vendor/*

# Pprof files
*.pprof
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ Command line random text generator
```bash
$ randomtext -h
Usage of randomtext:
-profile string
Type of profile - cpu,mem
-size string
Size of generated random text in KB, MB, GB, TB (default "1MB")
Size of generated random text in KB, MB, GB, TB (default "1MB")
-type string
Type of text to be generated - chars, words, zeros (default "chars")
Type of text to be generated - chars, words, zeros (default "chars")
```

### Examples
Expand Down
9 changes: 9 additions & 0 deletions cmd/randomtext/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"flag"
"fmt"
"github.com/kishaningithub/randomtext"
"github.com/pkg/profile"
"os"
"regexp"
"strconv"
Expand All @@ -14,7 +15,15 @@ import (
func main() {
sizePtr := flag.String("size", "1MB", "Size of generated random text in KB, MB, GB, TB")
typePtr := flag.String("type", "chars", "Type of text to be generated - chars, words, zeros")
profileTypePtr := flag.String("profile", "", "Type of profile - cpu,mem")
flag.Parse()
profileType := *profileTypePtr
switch profileType {
case "cpu":
defer profile.Start(profile.ProfilePath(".")).Stop()
case "mem":
defer profile.Start(profile.ProfilePath("."), profile.MemProfile).Stop()
}
sizeInBytes, err := parseSize(strings.ToLower(*sizePtr))
handleErr(err)
generator, err := parseType(strings.ToLower(*typePtr))
Expand Down
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ module github.com/kishaningithub/randomtext

go 1.17

require github.com/stretchr/testify v1.7.0
require (
github.com/pkg/profile v1.6.0
github.com/stretchr/testify v1.7.0
)

require (
github.com/davecgh/go-spew v1.1.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pkg/profile v1.6.0 h1:hUDfIISABYI59DyeB3OTay/HxSRwTQ8rB/H83k6r5dM=
github.com/pkg/profile v1.6.0/go.mod h1:qBsxPvzyUincmltOk6iyRVxHYg4adc0OFOv72ZdLa18=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down

0 comments on commit f38f417

Please sign in to comment.