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_cfgable.h"
27#include "tool_cb_prg.h"
28#include "tool_operate.h"
29#include "terminal.h"
31#define MAX_BARLENGTH 400
32#define MIN_BARLENGTH 20
34/* 200 values generated by this perl code:
36 my $pi = 3.1415;
37 foreach my $i (1 .. 200) {
38 printf "%d, ", sin($i / 200 * 2 * $pi) * 500000 + 500000;
39 } */
40static const int sinus[] = {
41 515704, 531394, 547052, 562664, 578214, 593687, 609068, 624341, 639491,
42 654504, 669364, 684057, 698568, 712883, 726989, 740870, 754513, 767906,
43 781034, 793885, 806445, 818704, 830647, 842265, 853545, 864476, 875047,
44 885248, 895069, 904500, 913532, 922156, 930363, 938145, 945495, 952406,
45 958870, 964881, 970434, 975522, 980141, 984286, 987954, 991139, 993840,
46 996054, 997778, 999011, 999752, 999999, 999754, 999014, 997783, 996060,
47 993848, 991148, 987964, 984298, 980154, 975536, 970449, 964898, 958888,
48 952426, 945516, 938168, 930386, 922180, 913558, 904527, 895097, 885277,
49 875077, 864507, 853577, 842299, 830682, 818739, 806482, 793922, 781072,
50 767945, 754553, 740910, 727030, 712925, 698610, 684100, 669407, 654548,
51 639536, 624386, 609113, 593733, 578260, 562710, 547098, 531440, 515751,
52 500046, 484341, 468651, 452993, 437381, 421830, 406357, 390976, 375703,
53 360552, 345539, 330679, 315985, 301474, 287158, 273052, 259170, 245525,
54 232132, 219003, 206152, 193590, 181331, 169386, 157768, 146487, 135555,
55 124983, 114781, 104959, 95526, 86493, 77868, 69660, 61876, 54525,
56 47613, 41147, 35135, 29581, 24491, 19871, 15724, 12056, 8868,
57 6166, 3951, 2225, 990, 248, 0, 244, 982, 2212,
58 3933, 6144, 8842, 12025, 15690, 19832, 24448, 29534, 35084,
59 41092, 47554, 54462, 61809, 69589, 77794, 86415, 95445, 104873,
60 114692, 124891, 135460, 146389, 157667, 169282, 181224, 193480, 206039,
61 218888, 232015, 245406, 259048, 272928, 287032, 301346, 315856, 330548,
62 345407, 360419, 375568, 390841, 406221, 421693, 437243, 452854, 468513,
63 484202, 499907
64};
66static void fly(struct ProgressData *bar, bool moved)
67{
68 char buf[MAX_BARLENGTH + 2];
69 int pos;
70 int check = bar->width - 2;
72 /* bar->width is range checked when assigned */
73 DEBUGASSERT(bar->width <= MAX_BARLENGTH);
74 buf[0] = '\r';
75 memset(&buf[1], ' ', bar->width);
76 buf[bar->width + 1] = '\0';
78 memcpy(&buf[bar->bar + 1], "-=O=-", 5);
80 pos = (sinus[bar->tick % 200] / (1000000 / check)) + 1;
81 buf[pos] = '#';
82 pos = (sinus[(bar->tick + 5) % 200] / (1000000 / check)) + 1;
83 buf[pos] = '#';
84 pos = (sinus[(bar->tick + 10) % 200] / (1000000 / check)) + 1;
85 buf[pos] = '#';
86 pos = (sinus[(bar->tick + 15) % 200] / (1000000 / check)) + 1;
87 buf[pos] = '#';
89 fputs(buf, bar->out);
90 bar->tick += 2;
91 if(bar->tick >= 200)
92 bar->tick -= 200;
94 bar->bar += (moved ? bar->barmove : 0);
95 if(bar->bar >= (bar->width - 6)) {
96 bar->barmove = -1;
97 bar->bar = bar->width - 6;
98 }
99 else if(bar->bar < 0) {
100 bar->barmove = 1;
101 bar->bar = 0;
102 }
103}
105/*
106 * callback for CURLOPT_XFERINFOFUNCTION
107 */
108static void update_width(struct ProgressData *bar)
109{
110 int cols = get_terminal_columns();
111 if(cols > MAX_BARLENGTH)
112 bar->width = MAX_BARLENGTH;
113 else if(cols > MIN_BARLENGTH)
114 bar->width = cols;
115 else
116 bar->width = MIN_BARLENGTH;
117}
119int tool_progress_cb(void *clientp,
120 curl_off_t dltotal, curl_off_t dlnow,
121 curl_off_t ultotal, curl_off_t ulnow)
122{
123 struct curltime now = curlx_now();
124 struct per_transfer *per = clientp;
125 struct OperationConfig *config = per->config;
126 struct ProgressData *bar = &per->progressbar;
127 curl_off_t total;
128 curl_off_t point;
129 curl_off_t totalall;
130 curl_off_t nowall;
132 totalall = ((CURL_OFF_T_MAX - dltotal) < ultotal) ?
133 CURL_OFF_T_MAX : dltotal + ultotal;
135 nowall = ((CURL_OFF_T_MAX - dlnow) < ulnow) ?
136 CURL_OFF_T_MAX : dlnow + ulnow;
138 if(!bar->calls)
139 update_width(bar);
141 /* Calculate expected transfer size. initial_size can be less than zero when
142 indicating that we are expecting to get the filesize from the remote */
143 if(bar->initial_size < 0) {
144 if(dltotal || ultotal)
145 total = totalall;
146 else
147 total = CURL_OFF_T_MAX;
148 }
149 else if((CURL_OFF_T_MAX - bar->initial_size) < totalall)
150 total = CURL_OFF_T_MAX;
151 else
152 total = totalall + bar->initial_size;
154 /* Calculate the current progress. initial_size can be less than zero when
155 indicating that we are expecting to get the filesize from the remote */
156 if(bar->initial_size < 0) {
157 if(dltotal || ultotal)
158 point = nowall;
159 else
160 point = CURL_OFF_T_MAX;
161 }
162 else if((CURL_OFF_T_MAX - bar->initial_size) < nowall)
163 point = CURL_OFF_T_MAX;
164 else
165 point = nowall + bar->initial_size;
167 if(bar->calls) {
168 /* after first call... */
169 if(total) {
170 /* we know the total data to get... */
171 if(bar->prev == point)
172 /* progress did not change since last invoke */
173 return 0;
174 else if((curlx_timediff_ms(now, bar->prevtime) < 100L) && point < total)
175 /* limit progress-bar updating to 10 Hz except when we are at 100% */
176 return 0;
177 }
178 else {
179 /* total is unknown */
180 if(curlx_timediff_ms(now, bar->prevtime) < 100L)
181 /* limit progress-bar updating to 10 Hz */
182 return 0;
183 update_width(bar);
184 fly(bar, point != bar->prev);
185 }
186 }
188 /* count invokes */
189 bar->calls++;
191 update_width(bar);
192 if((total > 0) && (point != bar->prev)) {
193 char line[MAX_BARLENGTH + 1];
194 char format[40];
195 double frac;
196 double percent;
197 int barwidth;
198 size_t num;
199 if(point > total)
200 /* we have got more than the expected total! */
201 total = point;
203 frac = (double)point / (double)total;
204 percent = frac * 100.0;
205 barwidth = bar->width - 7;
206 num = (size_t)(((double)barwidth) * frac);
207 if(num > MAX_BARLENGTH)
208 num = MAX_BARLENGTH;
209 memset(line, '#', num);
210 line[num] = '\0';
211 curl_msnprintf(format, sizeof(format), "\r%%-%ds %%5.1f%%%%", barwidth);
212#ifdef CURL_HAVE_DIAG
213#pragma GCC diagnostic push
214#pragma GCC diagnostic ignored "-Wformat-nonliteral"
215#endif
216 curl_mfprintf(bar->out, format, line, percent);
217#ifdef CURL_HAVE_DIAG
218#pragma GCC diagnostic pop
219#endif
220 }
221 fflush(bar->out);
222 bar->prev = point;
223 bar->prevtime = now;
225 if(config->readbusy) {
226 config->readbusy = FALSE;
227 curl_easy_pause(per->curl, CURLPAUSE_CONT);
228 }
230 return 0;
231}
233void progressbarinit(struct ProgressData *bar, struct OperationConfig *config)
234{
235 memset(bar, 0, sizeof(struct ProgressData));
237 /* pass the resume from value through to the progress function so it can
238 * display progress towards total file not the part that is left. */
239 if(config->use_resume)
240 bar->initial_size = config->resume_from;
242 bar->out = tool_stderr;
243 bar->tick = 150;
244 bar->barmove = 1;
245}
Diagnostics4 git calls · 31 ms
CallStatusSizeTime031 ms
discover200152 B3 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=3 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 · hit3 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=3 git.response.bytes=149 git.response.cache=HIT git.response.duration_ms=3 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 · hit2 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=2 git.response.bytes=293470 git.response.cache=HIT git.response.duration_ms=2 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 KiB · hit26 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=26 git.response.bytes=3421 git.response.cache=HIT git.response.duration_ms=26 git.fetch.wants=60709426e42c676acd8883c35640ecb29a9eb7e5 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=3421 git.pkt.payload.max=3400 git.sideband.band1.bytes=3399 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
- a5e26dad496bf4e0
- Request
- ace077a8…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format