Skip to content

Commit

Permalink
Enhance HTML with new hotqueries and query plan general info
Browse files Browse the repository at this point in the history
Signed-off-by: Florent Poinsard <[email protected]>
  • Loading branch information
frouioui committed Dec 12, 2024
1 parent e70d1db commit ff2bae4
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 23 deletions.
5 changes: 2 additions & 3 deletions go/summarize/markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,7 @@ func renderTransactions(md *markdown.MarkDown, transactions []TransactionSummary
}

func renderPlansSection(md *markdown.MarkDown, analysis PlanAnalysis) error {
sum := analysis.PassThrough + analysis.SimpleRouted + analysis.Complex + analysis.Unplannable
if sum == 0 {
if analysis.Total == 0 {
return nil
}

Expand All @@ -241,7 +240,7 @@ func renderPlansSection(md *markdown.MarkDown, analysis PlanAnalysis) error {
{planalyze.SimpleRouted.String(), strconv.Itoa(analysis.SimpleRouted)},
{planalyze.Complex.String(), strconv.Itoa(analysis.Complex)},
{planalyze.Unplannable.String(), strconv.Itoa(analysis.Unplannable)},
{"Total", strconv.Itoa(sum)},
{"Total", strconv.Itoa(analysis.Total)},
}
md.PrintTable(headers, rows)
md.NewLine()
Expand Down
7 changes: 4 additions & 3 deletions go/summarize/summarize-planalyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,18 @@ import (
)

func summarizePlanAnalyze(s *Summary, data planalyze.Output) (err error) {
s.planAnalysis = PlanAnalysis{
s.PlanAnalysis = PlanAnalysis{
PassThrough: len(data.PassThrough),
SimpleRouted: len(data.SimpleRouted),
Complex: len(data.Complex),
Unplannable: len(data.Unplannable),
}
s.PlanAnalysis.Total = s.PlanAnalysis.PassThrough + s.PlanAnalysis.SimpleRouted + s.PlanAnalysis.Complex + s.PlanAnalysis.Unplannable

s.addPlanResult(data.SimpleRouted)
s.addPlanResult(data.Complex)

s.planAnalysis.simpleRouted = append(s.planAnalysis.simpleRouted, data.SimpleRouted...)
s.planAnalysis.complex = append(s.planAnalysis.complex, data.Complex...)
s.PlanAnalysis.simpleRouted = append(s.PlanAnalysis.simpleRouted, data.SimpleRouted...)
s.PlanAnalysis.complex = append(s.PlanAnalysis.complex, data.Complex...)
return nil
}
14 changes: 7 additions & 7 deletions go/summarize/summarize.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,26 +179,26 @@ func compileSummary(s *Summary) error {

func compileHotQueries(s *Summary) error {
for _, result := range s.queries {
checkQueryForHotness(&s.hotQueries, result, s.hotQueryFn)
checkQueryForHotness(&s.HotQueries, result, s.hotQueryFn)
}
var hasTime bool
sort.Slice(s.hotQueries, func(i, j int) bool {
if s.hotQueries[i].QueryAnalysisResult.QueryTime != 0 {
sort.Slice(s.HotQueries, func(i, j int) bool {
if s.HotQueries[i].QueryAnalysisResult.QueryTime != 0 {
hasTime = true
}
fnI := s.hotQueryFn(s.hotQueries[i].QueryAnalysisResult)
fnJ := s.hotQueryFn(s.hotQueries[j].QueryAnalysisResult)
fnI := s.hotQueryFn(s.HotQueries[i].QueryAnalysisResult)
fnJ := s.hotQueryFn(s.HotQueries[j].QueryAnalysisResult)

// if the two metrics are equal, sort them by alphabetical order
if fnI == fnJ {
return s.hotQueries[i].QueryAnalysisResult.QueryStructure > s.hotQueries[j].QueryAnalysisResult.QueryStructure
return s.HotQueries[i].QueryAnalysisResult.QueryStructure > s.HotQueries[j].QueryAnalysisResult.QueryStructure
}
return fnI > fnJ
})

// If we did not record any time, there is no hotness to record, so removing the field so it does not get rendered.
if !hasTime {
s.hotQueries = nil
s.HotQueries = nil
}
return nil
}
Expand Down
10 changes: 5 additions & 5 deletions go/summarize/summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ type (
Tables []*TableSummary
Failures []FailuresSummary
Transactions []TransactionSummary
HotQueries []keys.QueryAnalysisResult
planAnalysis PlanAnalysis
hotQueries []HotQueryResult
PlanAnalysis PlanAnalysis
HotQueries []HotQueryResult
hotQueryFn getMetric
AnalyzedFiles []string
queryGraph queryGraph
Expand Down Expand Up @@ -88,6 +87,7 @@ type (
SimpleRouted int
Complex int
Unplannable int
Total int

simpleRouted []planalyze.AnalyzedQuery
complex []planalyze.AnalyzedQuery
Expand Down Expand Up @@ -137,11 +137,11 @@ func (s *Summary) PrintMarkdown(out io.Writer, now time.Time) error {
s.AnalyzedFiles[i] = "`" + file + "`"
}
md.Printf(msg, now.Format(time.DateTime), filePlural, strings.Join(s.AnalyzedFiles, ", "))
err := renderPlansSection(md, s.planAnalysis)
err := renderPlansSection(md, s.PlanAnalysis)
if err != nil {
return err
}
renderHotQueries(md, s.hotQueries)
renderHotQueries(md, s.HotQueries)
renderTableUsage(md, s.Tables, s.HasRowCount)
renderTablesJoined(md, s)
renderTransactions(md, s.Transactions)
Expand Down
44 changes: 39 additions & 5 deletions go/web/templates/summarize.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,40 @@ <h1>Query Analysis Report</h1>
</thead>
</table>

<button class="collapsible">Query Planning</button>
<div class="content">
<table>
<thead>
<tr>
<th>Plan Complexity</th>
<th>Count</th>
</tr>
</thead>
<tbody>
<tr>
<td>Pass-through</td>
<td>{{.PlanAnalysis.PassThrough}}</td>
</tr>
<tr>
<td>Simple routed</td>
<td>{{.PlanAnalysis.SimpleRouted}}</td>
</tr>
<tr>
<td>Complex routed</td>
<td>{{.PlanAnalysis.Complex}}</td>
</tr>
<tr>
<td>Unplannable</td>
<td>{{.PlanAnalysis.Unplannable}}</td>
</tr>
<tr>
<td>Total</td>
<td>{{.PlanAnalysis.Total}}</td>
</tr>
</tbody>
</table>
</div>

<button class="collapsible">Top Queries</button>
<div class="content">
<table>
Expand All @@ -29,10 +63,10 @@ <h1>Query Analysis Report</h1>
{{range $index, $query := .HotQueries}}
<tr>
<td>{{$index | add 1}}</td> <!-- Add 1 to start numbering from 1 -->
<td>{{$query.UsageCount}}</td>
<td>{{$query.QueryTime}}</td>
<td>{{divide .QueryTime .UsageCount}}</td>
<td>{{$query.RowsExamined}}</td>
<td>{{$query.QueryAnalysisResult.UsageCount}}</td>
<td>{{$query.QueryAnalysisResult.QueryTime}}</td>
<td>{{divide $query.QueryAnalysisResult.QueryTime $query.QueryAnalysisResult.UsageCount}}</td>
<td>{{$query.QueryAnalysisResult.RowsExamined}}</td>
</tr>
{{end}}
</tbody>
Expand All @@ -52,7 +86,7 @@ <h1>Query Analysis Report</h1>
{{range $index, $query := .HotQueries}}
<tr>
<td style="text-align: right">{{$index | add 1}}</td>
<td style="text-align: left"><code>{{.QueryStructure}}</code></td>
<td style="text-align: left"><code>{{$query.QueryAnalysisResult.QueryStructure}}</code></td>
</tr>
{{end}}
</tbody>
Expand Down

0 comments on commit ff2bae4

Please sign in to comment.