QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "net/third_party/quiche/src/quic/core/quic_bandwidth.h" |
| 6 | |
| 7 | #include <cinttypes> |
vasilvv | 872e7a3 | 2019-03-12 16:42:44 -0700 | [diff] [blame] | 8 | #include <string> |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9 | |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 10 | #include "net/third_party/quiche/src/common/platform/api/quiche_str_cat.h" |
| 11 | #include "net/third_party/quiche/src/common/platform/api/quiche_string_piece.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12 | |
| 13 | namespace quic { |
| 14 | |
zhongyi | 26818ca | 2019-05-13 17:50:37 -0700 | [diff] [blame] | 15 | std::string QuicBandwidth::ToDebuggingValue() const { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 16 | if (bits_per_second_ < 80000) { |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 17 | return quiche::QuicheStringPrintf("%" PRId64 " bits/s (%" PRId64 |
| 18 | " bytes/s)", |
| 19 | bits_per_second_, bits_per_second_ / 8); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 20 | } |
| 21 | |
| 22 | double divisor; |
| 23 | char unit; |
| 24 | if (bits_per_second_ < 8 * 1000 * 1000) { |
| 25 | divisor = 1e3; |
| 26 | unit = 'k'; |
| 27 | } else if (bits_per_second_ < INT64_C(8) * 1000 * 1000 * 1000) { |
| 28 | divisor = 1e6; |
| 29 | unit = 'M'; |
| 30 | } else { |
| 31 | divisor = 1e9; |
| 32 | unit = 'G'; |
| 33 | } |
| 34 | |
| 35 | double bits_per_second_with_unit = bits_per_second_ / divisor; |
| 36 | double bytes_per_second_with_unit = bits_per_second_with_unit / 8; |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 37 | return quiche::QuicheStringPrintf("%.2f %cbits/s (%.2f %cbytes/s)", |
| 38 | bits_per_second_with_unit, unit, |
| 39 | bytes_per_second_with_unit, unit); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | } // namespace quic |