master
1/***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9 *
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at https://curl.se/docs/copyright.html.
13 *
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 * SPDX-License-Identifier: curl
22 *
23 ***************************************************************************/
24#include "tool_setup.h"
26#include "tool_operate.h"
27#include "tool_progress.h"
29/* The point of this function would be to return a string of the input data,
30 but never longer than 5 columns (+ one zero byte).
31 Add suffix k, M, G when suitable...
33 Unit test 1622
34 */
35UNITTEST char *max5data(curl_off_t bytes, char *max5, size_t mlen)
36{
37 /* a signed 64-bit value is 8192 petabytes maximum */
38 static const char unit[] = { 'k', 'M', 'G', 'T', 'P', 'E', 0 };
39 int k = 0;
40 if(bytes < 100000) {
41 curl_msnprintf(max5, mlen, "%5" CURL_FORMAT_CURL_OFF_T, bytes);
42 return max5;
43 }
45 do {
46 curl_off_t nbytes = bytes / 1024;
47 if(nbytes < 100) {
48 /* display with a decimal */
49 curl_msnprintf(max5, mlen, "%2" CURL_FORMAT_CURL_OFF_T ".%"
50 CURL_FORMAT_CURL_OFF_T "%c", bytes / 1024,
51 (bytes % 1024) * 10 / 1024, unit[k]);
52 break;
53 }
54 else if(nbytes < 10000) {
55 /* no decimals */
56 curl_msnprintf(max5, mlen, "%4" CURL_FORMAT_CURL_OFF_T "%c", nbytes,
57 unit[k]);
58 break;
59 }
60 bytes = nbytes;
61 k++;
62 DEBUGASSERT(unit[k]);
63 } while(unit[k]);
64 return max5;
65}
67static void add_offt(curl_off_t *val, curl_off_t add)
68{
69 if(CURL_OFF_T_MAX - *val < add)
70 /* maxed out! */
71 *val = CURL_OFF_T_MAX;
72 else
73 *val += add;
74}
76int xferinfo_cb(void *clientp,
77 curl_off_t dltotal,
78 curl_off_t dlnow,
79 curl_off_t ultotal,
80 curl_off_t ulnow)
81{
82 struct per_transfer *per = clientp;
83 struct OperationConfig *config = per->config;
84 per->dltotal = dltotal;
85 per->dlnow = dlnow;
86 if(dltotal)
87 add_offt(&per->dltotal, per->dlretry);
88 add_offt(&per->dlnow, per->dlretry);
89 per->ultotal = ultotal;
90 per->ulnow = ulnow;
92 if(per->abort)
93 return 1;
95 if(config->readbusy) {
96 config->readbusy = FALSE;
97 curl_easy_pause(per->curl, CURLPAUSE_CONT);
98 }
100 return 0;
101}
103/* Provide a time string that is 8 letters long (plus the zero byte)
105 Unit test 1622
106 */
107UNITTEST void timebuf(char *r, size_t rlen, curl_off_t seconds)
108{
109 curl_off_t h;
110 if(seconds <= 0) {
111 curlx_strcopy(r, rlen, " ", 8);
112 return;
113 }
114 h = seconds / 3600;
115 if(h <= 99) {
116 curl_off_t m = (seconds - (h * 3600)) / 60;
117 curl_off_t s = (seconds - (h * 3600)) - (m * 60);
118 curl_msnprintf(r, rlen, "%02" FMT_OFF_T ":%02" FMT_OFF_T ":"
119 "%02" FMT_OFF_T, h, m, s);
120 }
121 else {
122 curl_off_t d = seconds / 86400;
123 h = (seconds - (d * 86400)) / 3600;
124 if(d <= 999)
125 curl_msnprintf(r, rlen, "%3" FMT_OFF_T "d %02" FMT_OFF_T "h", d, h);
126 else { /* more than 999 days */
127 curl_off_t m = d / 30;
128 if(m <= 999) {
129 curl_msnprintf(r, rlen, "%3" FMT_OFF_T "m %02" FMT_OFF_T "d", m, d%30);
130 }
131 else { /* more than 999 months */
132 curl_off_t y = d / 365;
133 if(y <= 99999)
134 curl_msnprintf(r, rlen, "%7" FMT_OFF_T "y", y);
135 else
136 curlx_strcopy(r, rlen, " >99999y", 8);
137 }
138 }
139 }
140}
142static curl_off_t all_dltotal_done = 0;
143static curl_off_t all_ultotal_done = 0;
144static curl_off_t all_dlalready = 0;
145static curl_off_t all_ulalready = 0;
147struct speedcount {
148 curl_off_t dl;
149 curl_off_t ul;
150 struct curltime stamp;
151};
152#define SPEEDCNT 10
153static unsigned int speedindex;
154static bool indexwrapped;
155static struct speedcount speedstore[SPEEDCNT];
157/*
158 |DL% UL% Dled Uled Xfers Live Total Current Left Speed
159 | 6 -- 9.9G 0 2 2 0:00:40 0:00:02 0:00:37 4087M
160 */
161bool progress_meter(CURLM *multi, struct curltime *start, bool final)
162{
163 static struct curltime stamp;
164 static bool header = FALSE;
165 struct curltime now;
166 timediff_t diff;
168 if(global->noprogress || global->silent)
169 return FALSE;
171 now = curlx_now();
172 diff = curlx_timediff_ms(now, stamp);
174 if(!header) {
175 header = TRUE;
176 fputs("DL% UL% Dled Uled Xfers Live "
177 "Total Current Left Speed\n",
178 tool_stderr);
179 }
180 if(final || (diff > 500)) {
181 char time_left[9];
182 char time_total[9];
183 char time_spent[9];
184 char buffer[3][6];
185 curl_off_t spent = curlx_timediff_ms(now, *start) / 1000;
186 char dlpercen[4] = "--";
187 char ulpercen[4] = "--";
188 struct per_transfer *per;
189 curl_off_t all_dlnow = 0;
190 curl_off_t all_ulnow = 0;
191 curl_off_t all_dltotal = all_dltotal_done;
192 curl_off_t all_ultotal = all_ultotal_done;
193 curl_off_t xfers_added = 0;
194 curl_off_t xfers_running = 0;
195 bool dlknown = TRUE;
196 bool ulknown = TRUE;
197 curl_off_t speed = 0;
198 unsigned int i;
199 stamp = now;
201 /* first add the amounts of the already completed transfers */
202 add_offt(&all_dlnow, all_dlalready);
203 add_offt(&all_ulnow, all_ulalready);
205 for(per = transfers; per; per = per->next) {
206 add_offt(&all_dlnow, per->dlnow);
207 add_offt(&all_ulnow, per->ulnow);
208 if(!per->dltotal)
209 dlknown = FALSE;
210 else
211 add_offt(&all_dltotal, per->dltotal);
212 if(!per->ultotal)
213 ulknown = FALSE;
214 else
215 add_offt(&all_ultotal, per->ultotal);
216 }
217 if(dlknown && all_dltotal)
218 curl_msnprintf(dlpercen, sizeof(dlpercen), "%3" CURL_FORMAT_CURL_OFF_T,
219 all_dlnow < (CURL_OFF_T_MAX / 100) ?
220 (all_dlnow * 100 / all_dltotal) :
221 (all_dlnow / (all_dltotal / 100)));
223 if(ulknown && all_ultotal)
224 curl_msnprintf(ulpercen, sizeof(ulpercen), "%3" CURL_FORMAT_CURL_OFF_T,
225 all_ulnow < (CURL_OFF_T_MAX / 100) ?
226 (all_ulnow * 100 / all_ultotal) :
227 (all_ulnow / (all_ultotal / 100)));
229 /* get the transfer speed, the higher of the two */
231 i = speedindex;
232 speedstore[i].dl = all_dlnow;
233 speedstore[i].ul = all_ulnow;
234 speedstore[i].stamp = now;
235 if(++speedindex >= SPEEDCNT) {
236 indexwrapped = TRUE;
237 speedindex = 0;
238 }
240 {
241 timediff_t deltams;
242 curl_off_t dl;
243 curl_off_t ul;
244 curl_off_t dls;
245 curl_off_t uls;
246 if(indexwrapped) {
247 /* 'speedindex' is the oldest stored data */
248 deltams = curlx_timediff_ms(now, speedstore[speedindex].stamp);
249 dl = all_dlnow - speedstore[speedindex].dl;
250 ul = all_ulnow - speedstore[speedindex].ul;
251 }
252 else {
253 /* since the beginning */
254 deltams = curlx_timediff_ms(now, *start);
255 dl = all_dlnow;
256 ul = all_ulnow;
257 }
258 if(!deltams) /* no division by zero please */
259 deltams++;
260 dls = (curl_off_t)((double)dl / ((double)deltams / 1000.0));
261 uls = (curl_off_t)((double)ul / ((double)deltams / 1000.0));
262 speed = dls > uls ? dls : uls;
263 }
265 if(dlknown && speed) {
266 curl_off_t est = all_dltotal / speed;
267 curl_off_t left = (all_dltotal - all_dlnow) / speed;
268 timebuf(time_left, sizeof(time_left), left);
269 timebuf(time_total, sizeof(time_total), est);
270 }
271 else {
272 timebuf(time_left, sizeof(time_left), 0);
273 timebuf(time_total, sizeof(time_total), 0);
274 }
275 timebuf(time_spent, sizeof(time_spent), spent);
277 (void)curl_multi_get_offt(multi, CURLMINFO_XFERS_ADDED, &xfers_added);
278 (void)curl_multi_get_offt(multi, CURLMINFO_XFERS_RUNNING, &xfers_running);
279 curl_mfprintf(tool_stderr,
280 "\r"
281 "%-3s " /* percent downloaded */
282 "%-3s " /* percent uploaded */
283 "%s " /* Dled */
284 "%s " /* Uled */
285 "%5" CURL_FORMAT_CURL_OFF_T " " /* Xfers */
286 "%5" CURL_FORMAT_CURL_OFF_T " " /* Live */
287 " %s " /* Total time */
288 "%s " /* Current time */
289 "%s " /* Time left */
290 "%s " /* Speed */
291 "%5s" /* final newline */,
293 dlpercen, /* 3 letters */
294 ulpercen, /* 3 letters */
295 max5data(all_dlnow, buffer[0], sizeof(buffer[0])),
296 max5data(all_ulnow, buffer[1], sizeof(buffer[1])),
297 xfers_added,
298 xfers_running,
299 time_total,
300 time_spent,
301 time_left,
302 max5data(speed, buffer[2], sizeof(buffer[2])), /* speed */
303 final ? "\n" : "");
304 return TRUE;
305 }
306 return FALSE;
307}
309void progress_finalize(struct per_transfer *per)
310{
311 /* get the numbers before this transfer goes away */
312 add_offt(&all_dlalready, per->dlnow);
313 add_offt(&all_ulalready, per->ulnow);
314 add_offt(&all_dltotal_done, per->dltotal);
315 add_offt(&all_ultotal_done, per->ultotal);
316}
318void progress_reset_retry(struct per_transfer *per)
319{
320 per->dlnow = per->dlretry;
321 per->ulnow = 0;
322 per->dltotal = 0;
323 per->ultotal = 0;
325 /* Discarded bytes can make the counters decrease between samples. */
326 speedindex = 0;
327 indexwrapped = FALSE;
328}
Diagnostics4 git calls · 356 ms
CallStatusSizeTime0356 ms
discover200152 B2 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=2 git.response.bytes=152 git.server.agent=gitty/1.0 git.server.object_format=sha1 git.server.caps=agent ls-refs fetch object-format git.server.fetch=shallow filter sideband-all git.protocol.version=2 git.pkt.frames=8 git.pkt.data=6 git.pkt.flush=2 git.pkt.delim=0 git.pkt.bytes=152 git.pkt.payload.max=34
ls-refs200149 B · hit2 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=2 git.response.bytes=149 git.response.cache=HIT git.response.duration_ms=2 git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=149 git.pkt.payload.max=78 git.ls_refs.count=2 git.ls_refs.head=refs/heads/master
fetchblob:none · deepen 10200287 KiB · hit3 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=3 git.response.bytes=293470 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=blob:none git.fetch.filter.requested=tree:0 git.fetch.filter.fallback=blob:none git.fetch.filter.learned=false git.fetch.wants=31c911efe5652725e930f4d2e60c9060e5f6646d git.fetch.haves.count=0 git.fetch.deepen=10 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=10 git.pkt.data=8 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=293470 git.pkt.payload.max=65516 git.sideband.band1.bytes=293354 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=87 git.pack.bytes=293354 git.pack.ofs_delta=0 git.pack.ref_delta=1 git.pack.chain.max=1 git.pack.trailer=6a646bcda6740bab42e321b51998b52ea15146c0 git.pack.full=86Open pack map
fetch2003.3 KiB351 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=351 git.response.bytes=3422 git.response.cache=MISS git.response.duration_ms=351 git.fetch.wants=f70129f51eb22be9336a42045769b3ff10a01362 git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=3422 git.pkt.payload.max=3401 git.sideband.band1.bytes=3400 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0
Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.
- Remote
- https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/curl.git
- Ref
- refs/heads/master
- Commit
- 31c911efe5652725e930f4d2e60c9060e5f6646d
- cf-ray
- a5e13875286918aa
- Request
- 37440cde…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format