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 }; 44 45 // The size of the cord in bytes. This matches the result of Cord::size(). 46 int64_t size = 0; 47 48 // The estimated memory used by the sampled cord. This value matches the 49 // value as reported by Cord::EstimatedMemoryUsage(). 50 // A value of 0 implies the property has not been recorded. 51 int64_t estimated_memory_usage = 0; 52 53 // The effective memory used by the sampled cord, inversely weighted by the 54 // effective indegree of each allocated node. This is a representation of the 55 // fair share of memory usage that should be attributed to the sampled cord. 56 // This value is more useful for cases where one or more nodes are referenced 57 // by multiple Cord instances, and for cases where a Cord includes the same 58 // node multiple times (either directly or indirectly). 59 // A value of 0 implies the property has not been recorded. 60 int64_t estimated_fair_share_memory_usage = 0; 61 62 // The total number of nodes referenced by this cord. 63 // For ring buffer Cords, this includes the 'ring buffer' node. 64 // A value of 0 implies the property has not been recorded. 65 int64_t node_count = 0; 66 67 // Detailed node counts per type 68 NodeCounts node_counts; 69 70 // The cord method responsible for sampling the cord. 71 MethodIdentifier method = MethodIdentifier::kUnknown; 72 73 // The cord method responsible for sampling the parent cord if applicable. 74 MethodIdentifier parent_method = MethodIdentifier::kUnknown; 75 76 // Update tracker tracking invocation count per cord method. 77 CordzUpdateTracker update_tracker; 78 }; 79 80 } // namespace cord_internal 81 ABSL_NAMESPACE_END 82 } // namespace absl 83 84 #endif // ABSL_STRINGS_INTERNAL_CORDZ_STATISTICS_H_ 85