Skip to content

Commit

Permalink
fixed unexported fields for JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
eze-kiel committed Apr 20, 2021
1 parent 7ae6562 commit dfa5c64
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 58 deletions.
3 changes: 0 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

GOCMD=go
GOTEST=$(GOCMD) test
GOVET=$(GOCMD) vet
Expand All @@ -16,12 +15,10 @@ all: help

## Build:
digest: ## Build slowql-digest
mkdir -p ./out/bin
GO111MODULE=on $(GOCMD) build -o $(BUILD_ROOT)digest ./cmd/slowql-digest/
@echo "${GREEN}[*]${RESET} digest successfully built in ${YELLOW}${BUILD_ROOT}digest${RESET}"

replayer: ## Build slowql-replayer
mkdir -p ./out/bin
GO111MODULE=on $(GOCMD) build -o $(BUILD_ROOT)replayer ./cmd/slowql-replayer/
@echo "${GREEN}[*]${RESET} replayer successfully built in ${YELLOW}${BUILD_ROOT}replayer${RESET}"

Expand Down
40 changes: 20 additions & 20 deletions cmd/slowql-digest/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,37 +53,37 @@ func newApp(loglevel, kind string) (*app, error) {
func (a *app) digest(q query.Query, wg *sync.WaitGroup) error {
defer wg.Done()
var s statistics
s.fingerprint = fingerprint(q.Query)
s.hash = hash(s.fingerprint)
s.Fingerprint = fingerprint(q.Query)
s.Hash = hash(s.Fingerprint)

a.mu.Lock()
if cur, ok := a.res[s.hash]; ok {
if cur, ok := a.res[s.Hash]; ok {
// there is already results
cur.calls++
cur.cumBytesSent += q.BytesSent
cur.cumKilled += q.Killed
cur.cumLockTime += time.Duration(q.LockTime)
cur.cumRowsExamined += q.RowsExamined
cur.cumRowsSent += q.RowsSent
s.cumQueryTime += time.Duration(q.QueryTime)
cur.Calls++
cur.CumBytesSent += q.BytesSent
cur.CumKilled += q.Killed
cur.CumLockTime += time.Duration(q.LockTime)
cur.CumRowsExamined += q.RowsExamined
cur.CumRowsSent += q.RowsSent
s.CumQueryTime += time.Duration(q.QueryTime)

// update the entry in the map
a.res[s.hash] = cur
a.res[s.Hash] = cur
} else {
// it is the first time this hash appears
s.calls++
s.cumBytesSent = q.BytesSent
s.cumKilled = q.Killed
s.cumLockTime = time.Duration(q.LockTime)
s.cumRowsExamined = q.RowsExamined
s.cumRowsSent = q.RowsSent
s.cumQueryTime = time.Duration(q.QueryTime)
s.Calls++
s.CumBytesSent = q.BytesSent
s.CumKilled = q.Killed
s.CumLockTime = time.Duration(q.LockTime)
s.CumRowsExamined = q.RowsExamined
s.CumRowsSent = q.RowsSent
s.CumQueryTime = time.Duration(q.QueryTime)

// getting those values is done only once: same hash == same fingerprint & schema
s.schema = q.Schema
s.Schema = q.Schema

// add the entry to the map
a.res[s.hash] = s
a.res[s.Hash] = s
}
a.mu.Unlock()

Expand Down
70 changes: 35 additions & 35 deletions cmd/slowql-digest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,24 @@ type options struct {
}

type statistics struct {
hash string
fingerprint string
schema string
calls int
cumErrored int
cumKilled int
cumQueryTime time.Duration
cumLockTime time.Duration
cumRowsSent int
cumRowsExamined int
cumBytesSent int
concurrency float64
minTime time.Duration
maxTime time.Duration
meanTime time.Duration
p50Time time.Duration
p95Time time.Duration
stddevTime time.Duration
Hash string
Fingerprint string
Schema string
Calls int
CumErrored int
CumKilled int
CumQueryTime time.Duration
CumLockTime time.Duration
CumRowsSent int
CumRowsExamined int
CumBytesSent int
Concurrency float64
MinTime time.Duration
MaxTime time.Duration
MeanTime time.Duration
P50Time time.Duration
P95Time time.Duration
StddevTime time.Duration
}

var orders = []string{"random", "calls", "bytes_sent", "query_time", "lock_time",
Expand Down Expand Up @@ -216,16 +216,16 @@ Cum Query Time: %s
`,
Bold(Underline("Query #")),
Bold(Underline(i+1)),
res[i].calls,
res[i].hash,
res[i].fingerprint,
res[i].schema,
res[i].cumBytesSent,
res[i].cumRowsExamined,
res[i].cumRowsSent,
res[i].cumKilled,
res[i].cumLockTime,
res[i].cumQueryTime,
res[i].Calls,
res[i].Hash,
res[i].Fingerprint,
res[i].Schema,
res[i].CumBytesSent,
res[i].CumRowsExamined,
res[i].CumRowsSent,
res[i].CumKilled,
res[i].CumLockTime,
res[i].CumQueryTime,
)

count--
Expand Down Expand Up @@ -257,31 +257,31 @@ func sortResults(s []statistics, order string, dec bool) ([]statistics, error) {
break
case "calls":
sort.SliceStable(s, func(i, j int) bool {
return s[i].calls < s[j].calls
return s[i].Calls < s[j].Calls
})
case "bytes_sent":
sort.SliceStable(s, func(i, j int) bool {
return s[i].cumBytesSent < s[j].cumBytesSent
return s[i].CumBytesSent < s[j].CumBytesSent
})
case "query_time":
sort.SliceStable(s, func(i, j int) bool {
return s[i].cumQueryTime < s[j].cumQueryTime
return s[i].CumQueryTime < s[j].CumQueryTime
})
case "lock_time":
sort.SliceStable(s, func(i, j int) bool {
return s[i].cumLockTime < s[j].cumLockTime
return s[i].CumLockTime < s[j].CumLockTime
})
case "rows_sent":
sort.SliceStable(s, func(i, j int) bool {
return s[i].cumRowsSent < s[j].cumRowsSent
return s[i].CumRowsSent < s[j].CumRowsSent
})
case "rows_examined":
sort.SliceStable(s, func(i, j int) bool {
return s[i].cumRowsExamined < s[j].cumRowsExamined
return s[i].CumRowsExamined < s[j].CumRowsExamined
})
case "killed":
sort.SliceStable(s, func(i, j int) bool {
return s[i].cumKilled < s[j].cumKilled
return s[i].CumKilled < s[j].CumKilled
})
default:
return nil, errors.New("unknown order, using 'random'")
Expand Down

0 comments on commit dfa5c64

Please sign in to comment.