Skip to content

Commit

Permalink
different approach to writing raw data as .json
Browse files Browse the repository at this point in the history
  • Loading branch information
mchinta7 committed Jan 9, 2024
1 parent 9495dbc commit a8d9c40
Showing 1 changed file with 31 additions and 20 deletions.
51 changes: 31 additions & 20 deletions cmd/kperf/commands/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"path/filepath"
"sort"
"strconv"
"time"

"github.com/Azure/kperf/api/types"
"github.com/Azure/kperf/request"
Expand Down Expand Up @@ -160,26 +159,46 @@ func loadConfig(cliCtx *cli.Context) (*types.LoadProfile, error) {
}

func printResponseStats(f *os.File, stats *types.ResponseStats, rawData bool) {

copy := ResponseStatsCopy{}
copy.Total = stats.Total
copy.FailureList = stats.FailureList
copy.TotalReceivedBytes = stats.TotalReceivedBytes
copy.Duration = stats.Duration

copy.PercentileLatencies = make(map[string]string)
percentileLatencies := make(map[string]string)
for i, v := range stats.PercentileLatencies {
iCopy := strconv.FormatFloat(i, 'f', 2, 64)
copy.PercentileLatencies[iCopy] = strconv.FormatFloat(v, 'f', 3, 64)
percentileLatencies[iCopy] = strconv.FormatFloat(v, 'f', 3, 64)
}

if rawData {
b, err := json.MarshalIndent(copy, "", " ")
total, err := json.MarshalIndent(stats.Total, "", " ")
if err != nil {
fmt.Println(err)
return
}
fList, err := json.MarshalIndent(stats.FailureList, "", " ")
if err != nil {
fmt.Println(err)
return
}
fmt.Fprint(f, string(b))
bytes, err := json.MarshalIndent(stats.TotalReceivedBytes, "", " ")
if err != nil {
fmt.Println(err)
return
}
duration, err := json.MarshalIndent(stats.Duration, "", " ")
if err != nil {
fmt.Println(err)
return
}
pLatencies, err := json.MarshalIndent(percentileLatencies, "", " ")
if err != nil {
fmt.Println(err)
return
}
fmt.Fprint(f, "{\n")
fmt.Fprintf(f, " \"Total\": %s,\n", string(total))
fmt.Fprintf(f, " \"Failure List\": %s,\n", string(fList))
fmt.Fprintf(f, " \"Total Received Bytes\":%s,\n", string(bytes))
fmt.Fprintf(f, " \"Duration\":%s,\n", string(duration))
fmt.Fprintf(f, " \"Percentile Latencies\":%s,\n", pLatencies)
fmt.Fprint(f, "}")

} else {
fmt.Fprint(f, "Response Stat: \n")
fmt.Fprintf(f, " Total: %v\n", stats.Total)
Expand Down Expand Up @@ -212,11 +231,3 @@ func printResponseStats(f *os.File, stats *types.ResponseStats, rawData bool) {
}

}

type ResponseStatsCopy struct {
Total int
FailureList []error
TotalReceivedBytes int64
Duration time.Duration
PercentileLatencies map[string]string
}

0 comments on commit a8d9c40

Please sign in to comment.