Skip to content

Commit 295e2d9

Browse files
addressing after review
1 parent 7b68d65 commit 295e2d9

File tree

3 files changed

+14
-20
lines changed

3 files changed

+14
-20
lines changed

examples/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@
33
### Profiling
44
Prerequisite: `go get github.com/pkg/profile`
55

6-
* CPU profile. Execute: `go build -ldflags "-X main.RunCPUProfile=true" main_profile_feature.go && ./main_profile_feature`. It will create cpu.pprof file in your current directory. Then run: `go tool pprof -http=:8080 cpu.pprof` and profile cpu usage using web browser.
7-
* Memory profile. Execute: `go build -ldflags "-X main.RunMemProfile=true" main_profile_feature.go.go && ./main_profile_feature`. It will create mem.pprof file in your current directory. Then run: `go tool pprof -http=:8080 mem.pprof` and profile memory using browser.
6+
DATAFILES_DIR env var has to be set to point to the path where 100_entities.json is located
7+
8+
* CPU profile. Execute: `go build -ldflags "-X main.ProfileMode=cpu" main_profile_feature.go && ./main_profile_feature`. It will create cpu.pprof file in your current directory. Then run: `go tool pprof -http=:8080 cpu.pprof` and profile cpu usage using web browser.
9+
* Memory profile. Execute: `go build -ldflags "-X main.ProfileMode=mem" main_profile_feature.go.go && ./main_profile_feature`. It will create mem.pprof file in your current directory. Then run: `go tool pprof -http=:8080 mem.pprof` and profile memory using browser.

examples/main_profile_feature.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// to run the CPU profiling: go build -ldflags "-X main.RunCPUProfile=true" main.go && ./main
2-
// to run the Mem profiling: go build -ldflags "-X main.RunMemProfile=true" main.go && ./main
1+
// to run the CPU profiling: go build -ldflags "-X main.ProfileMode=mem" main_profile_feature.go && ./main_profile_feature
32

43
package main
54

@@ -17,7 +16,6 @@ import (
1716
"github.com/pkg/profile"
1817
)
1918

20-
// stressTest has everything that test app has. it is used to run profile
2119
func stressTest() {
2220
/*
2321
For the test app, the biggest json file is used with 100 entities.
@@ -57,17 +55,18 @@ func stressTest() {
5755
clientApp.IsFeatureEnabled("feature_5", user)
5856
}
5957

60-
var RunMemProfile = "false"
61-
var RunCPUProfile = "false"
58+
var ProfileMode = ""
59+
60+
const RUN_NUMBER = 50
6261

6362
func main() {
6463

65-
if RunMemProfile == "true" || RunCPUProfile == "true" {
64+
if ProfileMode != "" {
6665

67-
const RUN_NUMBER = 50
68-
if RunMemProfile == "true" {
66+
switch ProfileMode {
67+
case "mem":
6968
defer profile.Start(profile.MemProfile, profile.ProfilePath("."), profile.MemProfileRate(1)).Stop()
70-
} else if RunCPUProfile == "true" {
69+
case "cpu":
7170
defer profile.Start(profile.CPUProfile, profile.ProfilePath(".")).Stop()
7271
}
7372

optimizely/config/datafileprojectconfig/json_parser_test.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@
1717
package datafileprojectconfig
1818

1919
import (
20-
"encoding/json"
2120
"fmt"
2221
"io/ioutil"
23-
"log"
2422
"testing"
2523

2624
"github.com/optimizely/go-sdk/optimizely/config/datafileprojectconfig/entities"
@@ -65,14 +63,9 @@ func TestParseDatafilePasses(t *testing.T) {
6563

6664
func BenchmarkParseDatafilePasses(b *testing.B) {
6765
for n := 0; n < b.N; n++ {
68-
datafile, err := ioutil.ReadFile("test/100_entities.json")
69-
if err != nil {
70-
log.Fatal(err)
71-
}
66+
datafile, _ := ioutil.ReadFile("test/100_entities.json")
7267

73-
datafileStruct := &entities.Datafile{}
74-
75-
json.Unmarshal(datafile, &datafileStruct)
68+
Parse(datafile)
7669

7770
}
7871

0 commit comments

Comments
 (0)