added grabbing info about downloaded metadata (#8972)

This commit is contained in:
Dmytro 2023-12-13 15:04:14 +01:00 committed by GitHub
parent 06e77d1705
commit ac1e42b68d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 26 deletions

View File

@ -53,6 +53,7 @@ func (d *DiagnosticClient) runSnapshotListener() {
d.snapshotDownload.Alloc = info.Alloc
d.snapshotDownload.Sys = info.Sys
d.snapshotDownload.DownloadFinished = info.DownloadFinished
d.snapshotDownload.TorrentMetadataReady = info.TorrentMetadataReady
if info.DownloadFinished {
return

View File

@ -30,18 +30,19 @@ type PeerStatistics struct {
}
type SnapshotDownloadStatistics struct {
Downloaded uint64 `json:"downloaded"`
Total uint64 `json:"total"`
TotalTime float64 `json:"totalTime"`
DownloadRate uint64 `json:"downloadRate"`
UploadRate uint64 `json:"uploadRate"`
Peers int32 `json:"peers"`
Files int32 `json:"files"`
Connections uint64 `json:"connections"`
Alloc uint64 `json:"alloc"`
Sys uint64 `json:"sys"`
DownloadFinished bool `json:"downloadFinished"`
Segments map[string]SegmentDownloadStatistics `json:"segments"`
Downloaded uint64 `json:"downloaded"`
Total uint64 `json:"total"`
TotalTime float64 `json:"totalTime"`
DownloadRate uint64 `json:"downloadRate"`
UploadRate uint64 `json:"uploadRate"`
Peers int32 `json:"peers"`
Files int32 `json:"files"`
Connections uint64 `json:"connections"`
Alloc uint64 `json:"alloc"`
Sys uint64 `json:"sys"`
DownloadFinished bool `json:"downloadFinished"`
Segments map[string]SegmentDownloadStatistics `json:"segments"`
TorrentMetadataReady int32 `json:"torrentMetadataReady"`
}
type SegmentDownloadStatistics struct {

View File

@ -160,10 +160,26 @@ Loop:
log.Info(fmt.Sprintf("[%s] download finished", logPrefix), "time", time.Since(downloadStartTime).String())
break Loop
} else {
diagnostics.Send(diagnostics.SnapshotDownloadStatistics{
Downloaded: stats.BytesCompleted,
Total: stats.BytesTotal,
TotalTime: time.Since(downloadStartTime).Round(time.Second).Seconds(),
DownloadRate: stats.DownloadRate,
UploadRate: stats.UploadRate,
Peers: stats.PeersUnique,
Files: stats.FilesTotal,
Connections: stats.ConnectionsTotal,
Alloc: m.Alloc,
Sys: m.Sys,
DownloadFinished: stats.Completed,
TorrentMetadataReady: stats.MetadataReady,
})
if stats.MetadataReady < stats.FilesTotal {
log.Info(fmt.Sprintf("[%s] Waiting for torrents metadata: %d/%d", logPrefix, stats.MetadataReady, stats.FilesTotal))
continue
}
dbg.ReadMemStats(&m)
downloadTimeLeft := calculateTime(stats.BytesTotal-stats.BytesCompleted, stats.DownloadRate)
suffix := "downloading"
@ -171,20 +187,6 @@ Loop:
suffix += " (or verifying)"
}
diagnostics.Send(diagnostics.SnapshotDownloadStatistics{
Downloaded: stats.BytesCompleted,
Total: stats.BytesTotal,
TotalTime: time.Since(downloadStartTime).Round(time.Second).Seconds(),
DownloadRate: stats.DownloadRate,
UploadRate: stats.UploadRate,
Peers: stats.PeersUnique,
Files: stats.FilesTotal,
Connections: stats.ConnectionsTotal,
Alloc: m.Alloc,
Sys: m.Sys,
DownloadFinished: stats.Completed,
})
log.Info(fmt.Sprintf("[%s] %s", logPrefix, suffix),
"progress", fmt.Sprintf("%.2f%% %s/%s", stats.Progress, common.ByteCount(stats.BytesCompleted), common.ByteCount(stats.BytesTotal)),
"time-left", downloadTimeLeft,