-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
68 lines (56 loc) · 2.36 KB
/
main.go
File metadata and controls
68 lines (56 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"fmt"
"log"
"time"
"github.com/AnonC0DER/SpeedBench/internal/config"
"github.com/AnonC0DER/SpeedBench/internal/downloader"
"github.com/AnonC0DER/SpeedBench/internal/exporter"
"github.com/AnonC0DER/SpeedBench/internal/stats"
"github.com/AnonC0DER/SpeedBench/internal/utils"
)
func main() {
cfg := config.Load()
config.Validate(cfg)
utils.PrepareLogging(cfg)
fmt.Println("Starting aria2c loop...")
fmt.Printf("Source: %s\n", cfg.SourceName)
fmt.Printf("URL: %s\n", cfg.URL)
fmt.Printf("Iterations: %d\n\n", cfg.Times)
startTime := time.Now()
iterations := downloader.RunLoop(cfg)
endTime := time.Now()
fmt.Println("\naria2c loop finished")
if cfg.LogType == "file" {
fmt.Printf("Logs saved to %s\n", cfg.LogFile)
}
agg := stats.CalculateAggregateMetrics(cfg, iterations, startTime, endTime)
fmt.Printf("\n=== Summary ===\n")
fmt.Printf("Success Rate: %.2f%% (%d/%d)\n", agg.SuccessRate, agg.SuccessfulDownloads, agg.TotalIterations)
fmt.Printf("Avg Speed: %.2f MB/s\n", agg.AvgSpeed)
fmt.Printf("Speed Range: %.2f - %.2f MB/s\n", agg.MinSpeed, agg.MaxSpeed)
fmt.Printf("Speed P50/P95/P99: %.2f / %.2f / %.2f MB/s\n", agg.P50Speed, agg.P95Speed, agg.P99Speed)
fmt.Printf("Speed StdDev: %.2f MB/s\n", agg.StdDevSpeed)
fmt.Printf("Avg Duration: %.2f seconds\n", agg.AvgDuration)
fmt.Printf("Total Downloaded: %.2f MB\n", float64(agg.TotalBytesDownloaded)/(1024*1024))
if agg.AvgDNSLookupTime > 0 || agg.AvgConnectionTime > 0 || agg.AvgSSLHandshakeTime > 0 || agg.AvgTotalConnectTime > 0 {
fmt.Printf("\nConnection Timing (ms)\n")
if agg.AvgDNSLookupTime > 0 {
fmt.Printf("DNS Lookup Avg: %.1f (min: %.1f, max: %.1f)\n", agg.AvgDNSLookupTime, agg.MinDNSLookupTime, agg.MaxDNSLookupTime)
}
if agg.AvgConnectionTime > 0 {
fmt.Printf("TCP Connect Avg: %.1f (min: %.1f, max: %.1f)\n", agg.AvgConnectionTime, agg.MinConnectionTime, agg.MaxConnectionTime)
}
if agg.AvgSSLHandshakeTime > 0 {
fmt.Printf("SSL Handshake Avg: %.1f (min: %.1f, max: %.1f)\n", agg.AvgSSLHandshakeTime, agg.MinSSLHandshakeTime, agg.MaxSSLHandshakeTime)
}
if agg.AvgTotalConnectTime > 0 {
fmt.Printf("Total Connect Avg: %.1f (min: %.1f, max: %.1f)\n", agg.AvgTotalConnectTime, agg.MinTotalConnectTime, agg.MaxTotalConnectTime)
}
}
err := exporter.Export(cfg, agg)
if err != nil {
log.Printf("Failed to export metrics: %v", err)
}
utils.DoSleep(cfg)
}