Skip to content

Commit

Permalink
Log download durations
Browse files Browse the repository at this point in the history
  • Loading branch information
edolstra committed Jul 24, 2024
1 parent b13ba74 commit caf4e98
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/libstore/filetransfer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ struct curlFileTransfer : public FileTransfer

curl_off_t writtenToSink = 0;

std::chrono::steady_clock::time_point startTime = std::chrono::steady_clock::now();

inline static const std::set<long> successfulStatuses {200, 201, 204, 206, 304, 0 /* other protocol */};

/* Get the HTTP status code, or 0 for other protocols. */
long getHTTPStatus()
{
Expand Down Expand Up @@ -373,10 +376,14 @@ struct curlFileTransfer : public FileTransfer

void finish(CURLcode code)
{
auto finishTime = std::chrono::steady_clock::now();

auto httpStatus = getHTTPStatus();

debug("finished %s of '%s'; curl status = %d, HTTP status = %d, body = %d bytes",
request.verb(), request.uri, code, httpStatus, result.bodySize);
debug("finished %s of '%s'; curl status = %d, HTTP status = %d, body = %d bytes, duration = %.2f s",
request.verb(), request.uri, code, httpStatus, result.bodySize,
std::chrono::duration_cast<std::chrono::milliseconds>(finishTime - startTime).count() / 1000.0f
);

appendCurrentUrl();

Expand Down

0 comments on commit caf4e98

Please sign in to comment.