blob: 9fcc3b986ae9427a35beea48a0c9be958c279e24 [file] [log] [blame]
QUICHE teama6ef0a62019-03-07 20:34:33 -05001// 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>
vasilvv872e7a32019-03-12 16:42:44 -07008#include <string>
QUICHE teama6ef0a62019-03-07 20:34:33 -05009
10#include "net/third_party/quiche/src/quic/platform/api/quic_str_cat.h"
QUICHE teama6ef0a62019-03-07 20:34:33 -050011
12namespace quic {
13
zhongyi26818ca2019-05-13 17:50:37 -070014std::string QuicBandwidth::ToDebuggingValue() const {
QUICHE teama6ef0a62019-03-07 20:34:33 -050015 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