Flow-IPC 3.0.0
Flow-IPC project: Full implementation reference.
blob_transport_stats.cpp
Go to the documentation of this file.
1/* Flow-IPC: Core
2 * Copyright 2023 Akamai Technologies, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the
5 * "License"); you may not use this file except in
6 * compliance with the License. You may obtain a copy
7 * of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in
12 * writing, software distributed under the License is
13 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
14 * CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing
16 * permissions and limitations under the License. */
17
18/// @file
20#include <cassert>
21
23{
24
25// Local helpers.
26
27namespace
28{
29
30/* (File-local/internal-use) Constructs a payload-size histogram whose last bucket isolates exactly max_payload_size.
31 * Bucket 0 absorbs the remainder when max_payload_size is not divisible by bucket_sz,
32 * so that subsequent bucket boundaries align and one falls exactly on max_payload_size.
33 * When divisible, bucket 0 is the same width as the rest (uniform). */
34flow::util::stat::Histogram_counter make_payload_sz_histo(size_t max_payload_size, size_t bucket_sz)
35{
36 assert((max_payload_size >= 1) && "max_payload_size must be >= 1.");
37
38 const auto remainder = max_payload_size % bucket_sz;
39 const auto bucket0_sz = (remainder == 0) ? bucket_sz : remainder;
40
41 return flow::util::stat::Histogram_counter{size_t(2) + ((max_payload_size - size_t(1)) / bucket_sz),
42 int64_t(bucket0_sz),
43 int64_t(bucket_sz), 0};
44}
45
46} // namespace (anon)
47
48// Implementations.
49
50Blob_snd_stats::Blob_snd_stats(size_t max_payload_size) :
51 m_histo_payload_sz(make_payload_sz_histo(max_payload_size, S_PAYLOAD_SZ_HISTO_BUCKET_SZ))
52{
53 // Yep.
54}
55
57{
58 return stats;
59}
60
61Blob_rcv_stats::Blob_rcv_stats(size_t max_payload_size) :
62 m_histo_payload_sz(make_payload_sz_histo(max_payload_size, S_PAYLOAD_SZ_HISTO_BUCKET_SZ))
63{
64 // Yep.
65}
66
68{
69 return stats;
70}
71
72
73} // namespace ipc::transport::stat
Stats-related sub-namespace, for ADL segregation and general organization.
const Blob_rcv_stats & blob_rcv_stats(const Blob_rcv_stats &stats)
Maps a stats struct type to its core Blob_rcv_stats; identity for Blob_rcv_stats itself.
const Blob_snd_stats & blob_snd_stats(const Blob_snd_stats &stats)
Maps a stats struct type to its core Blob_snd_stats; identity for Blob_snd_stats itself.
Cumulative stats from the incoming-direction (receive) pipe of a Blob_receiver or Native_handle_recei...
Blob_rcv_stats(size_t max_payload_size)
Constructs stats with all counters zeroed and a payload-size histogram sized for the given max payloa...
Cumulative stats from the outgoing-direction (send) pipe of a Blob_sender or Native_handle_sender con...
Blob_snd_stats(size_t max_payload_size)
Constructs stats with all counters zeroed and a payload-size histogram sized for the given max payloa...