Overview
Comment: | utils/ofhttp: Only update BPS once per second
Calculating and updating it more frequently results in fluctuations. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
2743414e6e4bacd6aed06dec82279126 |
User & Date: | js on 2015-05-05 20:16:48 |
Other Links: | manifest | tags |
Context
2015-05-06
| ||
20:18 | OFNotConnectedException -> OFNotOpenException check-in: ff759684e2 user: js tags: trunk | |
2015-05-05
| ||
20:16 | utils/ofhttp: Only update BPS once per second check-in: 2743414e6e user: js tags: trunk | |
10:26 | runtime/protocol.m: Remove __gnu_inline__ check-in: 9b5445fd7e user: js tags: trunk | |
Changes
Modified utils/ofhttp/ProgressBar.h from [fea9147d40] to [41e4a8fdbc].
︙ | ︙ | |||
18 19 20 21 22 23 24 | @class OFDate; @class OFTimer; @interface ProgressBar: OFObject { intmax_t _received, _lastReceived, _length, _resumedFrom; | | < | > > | 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | @class OFDate; @class OFTimer; @interface ProgressBar: OFObject { intmax_t _received, _lastReceived, _length, _resumedFrom; OFDate *_startDate, *_lastReceivedDate; OFTimer *_drawTimer, *_BPSTimer; bool _stopped; float _BPS; } - initWithLength: (intmax_t)length resumedFrom: (intmax_t)resumedFrom; - (void)setReceived: (intmax_t)received; - (void)draw; - (void)calculateBPS; - (void)stop; @end |
Modified utils/ofhttp/ProgressBar.m from [5e42a1538e] to [7133bd835c].
︙ | ︙ | |||
39 40 41 42 43 44 45 | @try { void *pool = objc_autoreleasePoolPush(); _length = length; _resumedFrom = resumedFrom; _startDate = [[OFDate alloc] init]; | > | > > > > > > | | | 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | @try { void *pool = objc_autoreleasePoolPush(); _length = length; _resumedFrom = resumedFrom; _startDate = [[OFDate alloc] init]; _lastReceivedDate = [[OFDate alloc] init]; _drawTimer = [[OFTimer scheduledTimerWithTimeInterval: UPDATE_INTERVAL target: self selector: @selector(draw) repeats: true] retain]; _BPSTimer = [[OFTimer scheduledTimerWithTimeInterval: 1.0 target: self selector: @selector(calculateBPS) repeats: true] retain]; objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [self stop]; [_drawTimer release]; [_BPSTimer release]; [super dealloc]; } - (void)setReceived: (intmax_t)received { _received = received; } - (void)_drawProgress { uint_fast8_t i; float bars, percent; bars = (float)(_resumedFrom + _received) / (_resumedFrom + _length) * BAR_WIDTH; percent = (float)(_resumedFrom + _received) / (_resumedFrom + _length) * 100; [of_stdout writeString: @"\r ▕"]; |
︙ | ︙ | |||
109 110 111 112 113 114 115 | for (i = 0; i < BAR_WIDTH - (uint_fast8_t)bars - 1; i++) [of_stdout writeString: @" "]; } [of_stdout writeFormat: @"▏ %6.2f%% ", percent]; if (percent == 100) | | < < | | | | | | | < < < < < | < < | | | | | | | < < < > > > > > > > > > > > | | 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | for (i = 0; i < BAR_WIDTH - (uint_fast8_t)bars - 1; i++) [of_stdout writeString: @" "]; } [of_stdout writeFormat: @"▏ %6.2f%% ", percent]; if (percent == 100) _BPS = (float)_received / -[_startDate timeIntervalSinceNow]; if (_BPS >= GIBIBYTE) [of_stdout writeFormat: @"%7.2f GiB/s", _BPS / GIBIBYTE]; else if (_BPS >= MEBIBYTE) [of_stdout writeFormat: @"%7.2f MiB/s", _BPS / MEBIBYTE]; else if (_BPS >= KIBIBYTE) [of_stdout writeFormat: @"%7.2f KiB/s", _BPS / KIBIBYTE]; else [of_stdout writeFormat: @"%7.2f B/s ", _BPS]; } - (void)_drawReceived { if (_resumedFrom + _received >= GIBIBYTE) [of_stdout writeFormat: @"\r %7.2f GiB ", (float)(_resumedFrom + _received) / GIBIBYTE]; else if (_resumedFrom + _received >= MEBIBYTE) [of_stdout writeFormat: @"\r %7.2f MiB ", (float)(_resumedFrom + _received) / MEBIBYTE]; else if (_resumedFrom + _received >= KIBIBYTE) [of_stdout writeFormat: @"\r %7.2f KiB ", (float)(_resumedFrom + _received) / KIBIBYTE]; else [of_stdout writeFormat: @"\r %jd bytes ", _resumedFrom + _received]; if (_stopped) _BPS = (float)_received / -[_startDate timeIntervalSinceNow]; if (_BPS >= GIBIBYTE) [of_stdout writeFormat: @"%7.2f GiB/s", _BPS / GIBIBYTE]; else if (_BPS >= MEBIBYTE) [of_stdout writeFormat: @"%7.2f MiB/s", _BPS / MEBIBYTE]; else if (_BPS >= KIBIBYTE) [of_stdout writeFormat: @"%7.2f KiB/s", _BPS / KIBIBYTE]; else [of_stdout writeFormat: @"%7.2f B/s ", _BPS]; } - (void)draw { if (_length > 0) [self _drawProgress]; else [self _drawReceived]; } - (void)calculateBPS { _BPS = (float)(_received - _lastReceived) / -[_lastReceivedDate timeIntervalSinceNow];; _lastReceived = _received; [_lastReceivedDate release]; _lastReceivedDate = [[OFDate alloc] init]; } - (void)stop { [_drawTimer invalidate]; [_BPSTimer invalidate]; _stopped = true; } @end |