Skip to content

Commit

Permalink
remove profiling stuff - easy to do via command line or IDE
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Bray <tbray@textuality.com>
  • Loading branch information
timbray committed Apr 12, 2024
1 parent ba69bce commit 2f265c6
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 91 deletions.
34 changes: 6 additions & 28 deletions internal/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@ import (
)

type Config struct {
Size int
Fields []uint
Fname string
Filter Filters
Width int
Sample bool
CPUProfile string
TraceFname string
Size int
Fields []uint
Fname string
Filter Filters
Width int
Sample bool
}

func Configure(args []string) (*Config, error) {
Expand Down Expand Up @@ -45,26 +43,6 @@ func Configure(args []string) (*Config, error) {
i++
config.Fields, err = parseFields(args[i])
}
case arg == "--cpuprofile":
if (i + 1) >= len(args) {
err = errors.New("insufficient arguments for --cpuprofile")
} else {
/* == ENABLE PROFILING ==
i++
config.CPUProfile = args[i]
*/
err = errors.New("to enable profiling, uncomment lines marked ENABLE PROFILING")
}
case arg == "--trace":
if (i + 1) >= len(args) {
err = errors.New("insufficient arguments for --trace")
} else {
/* == ENABLE PROFILING ==
i++
config.TraceFname = args[i]
*/
err = errors.New("to enable profiling, uncomment lines marked ENABLE PROFILING")
}
case arg == "-g" || arg == "--grep":
if (i + 1) >= len(args) {
err = errors.New("insufficient arguments for --grep")
Expand Down
7 changes: 0 additions & 7 deletions internal/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ func TestArgSyntax(t *testing.T) {
{"--sample", "--trace"}, {"--trace"},
{"--sed"}, {"-s", "x"}, {"--sample", "--sed", "1"},
{"--width", "a"}, {"-w", "0"}, {"--sample", "-w"},
// COMMENT OUT FOLLOWING TO ENABLE TRACING
{"--cpuprofile", "/tmp/cp"},
{"--trace", "/tmp/tr"},
}

// not testing -h/--help because it'd be extra work to avoid printing out the usage
Expand All @@ -29,10 +26,6 @@ func TestArgSyntax(t *testing.T) {
{"--sample"},
{"--width", "2"}, {"-w", "3"},
{"--sample", "fname"},
/* == ENABLE PROFILING ==
{"--cpuprofile", "/tmp/cp"},
{"--trace", "/tmp/tr"},
*/
}

for _, bad := range bads {
Expand Down
30 changes: 0 additions & 30 deletions internal/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,6 @@ func Run(config *Config, instream io.Reader) ([]*KeyCount, error) {
var topList []*KeyCount
var err error

/* == ENABLE PROFILING ==
if config.CPUProfile != "" {
f, err := os.Create(config.CPUProfile)
if err != nil {
_, _ = fmt.Fprintf(os.Stderr, "can't create profiler: %s\n", err.Error())
return nil, err
}
err = pprof.StartCPUProfile(f)
if err != nil {
_, _ = fmt.Fprintf(os.Stderr, "can't start profiler: %s\n", err.Error())
return nil, err
}
defer pprof.StopCPUProfile()
}
if config.TraceFname != "" {
f, err := os.Create(config.TraceFname)
if err != nil {
_, _ = fmt.Fprintf(os.Stderr, "can't create trace output file: %s\n", err.Error())
return nil, err
}
// The generated trace can be analyzed with: go tool trace <tracefile>
err = trace.Start(f)
if err != nil {
_, _ = fmt.Fprintf(os.Stderr, "can't start tracing: %s\n", err.Error())
return nil, err
}
defer trace.Stop()
}
*/

if config.Fname == "" {
if config.Sample {
for i, sed := range config.Filter.Seds {
Expand Down
26 changes: 0 additions & 26 deletions internal/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,6 @@ import (
"testing"
)

/* == ENABLE PROFILING ==
func TestRunner(t *testing.T) {
var err error
var c *Config
bads := [][]string{
{"--cpuprofile", "/"},
{"--trace", "/"},
}
for _, bad := range bads {
osBad := []string{"OS"}
osBad = append(osBad, bad...)
c, err = Configure(osBad)
if err != nil {
t.Error("Configure!")
}
_, err = Run(c, nil)
if err == nil {
t.Error("Accepted bogus config")
}
}
}
*/

func TestStreamAndFile(t *testing.T) {
args := []string{"-f", "7", "../test/data/apache-50k.txt"}

Expand Down

0 comments on commit 2f265c6

Please sign in to comment.