MCPcopy
hub / github.com/nakabonne/ali / redrawCharts

Method redrawCharts

gui/drawer.go:42–101  ·  view source on GitHub ↗

redrawCharts sets the values held by itself as chart values, at the specified interval as redrawInterval.

(ctx context.Context)

Source from the content-addressed store, hash-verified

40
41// redrawCharts sets the values held by itself as chart values, at the specified interval as redrawInterval.
42func (d *drawer) redrawCharts(ctx context.Context) {
43 ticker := time.NewTicker(d.redrawInterval)
44 defer ticker.Stop()
45
46 d.chartDrawing.Store(true)
47L:
48 for {
49 select {
50 case <-ctx.Done():
51 break L
52 case <-ticker.C:
53 end := time.Now()
54 start := end.Add(-d.queryRange)
55
56 latencies, err := d.storage.Select(storage.LatencyMetricName, start, end)
57 if err != nil {
58 log.Printf("failed to select latency data points: %v\n", err)
59 }
60 d.widgets.latencyChart.Series("latency", latencies,
61 linechart.SeriesCellOpts(cell.FgColor(cell.ColorNumber(87))),
62 linechart.SeriesXLabels(map[int]string{
63 0: "req",
64 }),
65 )
66
67 p50, err := d.storage.Select(storage.P50MetricName, start, end)
68 if err != nil {
69 log.Printf("failed to select p50 data points: %v\n", err)
70 }
71 d.widgets.percentilesChart.Series("p50", p50,
72 linechart.SeriesCellOpts(d.widgets.p50Legend.cellOpts...),
73 )
74
75 p90, err := d.storage.Select(storage.P90MetricName, start, end)
76 if err != nil {
77 log.Printf("failed to select p90 data points: %v\n", err)
78 }
79 d.widgets.percentilesChart.Series("p90", p90,
80 linechart.SeriesCellOpts(d.widgets.p90Legend.cellOpts...),
81 )
82
83 p95, err := d.storage.Select(storage.P95MetricName, start, end)
84 if err != nil {
85 log.Printf("failed to select p95 data points: %v\n", err)
86 }
87 d.widgets.percentilesChart.Series("p95", p95,
88 linechart.SeriesCellOpts(d.widgets.p95Legend.cellOpts...),
89 )
90
91 p99, err := d.storage.Select(storage.P99MetricName, start, end)
92 if err != nil {
93 log.Printf("failed to select p99 data points: %v\n", err)
94 }
95 d.widgets.percentilesChart.Series("p99", p99,
96 linechart.SeriesCellOpts(d.widgets.p99Legend.cellOpts...),
97 )
98 }
99 }

Callers 2

TestRedrawChartsFunction · 0.95
attackFunction · 0.80

Calls 3

StopMethod · 0.65
SelectMethod · 0.65
SeriesMethod · 0.65

Tested by 1

TestRedrawChartsFunction · 0.76