From dedbd3d18c6f1b78838995c8044ac5caf867fc4b Mon Sep 17 00:00:00 2001 From: technillogue Date: Thu, 21 Mar 2024 21:38:28 -0700 Subject: [PATCH] decode exit status --- CHANGELOG.md | 1 + remotefile/main.go | 15 ++++++++++----- src/main.cpp | 12 ++++++++++-- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 02991f4..0295bc2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ +0.1.7 decode downloader exit code. iterative merge tensors. 0.1.6 algo arg for compression, respect LOAD_UNCOMPRESSED, fix vmsplice 0.1.5 pass envvars to downloader + remotefile works with regional cache 0.1.4 increase merge_tensors maxsize and make compression block size configurable diff --git a/remotefile/main.go b/remotefile/main.go index 7cb4462..a51f01c 100644 --- a/remotefile/main.go +++ b/remotefile/main.go @@ -93,12 +93,12 @@ func (b *DownloadBuffer) IsDone() bool { return b.done && len(b.data) == 0 } -func downloadToBuffer(buf *DownloadBuffer) { +func downloadToBuffer(buf *DownloadBuffer) int64 { startTime := time.Now() resp, err := client.Get(buf.url) if err != nil { fmt.Fprintf(os.Stderr, "Error fetching %s: %v\n", buf.url, err) - return + return 0 } defer resp.Body.Close() @@ -118,11 +118,11 @@ func downloadToBuffer(buf *DownloadBuffer) { throughput := float64(resp.ContentLength) / elapsed.Seconds() / 1024 / 1024 fmt.Fprintf(os.Stderr, "Downloaded %s in %s (%.2f MB/s)\n", resp.Request.URL, elapsed, throughput) buf.chunkPool.Put(chunk) - return + return resp.ContentLength } if err != nil { fmt.Fprintf(os.Stderr, "Error reading from %s: %v\n", resp.Request.URL, err) - return + return 0 } } } @@ -177,6 +177,8 @@ func main() { } bufChan := make(chan *DownloadBuffer) go func(bufChan chan *DownloadBuffer) { + total_size := int64(0) + start := time.Now() for _, url := range os.Args[1:] { // ignore curl args if url == "-s" || url == "-v" { @@ -184,8 +186,11 @@ func main() { } buf := NewBuffer(url) bufChan <- buf - downloadToBuffer(buf) + total_size += downloadToBuffer(buf) } + elapsed := time.Since(start) + throughput := float64(total_size) / elapsed.Seconds() / 1024 / 1024 + fmt.Fprintf(os.Stderr, "Overall downloaded %d MB in %s (%.2f MB/s)\n", total_size/1024/1024, elapsed, throughput) close(bufChan) }(bufChan) for buf := range bufChan { diff --git a/src/main.cpp b/src/main.cpp index 7687977..d984fd0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -242,7 +242,15 @@ class DownloadProc { throw std::runtime_error("Failed to spawn curl subprocess. Error code: " + std::to_string(retcode)); int status; waitpid(pid, &status, 0); - throw std::runtime_error("Failed to spawn curl subprocess. Error code: " + std::to_string(retcode) + ", exit code: " + std::to_string(status)); + // decode status + if (WIFEXITED(status)) + throw std::runtime_error("Failed to spawn curl subprocess. Error code: " + std::to_string(retcode) + ", exit code: " + std::to_string(WEXITSTATUS(status))); + else if (WIFSIGNALED(status)) + throw std::runtime_error("Failed to spawn curl subprocess. Error code: " + std::to_string(retcode) + ", exit signal: " + std::to_string(WTERMSIG(status))); + else if (WIFSTOPPED(status)) + throw std::runtime_error("Failed to spawn curl subprocess. Error code: " + std::to_string(retcode) + ", stop signal: " + std::to_string(WSTOPSIG(status))); + else + throw std::runtime_error("Failed to spawn curl subprocess. Error code: " + std::to_string(retcode) + ", unknown status: " + std::to_string(status)); } // close write end of the pipe close(pipefd[1]); @@ -256,7 +264,7 @@ class DownloadProc { kill(pid, SIGTERM); int status; waitpid(pid, &status, 0); - int code = ((WIFEXITED(status) ? WEXITSTATUS(status) : (WIFSIGNALED(status) ? -WTERMSIG(status) : 0))) + int code = ((WIFEXITED(status) ? WEXITSTATUS(status) : (WIFSIGNALED(status) ? -WTERMSIG(status) : 0))); log("killed downloader process. exit code: " + std::to_string(code)); }