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
0 commit comments