cordz_statistics.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. #ifndef ABSL_STRINGS_INTERNAL_CORDZ_STATISTICS_H_
  15. #define ABSL_STRINGS_INTERNAL_CORDZ_STATISTICS_H_
  16. #include <cstdint>
  17. #include "absl/base/config.h"
  18. #include "absl/strings/internal/cordz_update_tracker.h"
  19. namespace absl {
  20. ABSL_NAMESPACE_BEGIN
  21. namespace cord_internal {
  22. // CordzStatistics captures some meta information about a Cord's shape.
  23. struct CordzStatistics {
  24. using MethodIdentifier = CordzUpdateTracker::MethodIdentifier;
  25. // Node counts information
  26. struct NodeCounts {
  27. size_t flat = 0; // #flats
  28. size_t flat_64 = 0; // #flats up to 64 bytes
  29. size_t flat_128 = 0; // #flats up to 128 bytes
  30. size_t flat_256 = 0; // #flats up to 256 bytes
  31. size_t flat_512 = 0; // #flats up to 512 bytes
  32. size_t flat_1k = 0; // #flats up to 1K bytes
  33. size_t external = 0; // #external reps
  34. size_t substring = 0; // #substring reps
  35. size_t concat = 0; // #concat reps
  36. size_t ring = 0; // #ring buffer reps
  37. size_t btree = 0; // #btree reps
  38. };
  39. // The size of the cord in bytes. This matches the result of Cord::size().
  40. int64_t size = 0;
  41. // The estimated memory used by the sampled cord. This value matches the
  42. // value as reported by Cord::EstimatedMemoryUsage().
  43. // A value of 0 implies the property has not been recorded.
  44. int64_t estimated_memory_usage = 0;
  45. // The effective memory used by the sampled cord, inversely weighted by the
  46. // effective indegree of each allocated node. This is a representation of the
  47. // fair share of memory usage that should be attributed to the sampled cord.
  48. // This value is more useful for cases where one or more nodes are referenced
  49. // by multiple Cord instances, and for cases where a Cord includes the same
  50. // node multiple times (either directly or indirectly).
  51. // A value of 0 implies the property has not been recorded.
  52. int64_t estimated_fair_share_memory_usage = 0;
  53. // The total number of nodes referenced by this cord.
  54. // For ring buffer Cords, this includes the 'ring buffer' node.
  55. // For btree Cords, this includes all 'CordRepBtree' tree nodes as well as all
  56. // the substring, flat and external nodes referenced by the tree.
  57. // A value of 0 implies the property has not been recorded.
  58. int64_t node_count = 0;
  59. // Detailed node counts per type
  60. NodeCounts node_counts;
  61. // The cord method responsible for sampling the cord.
  62. MethodIdentifier method = MethodIdentifier::kUnknown;
  63. // The cord method responsible for sampling the parent cord if applicable.
  64. MethodIdentifier parent_method = MethodIdentifier::kUnknown;
  65. // Update tracker tracking invocation count per cord method.
  66. CordzUpdateTracker update_tracker;
  67. };
  68. } // namespace cord_internal
  69. ABSL_NAMESPACE_END
  70. } // namespace absl
  71. #endif // ABSL_STRINGS_INTERNAL_CORDZ_STATISTICS_H_