aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2015-06-27 03:05:49 +0800
committerPéter Szilágyi <peterke@gmail.com>2015-06-27 03:05:49 +0800
commitd099a42c8564405f2f08b83ec67e0fd96fb03732 (patch)
treef162f6df615922629d4b995804c378f95e95faeb /cmd
parent7e69392249b37369a1dd6e10bb31b7e2e655b05d (diff)
downloadgo-tangerine-d099a42c8564405f2f08b83ec67e0fd96fb03732.tar
go-tangerine-d099a42c8564405f2f08b83ec67e0fd96fb03732.tar.gz
go-tangerine-d099a42c8564405f2f08b83ec67e0fd96fb03732.tar.bz2
go-tangerine-d099a42c8564405f2f08b83ec67e0fd96fb03732.tar.lz
go-tangerine-d099a42c8564405f2f08b83ec67e0fd96fb03732.tar.xz
go-tangerine-d099a42c8564405f2f08b83ec67e0fd96fb03732.tar.zst
go-tangerine-d099a42c8564405f2f08b83ec67e0fd96fb03732.zip
cmd/geth: fix monitor panic, don't pre-fill with dummy data
Diffstat (limited to 'cmd')
-rw-r--r--cmd/geth/monitorcmd.go28
1 files changed, 18 insertions, 10 deletions
diff --git a/cmd/geth/monitorcmd.go b/cmd/geth/monitorcmd.go
index 545ac3274..fe771b561 100644
--- a/cmd/geth/monitorcmd.go
+++ b/cmd/geth/monitorcmd.go
@@ -105,9 +105,6 @@ func monitor(ctx *cli.Context) {
charts := make([]*termui.LineChart, len(monitored))
units := make([]int, len(monitored))
data := make([][]float64, len(monitored))
- for i := 0; i < len(data); i++ {
- data[i] = make([]float64, 512)
- }
for i := 0; i < len(monitored); i++ {
charts[i] = createChart((termui.TermHeight() - footer.Height) / rows)
row := termui.Body.Rows[i%rows]
@@ -238,7 +235,11 @@ func fetchMetric(metrics map[string]interface{}, metric string) float64 {
func refreshCharts(xeth *rpc.Xeth, metrics []string, data [][]float64, units []int, charts []*termui.LineChart, ctx *cli.Context, footer *termui.Par) (realign bool) {
values, err := retrieveMetrics(xeth)
for i, metric := range metrics {
- data[i] = append([]float64{fetchMetric(values, metric)}, data[i][:len(data[i])-1]...)
+ if len(data) < 512 {
+ data[i] = append([]float64{fetchMetric(values, metric)}, data[i]...)
+ } else {
+ data[i] = append([]float64{fetchMetric(values, metric)}, data[i][:len(data[i])-1]...)
+ }
if updateChart(metric, data[i], &units[i], charts[i], err) {
realign = true
}
@@ -255,12 +256,16 @@ func updateChart(metric string, data []float64, base *int, chart *termui.LineCha
colors := []termui.Attribute{termui.ColorBlue, termui.ColorCyan, termui.ColorGreen, termui.ColorYellow, termui.ColorRed, termui.ColorRed}
// Extract only part of the data that's actually visible
- data = data[:chart.Width*2]
-
+ if chart.Width*2 < len(data) {
+ data = data[:chart.Width*2]
+ }
// Find the maximum value and scale under 1K
- high := data[0]
- for _, value := range data[1:] {
- high = math.Max(high, value)
+ high := 0.0
+ if len(data) > 0 {
+ high = data[0]
+ for _, value := range data[1:] {
+ high = math.Max(high, value)
+ }
}
unit, scale := 0, 1.0
for high >= 1000 {
@@ -271,6 +276,10 @@ func updateChart(metric string, data []float64, base *int, chart *termui.LineCha
realign, *base, *chart = true, unit, *createChart(chart.Height)
}
// Update the chart's data points with the scaled values
+ if cap(chart.Data) < len(data) {
+ chart.Data = make([]float64, len(data))
+ }
+ chart.Data = chart.Data[:len(data)]
for i, value := range data {
chart.Data[i] = value / scale
}
@@ -296,7 +305,6 @@ func createChart(height int) *termui.LineChart {
if runtime.GOOS == "windows" {
chart.Mode = "dot"
}
- chart.Data = make([]float64, 512)
chart.DataLabels = []string{""}
chart.Height = height
chart.AxesColor = termui.ColorWhite