diff options
author | Abseil Team <absl-team@google.com> | 2021-04-15 19:42:51 -0700 |
---|---|---|
committer | Dino Radaković <dinor@google.com> | 2021-04-15 19:45:30 -0700 |
commit | e20fe888fabc1fc995dc61180e8a31b5f809a95f (patch) | |
tree | 5877907889fe35eb3162aa71111e16bd1d59fde4 /absl/strings/cord.cc | |
parent | 46dfbfe31ca1dd414e4c33cbcbcd7199bb4efde3 (diff) |
Export of internal Abseil changes
--
341670bce317dd6af8d3c066970230591a47e80c by Martijn Vels <mvels@google.com>:
Change GetStack() and GetParentStack() to return absl::Span
PiperOrigin-RevId: 368765721
--
6aaab9536d6957303c7aba100c3afaa6fb0ea2c8 by Martijn Vels <mvels@google.com>:
Remove locking from parent stack.
This change removes the need to lock all access to `parent_stack' by making the 'copy constructor' logic specify the 'copied from' CordzInfo (where available) to the TrackCord function, after which parent_stack is immutable.
PiperOrigin-RevId: 368760630
--
b19e2059cada35a8ede994833018edac94de6ddc by Martijn Vels <mvels@google.com>:
Add cordz instrumentation to Cord
PiperOrigin-RevId: 368746225
--
67b8bbf980f0f4e1db79aa32968e9a715a09b51a by Martijn Vels <mvels@google.com>:
Create ABSL_INTERNAL_CORDZ_ENABLED define controlling when Cordz code is enabled
There are specific builds and condtions under which we don't support cordz sampling, which is per this change represented by ABSL_INTERNAL_CORDZ_ENABLED being defined.
PiperOrigin-RevId: 368731603
--
8cbfe0e3169637a620f4b66ad2bc2ce340879cb0 by Martijn Vels <mvels@google.com>:
Add a `rep` property to CordzInfo to be managed by Cord logic.
This change adds a `rep` property to CordzInfo, which is intended to be used by collection logic.
Mini design:
Cord invokes TrackCord() providing the active 'root' cordrep of the newly sampled Cord, returning a CordzInfo with a weak (uncounted) reference to this root. Cord invokes `SetCordRep()` each time the root cordrep of the sampled Cord is updated while holding `mutex()`. Cord must also obtain `mutex()` _before_ removing a reference on the old root. i.e.: Cord must guarantee that the (weak) reference held in CordzInfo is at all times valid.
CordzInfo collection code can then safely obtain a (reference counted) rep pointer by adding a reference to `rep_` while holding `mutex()`. This requires only a very brief critical section inside CordzInfo logic, minimizing contention with concurrent Cord updates.
Cord code should typically obtain and hold `mutex()` for the entirety of each mutating Cord operation on a sampled cord. As Cord is thread compatible, it never competes on the lock with any other thread. The only possible concurrent access is from Cordz collection code, which should be a relatively rare event.
PiperOrigin-RevId: 368673758
--
1255120dce2bdd6b4205a34a0e555e0b74b6152f by Martijn Vels <mvels@google.com>:
Remove 'depth' from active recorded metrics.
Going forward we do not 'live' record depth (and size), but will observe these at collection time only.
PiperOrigin-RevId: 368636572
--
83e5146e35f221736b49e9f0a8805f8c159a51db by Martijn Vels <mvels@google.com>:
Make cordz targets visible in OSS
PiperOrigin-RevId: 368615010
--
dcb16a4f1239151f0a8c70a8cfeb29dabbd113b8 by Martijn Vels <mvels@google.com>:
Internal cleanup
PiperOrigin-RevId: 368514666
GitOrigin-RevId: 341670bce317dd6af8d3c066970230591a47e80c
Change-Id: I94cecfbbd441eb386f99fc5186c468a7a5538862
Diffstat (limited to 'absl/strings/cord.cc')
-rw-r--r-- | absl/strings/cord.cc | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/absl/strings/cord.cc b/absl/strings/cord.cc index 8f0999f..d33d6a0 100644 --- a/absl/strings/cord.cc +++ b/absl/strings/cord.cc @@ -38,6 +38,7 @@ #include "absl/strings/internal/cord_internal.h" #include "absl/strings/internal/cord_rep_flat.h" #include "absl/strings/internal/cord_rep_ring.h" +#include "absl/strings/internal/cordz_statistics.h" #include "absl/strings/internal/resize_uninitialized.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_format.h" @@ -426,6 +427,7 @@ void Cord::InlineRep::GetAppendRegion(char** region, size_t* size, CordRep* root = force_tree(max_length); if (PrepareAppendRegion(root, region, size, max_length)) { + UpdateCordzStatistics(); return; } @@ -460,6 +462,7 @@ void Cord::InlineRep::GetAppendRegion(char** region, size_t* size) { CordRep* root = force_tree(max_length); if (PrepareAppendRegion(root, region, size, max_length)) { + UpdateCordzStatistics(); return; } @@ -490,6 +493,27 @@ static bool RepMemoryUsageLeaf(const CordRep* rep, size_t* total_mem_usage) { return false; } +void Cord::InlineRep::StartProfiling() { + CordRep* tree = as_tree(); + auto* cordz_info = absl::cord_internal::CordzInfo::TrackCord(tree); + set_cordz_info(cordz_info); + cordz_info->RecordMetrics(size()); +} + +void Cord::InlineRep::StartProfiling(const Cord::InlineRep& src) { + CordRep* tree = as_tree(); + absl::cord_internal::CordzInfo* parent = + src.is_profiled() ? src.cordz_info() : nullptr; + auto* cordz_info = absl::cord_internal::CordzInfo::TrackCord(tree, parent); + set_cordz_info(cordz_info); + cordz_info->RecordMetrics(size()); +} + +void Cord::InlineRep::UpdateCordzStatisticsSlow() { + CordRep* tree = as_tree(); + data_.cordz_info()->RecordMetrics(tree->length); +} + void Cord::InlineRep::AssignSlow(const Cord::InlineRep& src) { UnrefTree(); @@ -497,11 +521,17 @@ void Cord::InlineRep::AssignSlow(const Cord::InlineRep& src) { if (is_tree()) { CordRep::Ref(tree()); clear_cordz_info(); + if (ABSL_PREDICT_FALSE(should_profile())) { + StartProfiling(src); + } } } void Cord::InlineRep::UnrefTree() { if (is_tree()) { + if (ABSL_PREDICT_FALSE(is_profiled())) { + absl::cord_internal::CordzInfo::UntrackCord(cordz_info()); + } CordRep::Unref(tree()); } } @@ -552,6 +582,9 @@ template Cord::Cord(std::string&& src); // The destruction code is separate so that the compiler can determine // that it does not need to call the destructor on a moved-from Cord. void Cord::DestroyCordSlow() { + if (ABSL_PREDICT_FALSE(contents_.is_profiled())) { + absl::cord_internal::CordzInfo::UntrackCord(contents_.cordz_info()); + } if (CordRep* tree = contents_.tree()) { CordRep::Unref(VerifyTree(tree)); } @@ -567,6 +600,10 @@ void Cord::Clear() { } Cord& Cord::operator=(absl::string_view src) { + if (ABSL_PREDICT_FALSE(contents_.is_profiled())) { + absl::cord_internal::CordzInfo::UntrackCord(contents_.cordz_info()); + contents_.clear_cordz_info(); + } const char* data = src.data(); size_t length = src.size(); @@ -615,6 +652,7 @@ void Cord::InlineRep::AppendArray(const char* src_data, size_t src_size) { char* region; if (PrepareAppendRegion(root, ®ion, &appended, src_size)) { memcpy(region, src_data, appended); + UpdateCordzStatistics(); } } else { // Try to fit in the inline buffer if possible. |