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 | |
| 10 | #include "net/third_party/quiche/src/quic/platform/api/quic_str_cat.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11 | |
| 12 | namespace quic { |
| 13 | |
zhongyi | 26818ca | 2019-05-13 17:50:37 -0700 | [diff] [blame] | 14 | std::string QuicBandwidth::ToDebuggingValue() const { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 15 | if (bits_per_second_ < 80000) { |
| 16 | return QuicStringPrintf("%" PRId64 " bits/s (%" PRId64 " bytes/s)", |
| 17 | bits_per_second_, bits_per_second_ / 8); |
| 18 | } |
| 19 | |
| 20 | double divisor; |
| 21 | char unit; |
| 22 | if (bits_per_second_ < 8 * 1000 * 1000) { |
| 23 | divisor = 1e3; |
| 24 | unit = 'k'; |
| 25 | } else if (bits_per_second_ < INT64_C(8) * 1000 * 1000 * 1000) { |
| 26 | divisor = 1e6; |
| 27 | unit = 'M'; |
| 28 | } else { |
| 29 | divisor = 1e9; |
| 30 | unit = 'G'; |
| 31 | } |
| 32 | |
| 33 | double bits_per_second_with_unit = bits_per_second_ / divisor; |
| 34 | double bytes_per_second_with_unit = bits_per_second_with_unit / 8; |
| 35 | return QuicStringPrintf("%.2f %cbits/s (%.2f %cbytes/s)", |
| 36 | bits_per_second_with_unit, unit, |
| 37 | bytes_per_second_with_unit, unit); |
| 38 | } |
| 39 | |
| 40 | } // namespace quic |