blob: ad2c03289a6ff21dbe76cdf729825c8bf72b8925 [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
dmcardlecf0bfcf2019-12-13 08:08:21 -080010#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 teama6ef0a62019-03-07 20:34:33 -050012
13namespace quic {
14
zhongyi26818ca2019-05-13 17:50:37 -070015std::string QuicBandwidth::ToDebuggingValue() const {
QUICHE teama6ef0a62019-03-07 20:34:33 -050016 if (bits_per_second_ < 80000) {
dmcardlecf0bfcf2019-12-13 08:08:21 -080017 return quiche::QuicheStringPrintf("%" PRId64 " bits/s (%" PRId64
18 " bytes/s)",
19 bits_per_second_, bits_per_second_ / 8);
QUICHE teama6ef0a62019-03-07 20:34:33 -050020 }
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;
dmcardlecf0bfcf2019-12-13 08:08:21 -080037 return quiche::QuicheStringPrintf("%.2f %cbits/s (%.2f %cbytes/s)",
38 bits_per_second_with_unit, unit,
39 bytes_per_second_with_unit, unit);
QUICHE teama6ef0a62019-03-07 20:34:33 -050040}
41
42} // namespace quic