Skip to content

Commit 6931b82

Browse files
Feat/improve hdr plot output (#10)
* use -1 for missed latencies * fix min latency calc * save hdr plot to file * add hdr plot to output * improve log --------- Co-authored-by: tosettil-polimi <info@tosettil.me>
1 parent 1090cfc commit 6931b82

File tree

2 files changed

+30
-17
lines changed

2 files changed

+30
-17
lines changed

pkg/coordinator/tasks/tx_pool_latency_analysis/task.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import (
55
"encoding/json"
66
"fmt"
77
"github.com/noku-team/assertoor/pkg/coordinator/utils/tx_load_tool"
8+
"math"
89
"math/rand"
10+
"os"
911
"time"
1012

1113
"github.com/ethereum/go-ethereum/crypto"
@@ -151,16 +153,17 @@ func (t *Task) Execute(ctx context.Context) error {
151153

152154
// Calculate statistics
153155
var maxLatency int64 = 0
154-
var minLatency int64 = 0
156+
var minLatency int64 = math.MaxInt64
155157
for _, lat := range result.LatenciesMus {
156158
if lat > maxLatency {
157159
maxLatency = lat
158160
}
159-
if lat < minLatency {
161+
if lat < minLatency && lat > 0 {
160162
minLatency = lat
161163
}
162164
}
163-
t.logger.Infof("Max latency: %d mus, Min latency: %d mus", maxLatency, minLatency)
165+
t.logger.Infof("Max latency: %d mus (%d ms), Min latency: %d mus (%d ms)",
166+
maxLatency, maxLatency/1000, minLatency, minLatency/1000)
164167

165168
// Generate HDR plot
166169
plot, err := hdr.HdrPlot(result.LatenciesMus)
@@ -169,13 +172,23 @@ func (t *Task) Execute(ctx context.Context) error {
169172
t.ctx.SetResult(types.TaskResultFailure)
170173
return nil
171174
}
175+
t.logger.Infof("HDR plot generated successfully")
176+
plotFilePath := "tx_pool_latency_hdr_plot.csv"
177+
err = os.WriteFile(plotFilePath, []byte(plot), 0644)
178+
if err != nil {
179+
t.logger.Errorf("Failed to write HDR plot to file: %v", err)
180+
t.ctx.SetResult(types.TaskResultFailure)
181+
return nil
182+
}
183+
t.logger.Infof("HDR plot saved to file: %s", plotFilePath)
172184

173185
t.ctx.Outputs.SetVar("tx_count", result.TotalTxs)
174186
t.ctx.Outputs.SetVar("min_latency_mus", minLatency)
175187
t.ctx.Outputs.SetVar("max_latency_mus", maxLatency)
176188
t.ctx.Outputs.SetVar("duplicated_p2p_event_count", result.DuplicatedP2PEventCount)
177189
t.ctx.Outputs.SetVar("missed_p2p_event_count", result.NotReceivedP2PEventCount)
178190
t.ctx.Outputs.SetVar("coordinated_omission_event_count", result.CoordinatedOmissionEventCount)
191+
t.ctx.Outputs.SetVar("hdr_plot", plot)
179192

180193
t.ctx.SetResult(types.TaskResultSuccess)
181194

pkg/coordinator/utils/tx_load_tool/tx_load_tool.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,23 +71,23 @@ func NewLoadResult(totNumberOfTxes int) *LoadResult {
7171
}
7272

7373
type Load struct {
74-
target *LoadTarget
75-
testDeadline time.Time
76-
TPS int
77-
Duration_s int
78-
LogInterval int
79-
Result *LoadResult
74+
target *LoadTarget
75+
testDeadline time.Time
76+
TPS int
77+
Duration_s int
78+
LogInterval int
79+
Result *LoadResult
8080
}
8181

8282
// NewLoad creates a new Load instance
8383
func NewLoad(target *LoadTarget, TPS int, duration_s int, testDeadline time.Time, logInterval int) *Load {
8484
return &Load{
85-
target: target,
86-
TPS: TPS,
87-
Duration_s: duration_s,
88-
testDeadline: testDeadline,
89-
LogInterval: logInterval,
90-
Result: NewLoadResult(TPS * duration_s),
85+
target: target,
86+
TPS: TPS,
87+
Duration_s: duration_s,
88+
testDeadline: testDeadline,
89+
LogInterval: logInterval,
90+
Result: NewLoadResult(TPS * duration_s),
9191
}
9292
}
9393

@@ -288,11 +288,11 @@ func (l *Load) MeasurePropagationLatencies() (*LoadResult, error) {
288288
if l.Result.LatenciesMus[i] == 0 {
289289
l.Result.NotReceivedP2PEventCount++
290290
// Assign a default value for missing P2P events
291-
l.Result.LatenciesMus[i] = (time.Duration(l.Duration_s) * time.Second).Microseconds()
291+
l.Result.LatenciesMus[i] = -1
292292
}
293293
}
294294
if l.Result.NotReceivedP2PEventCount > 0 {
295-
l.target.logger.Warnf("Missed p2p events: %d (assigned latency=duration)", l.Result.NotReceivedP2PEventCount)
295+
l.target.logger.Warnf("Missed p2p events: %d", l.Result.NotReceivedP2PEventCount)
296296
}
297297

298298
return l.Result, nil

0 commit comments

Comments
 (0)