1 // Copyright 2019 The Abseil Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // https://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef ABSL_STRINGS_INTERNAL_CORDZ_STATISTICS_H_ 16 #define ABSL_STRINGS_INTERNAL_CORDZ_STATISTICS_H_ 17 18 #include <cstdint> 19 20 #include "absl/base/config.h" 21 #include "absl/strings/internal/cordz_update_tracker.h" 22 23 namespace absl { 24 ABSL_NAMESPACE_BEGIN 25 namespace cord_internal { 26 27 // CordzStatistics captures some meta information about a Cord's shape. 28 struct CordzStatistics { 29 using MethodIdentifier = CordzUpdateTracker::MethodIdentifier; 30 31 // Node counts information 32 struct NodeCounts { 33 size_t flat = 0; // #flats 34 size_t flat_64 = 0; // #flats up to 64 bytes 35 size_t flat_128 = 0; // #flats up to 128 bytes 36 size_t flat_256 = 0; // #flats up to 256 bytes 37 size_t flat_512 = 0; // #flats up to 512 bytes 38 size_t flat_1k = 0; // #flats up to 1K bytes 39 size_t external = 0; // #external reps 40 size_t substring = 0; // #substring reps 41 size_t concat = 0; // #concat reps 42 size_t ring = 0; // #ring buffer reps 43 size_t btree = 0; // #btree reps 44 }; 45 46 // The size of the cord in bytes. This matches the result of Cord::size(). 47 int64_t size = 0; 48 49 // The estimated memory used by the sampled cord. This value matches the 50 // value as reported by Cord::EstimatedMemoryUsage(). 51 // A value of 0 implies the property has not been recorded. 52 int64_t estimated_memory_usage = 0; 53 54 // The effective memory used by the sampled cord, inversely weighted by the 55 // effective indegree of each allocated node. This is a representation of the 56 // fair share of memory usage that should be attributed to the sampled cord. 57 // This value is more useful for cases where one or more nodes are referenced 58 // by multiple Cord instances, and for cases where a Cord includes the same 59 // node multiple times (either directly or indirectly). 60 // A value of 0 implies the property has not been recorded. 61 int64_t estimated_fair_share_memory_usage = 0; 62 63 // The total number of nodes referenced by this cord. 64 // For ring buffer Cords, this includes the 'ring buffer' node. 65 // For btree Cords, this includes all 'CordRepBtree' tree nodes as well as all 66 // the substring, flat and external nodes referenced by the tree. 67 // A value of 0 implies the property has not been recorded. 68 int64_t node_count = 0; 69 70 // Detailed node counts per type 71 NodeCounts node_counts; 72 73 // The cord method responsible for sampling the cord. 74 MethodIdentifier method = MethodIdentifier::kUnknown; 75 76 // The cord method responsible for sampling the parent cord if applicable. 77 MethodIdentifier parent_method = MethodIdentifier::kUnknown; 78 79 // Update tracker tracking invocation count per cord method. 80 CordzUpdateTracker update_tracker; 81 }; 82 83 } // namespace cord_internal 84 ABSL_NAMESPACE_END 85 } // namespace absl 86 87 #endif // ABSL_STRINGS_INTERNAL_CORDZ_STATISTICS_H_ 88