|
|
|
// Copyright 2021 The Abseil Authors
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// https://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "gmock/gmock.h"
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
#include "absl/base/config.h"
|
|
|
|
#include "absl/base/internal/raw_logging.h"
|
|
|
|
#include "absl/base/macros.h"
|
|
|
|
#include "absl/strings/cord.h"
|
|
|
|
#include "absl/strings/cord_test_helpers.h"
|
|
|
|
#include "absl/strings/cordz_test_helpers.h"
|
|
|
|
#include "absl/strings/internal/cordz_functions.h"
|
|
|
|
#include "absl/strings/internal/cordz_info.h"
|
|
|
|
#include "absl/strings/internal/cordz_sample_token.h"
|
|
|
|
#include "absl/strings/internal/cordz_statistics.h"
|
|
|
|
#include "absl/strings/internal/cordz_update_tracker.h"
|
|
|
|
#include "absl/strings/str_cat.h"
|
|
|
|
#include "absl/strings/string_view.h"
|
|
|
|
|
|
|
|
#ifdef ABSL_INTERNAL_CORDZ_ENABLED
|
|
|
|
|
|
|
|
using testing::Eq;
|
Export of internal Abseil changes
--
60b8e77be4bab1bbd3b4c3b70054879229634511 by Derek Mauro <dmauro@google.com>:
Use _MSVC_LANG for some C++ dialect checks since MSVC doesn't
set __cplusplus accurately by default.
https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/
See GitHub #722.
PiperOrigin-RevId: 371362181
--
5d736accdff04db0e722f377c0d79f2d3ed53263 by Martijn Vels <mvels@google.com>:
Fix the estimated memory size for CordRepExternal
PiperOrigin-RevId: 371350380
--
eaaa1d8a167aeca67a2aa3a098a2b61a9d72172f by Martijn Vels <mvels@google.com>:
Remove flakes by not enforcing re-allocated pointers do never match original
Tests that do multiple updates could end up with the original allocated pointer on a 2nd resize, so the 'EqIfPrivate' should not assume that if we do 'not' have the capacity that all following relocations will never match the original. We only care about 'pointer unchanged if private and there is capacity', trying to establish 'pointer changed at some point due to re-allocation; is pointless.
PiperOrigin-RevId: 371338965
--
d1837bee6bade1902b095c1cbf64231668bb84c5 by Martijn Vels <mvels@google.com>:
Undo inline of small data copy in cord
This leads to a performance regression as the code is not inlined (absent hard FDO inputs), and there are no suitable tail call options.
PiperOrigin-RevId: 371332332
--
06dc64b833069efc7d18b11df607c8c22be690da by Martijn Vels <mvels@google.com>:
Add final instrumentation for Cordz and remove 'old' cordz logic.
This change instruments the last cord function for cordz. It removes the 'old' functions: set_tree, replace_tree, UpdateCordzStatistics and RecordMetrics.
PiperOrigin-RevId: 371219909
--
a5e0be538579c603052feec03e6d9910c43ea787 by Martijn Vels <mvels@google.com>:
Extend the life of CordRep* if inside a snapshot
If a snapshot (potentially) includes the current CordzInfo, we need to extent the lifetime of the CordRep*, as the snapshot 'point in time' observation of the cord should ideally be preserved.
PiperOrigin-RevId: 371146151
--
74d77a89774cd6c8ecdeebee0193b294a39383d6 by Martijn Vels <mvels@google.com>:
Instrument std::string consuming methods: ctor, operator=, Append and Prepend
This change moves the 'steal into CordRep' logic into a separate function so we can use it directly in the ctor, operator assign and append and prepend, allowing Cordz instrumentation with the proper method attributes.
The assign operator is implemented in AssignLargeString leaving the dispatch inlined in cord.h (which as a side effects also allows clean tail calls in the AssignLargeString method)
PiperOrigin-RevId: 371094756
--
b39effc45266b7ce2e7f96caa3b16cb6e3acc2dd by Martijn Vels <mvels@google.com>:
Add Cordz instrumentation to CordReader
PiperOrigin-RevId: 370990181
GitOrigin-RevId: 60b8e77be4bab1bbd3b4c3b70054879229634511
Change-Id: I96af62e6f1a643e8b1228ae01e6c84e33706bb05
4 years ago
|
|
|
using testing::AnyOf;
|
|
|
|
|
|
|
|
namespace absl {
|
|
|
|
ABSL_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
using cord_internal::CordzInfo;
|
|
|
|
using cord_internal::CordzSampleToken;
|
|
|
|
using cord_internal::CordzStatistics;
|
|
|
|
using cord_internal::CordzUpdateTracker;
|
|
|
|
using Method = CordzUpdateTracker::MethodIdentifier;
|
|
|
|
|
|
|
|
// Do not print cord contents, we only care about 'size' perhaps.
|
|
|
|
// Note that this method must be inside the named namespace.
|
|
|
|
inline void PrintTo(const Cord& cord, std::ostream* s) {
|
|
|
|
if (s) *s << "Cord[" << cord.size() << "]";
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
auto constexpr kMaxInline = cord_internal::kMaxInline;
|
|
|
|
|
|
|
|
// Returns a string_view value of the specified length
|
|
|
|
// We do this to avoid 'consuming' large strings in Cord by default.
|
|
|
|
absl::string_view MakeString(size_t size) {
|
|
|
|
thread_local std::string str;
|
|
|
|
str = std::string(size, '.');
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
absl::string_view MakeString(TestCordSize size) {
|
|
|
|
return MakeString(Length(size));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns a cord with a sampled method of kAppendString.
|
|
|
|
absl::Cord MakeAppendStringCord(TestCordSize size) {
|
|
|
|
absl::Cord cord;
|
|
|
|
cord.Append(MakeString(size));
|
|
|
|
return cord;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string TestParamToString(::testing::TestParamInfo<TestCordSize> size) {
|
|
|
|
return absl::StrCat("On", ToString(size.param), "Cord");
|
|
|
|
}
|
|
|
|
|
|
|
|
class CordzUpdateTest : public testing::TestWithParam<TestCordSize> {
|
|
|
|
public:
|
|
|
|
Cord& cord() { return cord_; }
|
|
|
|
|
|
|
|
Method InitialOr(Method method) const {
|
|
|
|
return (GetParam() > TestCordSize::kInlined) ? Method::kConstructorString
|
|
|
|
: method;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
CordzSamplingIntervalHelper sample_every_{1};
|
|
|
|
Cord cord_{MakeString(GetParam())};
|
|
|
|
};
|
|
|
|
|
Export of internal Abseil changes
--
60b8e77be4bab1bbd3b4c3b70054879229634511 by Derek Mauro <dmauro@google.com>:
Use _MSVC_LANG for some C++ dialect checks since MSVC doesn't
set __cplusplus accurately by default.
https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/
See GitHub #722.
PiperOrigin-RevId: 371362181
--
5d736accdff04db0e722f377c0d79f2d3ed53263 by Martijn Vels <mvels@google.com>:
Fix the estimated memory size for CordRepExternal
PiperOrigin-RevId: 371350380
--
eaaa1d8a167aeca67a2aa3a098a2b61a9d72172f by Martijn Vels <mvels@google.com>:
Remove flakes by not enforcing re-allocated pointers do never match original
Tests that do multiple updates could end up with the original allocated pointer on a 2nd resize, so the 'EqIfPrivate' should not assume that if we do 'not' have the capacity that all following relocations will never match the original. We only care about 'pointer unchanged if private and there is capacity', trying to establish 'pointer changed at some point due to re-allocation; is pointless.
PiperOrigin-RevId: 371338965
--
d1837bee6bade1902b095c1cbf64231668bb84c5 by Martijn Vels <mvels@google.com>:
Undo inline of small data copy in cord
This leads to a performance regression as the code is not inlined (absent hard FDO inputs), and there are no suitable tail call options.
PiperOrigin-RevId: 371332332
--
06dc64b833069efc7d18b11df607c8c22be690da by Martijn Vels <mvels@google.com>:
Add final instrumentation for Cordz and remove 'old' cordz logic.
This change instruments the last cord function for cordz. It removes the 'old' functions: set_tree, replace_tree, UpdateCordzStatistics and RecordMetrics.
PiperOrigin-RevId: 371219909
--
a5e0be538579c603052feec03e6d9910c43ea787 by Martijn Vels <mvels@google.com>:
Extend the life of CordRep* if inside a snapshot
If a snapshot (potentially) includes the current CordzInfo, we need to extent the lifetime of the CordRep*, as the snapshot 'point in time' observation of the cord should ideally be preserved.
PiperOrigin-RevId: 371146151
--
74d77a89774cd6c8ecdeebee0193b294a39383d6 by Martijn Vels <mvels@google.com>:
Instrument std::string consuming methods: ctor, operator=, Append and Prepend
This change moves the 'steal into CordRep' logic into a separate function so we can use it directly in the ctor, operator assign and append and prepend, allowing Cordz instrumentation with the proper method attributes.
The assign operator is implemented in AssignLargeString leaving the dispatch inlined in cord.h (which as a side effects also allows clean tail calls in the AssignLargeString method)
PiperOrigin-RevId: 371094756
--
b39effc45266b7ce2e7f96caa3b16cb6e3acc2dd by Martijn Vels <mvels@google.com>:
Add Cordz instrumentation to CordReader
PiperOrigin-RevId: 370990181
GitOrigin-RevId: 60b8e77be4bab1bbd3b4c3b70054879229634511
Change-Id: I96af62e6f1a643e8b1228ae01e6c84e33706bb05
4 years ago
|
|
|
template <typename T>
|
|
|
|
std::string ParamToString(::testing::TestParamInfo<T> param) {
|
|
|
|
return std::string(ToString(param.param));
|
|
|
|
}
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_SUITE_P(WithParam, CordzUpdateTest,
|
|
|
|
testing::Values(TestCordSize::kEmpty,
|
|
|
|
TestCordSize::kInlined,
|
|
|
|
TestCordSize::kLarge),
|
|
|
|
TestParamToString);
|
|
|
|
|
Export of internal Abseil changes
--
60b8e77be4bab1bbd3b4c3b70054879229634511 by Derek Mauro <dmauro@google.com>:
Use _MSVC_LANG for some C++ dialect checks since MSVC doesn't
set __cplusplus accurately by default.
https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/
See GitHub #722.
PiperOrigin-RevId: 371362181
--
5d736accdff04db0e722f377c0d79f2d3ed53263 by Martijn Vels <mvels@google.com>:
Fix the estimated memory size for CordRepExternal
PiperOrigin-RevId: 371350380
--
eaaa1d8a167aeca67a2aa3a098a2b61a9d72172f by Martijn Vels <mvels@google.com>:
Remove flakes by not enforcing re-allocated pointers do never match original
Tests that do multiple updates could end up with the original allocated pointer on a 2nd resize, so the 'EqIfPrivate' should not assume that if we do 'not' have the capacity that all following relocations will never match the original. We only care about 'pointer unchanged if private and there is capacity', trying to establish 'pointer changed at some point due to re-allocation; is pointless.
PiperOrigin-RevId: 371338965
--
d1837bee6bade1902b095c1cbf64231668bb84c5 by Martijn Vels <mvels@google.com>:
Undo inline of small data copy in cord
This leads to a performance regression as the code is not inlined (absent hard FDO inputs), and there are no suitable tail call options.
PiperOrigin-RevId: 371332332
--
06dc64b833069efc7d18b11df607c8c22be690da by Martijn Vels <mvels@google.com>:
Add final instrumentation for Cordz and remove 'old' cordz logic.
This change instruments the last cord function for cordz. It removes the 'old' functions: set_tree, replace_tree, UpdateCordzStatistics and RecordMetrics.
PiperOrigin-RevId: 371219909
--
a5e0be538579c603052feec03e6d9910c43ea787 by Martijn Vels <mvels@google.com>:
Extend the life of CordRep* if inside a snapshot
If a snapshot (potentially) includes the current CordzInfo, we need to extent the lifetime of the CordRep*, as the snapshot 'point in time' observation of the cord should ideally be preserved.
PiperOrigin-RevId: 371146151
--
74d77a89774cd6c8ecdeebee0193b294a39383d6 by Martijn Vels <mvels@google.com>:
Instrument std::string consuming methods: ctor, operator=, Append and Prepend
This change moves the 'steal into CordRep' logic into a separate function so we can use it directly in the ctor, operator assign and append and prepend, allowing Cordz instrumentation with the proper method attributes.
The assign operator is implemented in AssignLargeString leaving the dispatch inlined in cord.h (which as a side effects also allows clean tail calls in the AssignLargeString method)
PiperOrigin-RevId: 371094756
--
b39effc45266b7ce2e7f96caa3b16cb6e3acc2dd by Martijn Vels <mvels@google.com>:
Add Cordz instrumentation to CordReader
PiperOrigin-RevId: 370990181
GitOrigin-RevId: 60b8e77be4bab1bbd3b4c3b70054879229634511
Change-Id: I96af62e6f1a643e8b1228ae01e6c84e33706bb05
4 years ago
|
|
|
class CordzStringTest : public testing::TestWithParam<TestCordSize> {
|
|
|
|
private:
|
|
|
|
CordzSamplingIntervalHelper sample_every_{1};
|
|
|
|
};
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_SUITE_P(WithParam, CordzStringTest,
|
|
|
|
testing::Values(TestCordSize::kInlined,
|
|
|
|
TestCordSize::kStringSso1,
|
|
|
|
TestCordSize::kStringSso2,
|
|
|
|
TestCordSize::kSmall,
|
|
|
|
TestCordSize::kLarge),
|
|
|
|
ParamToString<TestCordSize>);
|
|
|
|
|
|
|
|
TEST(CordzTest, ConstructSmallArray) {
|
|
|
|
CordzSamplingIntervalHelper sample_every{1};
|
|
|
|
Cord cord(MakeString(TestCordSize::kSmall));
|
|
|
|
EXPECT_THAT(cord, HasValidCordzInfoOf(Method::kConstructorString));
|
|
|
|
}
|
|
|
|
|
Export of internal Abseil changes
--
60b8e77be4bab1bbd3b4c3b70054879229634511 by Derek Mauro <dmauro@google.com>:
Use _MSVC_LANG for some C++ dialect checks since MSVC doesn't
set __cplusplus accurately by default.
https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/
See GitHub #722.
PiperOrigin-RevId: 371362181
--
5d736accdff04db0e722f377c0d79f2d3ed53263 by Martijn Vels <mvels@google.com>:
Fix the estimated memory size for CordRepExternal
PiperOrigin-RevId: 371350380
--
eaaa1d8a167aeca67a2aa3a098a2b61a9d72172f by Martijn Vels <mvels@google.com>:
Remove flakes by not enforcing re-allocated pointers do never match original
Tests that do multiple updates could end up with the original allocated pointer on a 2nd resize, so the 'EqIfPrivate' should not assume that if we do 'not' have the capacity that all following relocations will never match the original. We only care about 'pointer unchanged if private and there is capacity', trying to establish 'pointer changed at some point due to re-allocation; is pointless.
PiperOrigin-RevId: 371338965
--
d1837bee6bade1902b095c1cbf64231668bb84c5 by Martijn Vels <mvels@google.com>:
Undo inline of small data copy in cord
This leads to a performance regression as the code is not inlined (absent hard FDO inputs), and there are no suitable tail call options.
PiperOrigin-RevId: 371332332
--
06dc64b833069efc7d18b11df607c8c22be690da by Martijn Vels <mvels@google.com>:
Add final instrumentation for Cordz and remove 'old' cordz logic.
This change instruments the last cord function for cordz. It removes the 'old' functions: set_tree, replace_tree, UpdateCordzStatistics and RecordMetrics.
PiperOrigin-RevId: 371219909
--
a5e0be538579c603052feec03e6d9910c43ea787 by Martijn Vels <mvels@google.com>:
Extend the life of CordRep* if inside a snapshot
If a snapshot (potentially) includes the current CordzInfo, we need to extent the lifetime of the CordRep*, as the snapshot 'point in time' observation of the cord should ideally be preserved.
PiperOrigin-RevId: 371146151
--
74d77a89774cd6c8ecdeebee0193b294a39383d6 by Martijn Vels <mvels@google.com>:
Instrument std::string consuming methods: ctor, operator=, Append and Prepend
This change moves the 'steal into CordRep' logic into a separate function so we can use it directly in the ctor, operator assign and append and prepend, allowing Cordz instrumentation with the proper method attributes.
The assign operator is implemented in AssignLargeString leaving the dispatch inlined in cord.h (which as a side effects also allows clean tail calls in the AssignLargeString method)
PiperOrigin-RevId: 371094756
--
b39effc45266b7ce2e7f96caa3b16cb6e3acc2dd by Martijn Vels <mvels@google.com>:
Add Cordz instrumentation to CordReader
PiperOrigin-RevId: 370990181
GitOrigin-RevId: 60b8e77be4bab1bbd3b4c3b70054879229634511
Change-Id: I96af62e6f1a643e8b1228ae01e6c84e33706bb05
4 years ago
|
|
|
TEST(CordzTest, ConstructLargeArray) {
|
|
|
|
CordzSamplingIntervalHelper sample_every{1};
|
|
|
|
Cord cord(MakeString(TestCordSize::kLarge));
|
|
|
|
EXPECT_THAT(cord, HasValidCordzInfoOf(Method::kConstructorString));
|
|
|
|
}
|
|
|
|
|
Export of internal Abseil changes
--
60b8e77be4bab1bbd3b4c3b70054879229634511 by Derek Mauro <dmauro@google.com>:
Use _MSVC_LANG for some C++ dialect checks since MSVC doesn't
set __cplusplus accurately by default.
https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/
See GitHub #722.
PiperOrigin-RevId: 371362181
--
5d736accdff04db0e722f377c0d79f2d3ed53263 by Martijn Vels <mvels@google.com>:
Fix the estimated memory size for CordRepExternal
PiperOrigin-RevId: 371350380
--
eaaa1d8a167aeca67a2aa3a098a2b61a9d72172f by Martijn Vels <mvels@google.com>:
Remove flakes by not enforcing re-allocated pointers do never match original
Tests that do multiple updates could end up with the original allocated pointer on a 2nd resize, so the 'EqIfPrivate' should not assume that if we do 'not' have the capacity that all following relocations will never match the original. We only care about 'pointer unchanged if private and there is capacity', trying to establish 'pointer changed at some point due to re-allocation; is pointless.
PiperOrigin-RevId: 371338965
--
d1837bee6bade1902b095c1cbf64231668bb84c5 by Martijn Vels <mvels@google.com>:
Undo inline of small data copy in cord
This leads to a performance regression as the code is not inlined (absent hard FDO inputs), and there are no suitable tail call options.
PiperOrigin-RevId: 371332332
--
06dc64b833069efc7d18b11df607c8c22be690da by Martijn Vels <mvels@google.com>:
Add final instrumentation for Cordz and remove 'old' cordz logic.
This change instruments the last cord function for cordz. It removes the 'old' functions: set_tree, replace_tree, UpdateCordzStatistics and RecordMetrics.
PiperOrigin-RevId: 371219909
--
a5e0be538579c603052feec03e6d9910c43ea787 by Martijn Vels <mvels@google.com>:
Extend the life of CordRep* if inside a snapshot
If a snapshot (potentially) includes the current CordzInfo, we need to extent the lifetime of the CordRep*, as the snapshot 'point in time' observation of the cord should ideally be preserved.
PiperOrigin-RevId: 371146151
--
74d77a89774cd6c8ecdeebee0193b294a39383d6 by Martijn Vels <mvels@google.com>:
Instrument std::string consuming methods: ctor, operator=, Append and Prepend
This change moves the 'steal into CordRep' logic into a separate function so we can use it directly in the ctor, operator assign and append and prepend, allowing Cordz instrumentation with the proper method attributes.
The assign operator is implemented in AssignLargeString leaving the dispatch inlined in cord.h (which as a side effects also allows clean tail calls in the AssignLargeString method)
PiperOrigin-RevId: 371094756
--
b39effc45266b7ce2e7f96caa3b16cb6e3acc2dd by Martijn Vels <mvels@google.com>:
Add Cordz instrumentation to CordReader
PiperOrigin-RevId: 370990181
GitOrigin-RevId: 60b8e77be4bab1bbd3b4c3b70054879229634511
Change-Id: I96af62e6f1a643e8b1228ae01e6c84e33706bb05
4 years ago
|
|
|
TEST_P(CordzStringTest, ConstructString) {
|
|
|
|
CordzSamplingIntervalHelper sample_every{1};
|
|
|
|
Cord cord(std::string(Length(GetParam()), '.'));
|
|
|
|
if (Length(GetParam()) > kMaxInline) {
|
|
|
|
EXPECT_THAT(cord, HasValidCordzInfoOf(Method::kConstructorString));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(CordzTest, CopyConstruct) {
|
|
|
|
CordzSamplingIntervalHelper sample_every{1};
|
|
|
|
Cord src = UnsampledCord(MakeString(TestCordSize::kLarge));
|
|
|
|
Cord cord(src);
|
|
|
|
EXPECT_THAT(cord, HasValidCordzInfoOf(Method::kConstructorCord));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(CordzTest, CopyConstructFromSampled) {
|
|
|
|
CordzSamplingIntervalHelper sample_every{1};
|
|
|
|
Cord src(MakeString(TestCordSize::kLarge));
|
|
|
|
Cord cord(src);
|
|
|
|
ASSERT_THAT(cord, HasValidCordzInfoOf(Method::kConstructorCord));
|
|
|
|
CordzStatistics stats = GetCordzInfoForTesting(cord)->GetCordzStatistics();
|
|
|
|
EXPECT_THAT(stats.parent_method, Eq(Method::kConstructorString));
|
|
|
|
EXPECT_THAT(stats.update_tracker.Value(Method::kConstructorString), Eq(1));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(CordzTest, MoveConstruct) {
|
|
|
|
CordzSamplingIntervalHelper sample_every{1};
|
|
|
|
Cord src(MakeString(TestCordSize::kLarge));
|
|
|
|
Cord cord(std::move(src));
|
|
|
|
EXPECT_THAT(cord, HasValidCordzInfoOf(Method::kConstructorString));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_P(CordzUpdateTest, AssignCord) {
|
|
|
|
Cord src = UnsampledCord(MakeString(TestCordSize::kLarge));
|
|
|
|
cord() = src;
|
|
|
|
EXPECT_THAT(cord(), HasValidCordzInfoOf(Method::kAssignCord));
|
|
|
|
CordzStatistics stats = GetCordzInfoForTesting(cord())->GetCordzStatistics();
|
|
|
|
EXPECT_THAT(stats.update_tracker.Value(Method::kConstructorString), Eq(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_P(CordzUpdateTest, AssignSampledCord) {
|
|
|
|
Cord src = MakeAppendStringCord(TestCordSize::kLarge);
|
|
|
|
cord() = src;
|
|
|
|
ASSERT_THAT(cord(), HasValidCordzInfoOf(Method::kAssignCord));
|
|
|
|
CordzStatistics stats = GetCordzInfoForTesting(cord())->GetCordzStatistics();
|
|
|
|
EXPECT_THAT(stats.parent_method, Eq(Method::kAppendString));
|
|
|
|
EXPECT_THAT(stats.update_tracker.Value(Method::kAppendString), Eq(1));
|
|
|
|
EXPECT_THAT(stats.update_tracker.Value(Method::kConstructorString), Eq(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(CordzUpdateTest, AssignSampledCordToUnsampledCord) {
|
|
|
|
CordzSamplingIntervalHelper sample_every{1};
|
|
|
|
Cord src = MakeAppendStringCord(TestCordSize::kLarge);
|
|
|
|
Cord cord = UnsampledCord(MakeString(TestCordSize::kLarge));
|
|
|
|
cord = src;
|
|
|
|
ASSERT_THAT(cord, HasValidCordzInfoOf(Method::kAssignCord));
|
|
|
|
CordzStatistics stats = GetCordzInfoForTesting(cord)->GetCordzStatistics();
|
|
|
|
EXPECT_THAT(stats.parent_method, Eq(Method::kAppendString));
|
|
|
|
EXPECT_THAT(stats.update_tracker.Value(Method::kAppendString), Eq(1));
|
|
|
|
EXPECT_THAT(stats.update_tracker.Value(Method::kConstructorString), Eq(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(CordzUpdateTest, AssignSampledCordToSampledCord) {
|
|
|
|
CordzSamplingIntervalHelper sample_every{1};
|
|
|
|
Cord src = MakeAppendStringCord(TestCordSize::kLarge);
|
|
|
|
Cord cord(MakeString(TestCordSize::kLarge));
|
|
|
|
cord = src;
|
|
|
|
ASSERT_THAT(cord, HasValidCordzInfoOf(Method::kAssignCord));
|
|
|
|
CordzStatistics stats = GetCordzInfoForTesting(cord)->GetCordzStatistics();
|
|
|
|
EXPECT_THAT(stats.parent_method, Eq(Method::kAppendString));
|
|
|
|
EXPECT_THAT(stats.update_tracker.Value(Method::kAppendString), Eq(1));
|
|
|
|
EXPECT_THAT(stats.update_tracker.Value(Method::kConstructorString), Eq(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(CordzTest, AssignInlinedCord) {
|
|
|
|
CordzSampleToken token;
|
|
|
|
CordzSamplingIntervalHelper sample_every{1};
|
|
|
|
Cord cord(MakeString(TestCordSize::kLarge));
|
|
|
|
const CordzInfo* info = GetCordzInfoForTesting(cord);
|
|
|
|
Cord src = UnsampledCord(MakeString(TestCordSize::kInlined));
|
|
|
|
cord = src;
|
|
|
|
EXPECT_THAT(GetCordzInfoForTesting(cord), Eq(nullptr));
|
|
|
|
EXPECT_FALSE(CordzInfoIsListed(info));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(CordzUpdateTest, MoveAssignCord) {
|
|
|
|
CordzSamplingIntervalHelper sample_every{1};
|
|
|
|
Cord cord;
|
|
|
|
Cord src(MakeString(TestCordSize::kLarge));
|
|
|
|
cord = std::move(src);
|
|
|
|
EXPECT_THAT(cord, HasValidCordzInfoOf(Method::kConstructorString));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_P(CordzUpdateTest, AssignLargeArray) {
|
|
|
|
cord() = MakeString(TestCordSize::kSmall);
|
|
|
|
EXPECT_THAT(cord(), HasValidCordzInfoOf(Method::kAssignString));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_P(CordzUpdateTest, AssignSmallArray) {
|
|
|
|
cord() = MakeString(TestCordSize::kSmall);
|
|
|
|
EXPECT_THAT(cord(), HasValidCordzInfoOf(Method::kAssignString));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_P(CordzUpdateTest, AssignInlinedArray) {
|
|
|
|
cord() = MakeString(TestCordSize::kInlined);
|
|
|
|
EXPECT_THAT(GetCordzInfoForTesting(cord()), Eq(nullptr));
|
|
|
|
}
|
|
|
|
|
Export of internal Abseil changes
--
60b8e77be4bab1bbd3b4c3b70054879229634511 by Derek Mauro <dmauro@google.com>:
Use _MSVC_LANG for some C++ dialect checks since MSVC doesn't
set __cplusplus accurately by default.
https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/
See GitHub #722.
PiperOrigin-RevId: 371362181
--
5d736accdff04db0e722f377c0d79f2d3ed53263 by Martijn Vels <mvels@google.com>:
Fix the estimated memory size for CordRepExternal
PiperOrigin-RevId: 371350380
--
eaaa1d8a167aeca67a2aa3a098a2b61a9d72172f by Martijn Vels <mvels@google.com>:
Remove flakes by not enforcing re-allocated pointers do never match original
Tests that do multiple updates could end up with the original allocated pointer on a 2nd resize, so the 'EqIfPrivate' should not assume that if we do 'not' have the capacity that all following relocations will never match the original. We only care about 'pointer unchanged if private and there is capacity', trying to establish 'pointer changed at some point due to re-allocation; is pointless.
PiperOrigin-RevId: 371338965
--
d1837bee6bade1902b095c1cbf64231668bb84c5 by Martijn Vels <mvels@google.com>:
Undo inline of small data copy in cord
This leads to a performance regression as the code is not inlined (absent hard FDO inputs), and there are no suitable tail call options.
PiperOrigin-RevId: 371332332
--
06dc64b833069efc7d18b11df607c8c22be690da by Martijn Vels <mvels@google.com>:
Add final instrumentation for Cordz and remove 'old' cordz logic.
This change instruments the last cord function for cordz. It removes the 'old' functions: set_tree, replace_tree, UpdateCordzStatistics and RecordMetrics.
PiperOrigin-RevId: 371219909
--
a5e0be538579c603052feec03e6d9910c43ea787 by Martijn Vels <mvels@google.com>:
Extend the life of CordRep* if inside a snapshot
If a snapshot (potentially) includes the current CordzInfo, we need to extent the lifetime of the CordRep*, as the snapshot 'point in time' observation of the cord should ideally be preserved.
PiperOrigin-RevId: 371146151
--
74d77a89774cd6c8ecdeebee0193b294a39383d6 by Martijn Vels <mvels@google.com>:
Instrument std::string consuming methods: ctor, operator=, Append and Prepend
This change moves the 'steal into CordRep' logic into a separate function so we can use it directly in the ctor, operator assign and append and prepend, allowing Cordz instrumentation with the proper method attributes.
The assign operator is implemented in AssignLargeString leaving the dispatch inlined in cord.h (which as a side effects also allows clean tail calls in the AssignLargeString method)
PiperOrigin-RevId: 371094756
--
b39effc45266b7ce2e7f96caa3b16cb6e3acc2dd by Martijn Vels <mvels@google.com>:
Add Cordz instrumentation to CordReader
PiperOrigin-RevId: 370990181
GitOrigin-RevId: 60b8e77be4bab1bbd3b4c3b70054879229634511
Change-Id: I96af62e6f1a643e8b1228ae01e6c84e33706bb05
4 years ago
|
|
|
TEST_P(CordzStringTest, AssignStringToInlined) {
|
|
|
|
Cord cord;
|
|
|
|
cord = std::string(Length(GetParam()), '.');
|
|
|
|
if (Length(GetParam()) > kMaxInline) {
|
|
|
|
EXPECT_THAT(cord, HasValidCordzInfoOf(Method::kAssignString));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_P(CordzStringTest, AssignStringToCord) {
|
|
|
|
Cord cord(MakeString(TestCordSize::kLarge));
|
|
|
|
cord = std::string(Length(GetParam()), '.');
|
|
|
|
if (Length(GetParam()) > kMaxInline) {
|
|
|
|
EXPECT_THAT(cord, HasValidCordzInfoOf(Method::kConstructorString));
|
|
|
|
EXPECT_THAT(cord, CordzMethodCountEq(Method::kAssignString, 1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_P(CordzUpdateTest, AssignInlinedString) {
|
|
|
|
cord() = std::string(Length(TestCordSize::kInlined), '.');
|
|
|
|
EXPECT_THAT(GetCordzInfoForTesting(cord()), Eq(nullptr));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_P(CordzUpdateTest, AppendCord) {
|
|
|
|
Cord src = UnsampledCord(MakeString(TestCordSize::kLarge));
|
|
|
|
cord().Append(src);
|
|
|
|
EXPECT_THAT(cord(), HasValidCordzInfoOf(InitialOr(Method::kAppendCord)));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_P(CordzUpdateTest, MoveAppendCord) {
|
|
|
|
cord().Append(UnsampledCord(MakeString(TestCordSize::kLarge)));
|
|
|
|
EXPECT_THAT(cord(), HasValidCordzInfoOf(InitialOr(Method::kAppendCord)));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_P(CordzUpdateTest, AppendSmallArray) {
|
|
|
|
cord().Append(MakeString(TestCordSize::kSmall));
|
|
|
|
EXPECT_THAT(cord(), HasValidCordzInfoOf(InitialOr(Method::kAppendString)));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_P(CordzUpdateTest, AppendLargeArray) {
|
|
|
|
cord().Append(MakeString(TestCordSize::kLarge));
|
|
|
|
EXPECT_THAT(cord(), HasValidCordzInfoOf(InitialOr(Method::kAppendString)));
|
|
|
|
}
|
|
|
|
|
Export of internal Abseil changes
--
60b8e77be4bab1bbd3b4c3b70054879229634511 by Derek Mauro <dmauro@google.com>:
Use _MSVC_LANG for some C++ dialect checks since MSVC doesn't
set __cplusplus accurately by default.
https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/
See GitHub #722.
PiperOrigin-RevId: 371362181
--
5d736accdff04db0e722f377c0d79f2d3ed53263 by Martijn Vels <mvels@google.com>:
Fix the estimated memory size for CordRepExternal
PiperOrigin-RevId: 371350380
--
eaaa1d8a167aeca67a2aa3a098a2b61a9d72172f by Martijn Vels <mvels@google.com>:
Remove flakes by not enforcing re-allocated pointers do never match original
Tests that do multiple updates could end up with the original allocated pointer on a 2nd resize, so the 'EqIfPrivate' should not assume that if we do 'not' have the capacity that all following relocations will never match the original. We only care about 'pointer unchanged if private and there is capacity', trying to establish 'pointer changed at some point due to re-allocation; is pointless.
PiperOrigin-RevId: 371338965
--
d1837bee6bade1902b095c1cbf64231668bb84c5 by Martijn Vels <mvels@google.com>:
Undo inline of small data copy in cord
This leads to a performance regression as the code is not inlined (absent hard FDO inputs), and there are no suitable tail call options.
PiperOrigin-RevId: 371332332
--
06dc64b833069efc7d18b11df607c8c22be690da by Martijn Vels <mvels@google.com>:
Add final instrumentation for Cordz and remove 'old' cordz logic.
This change instruments the last cord function for cordz. It removes the 'old' functions: set_tree, replace_tree, UpdateCordzStatistics and RecordMetrics.
PiperOrigin-RevId: 371219909
--
a5e0be538579c603052feec03e6d9910c43ea787 by Martijn Vels <mvels@google.com>:
Extend the life of CordRep* if inside a snapshot
If a snapshot (potentially) includes the current CordzInfo, we need to extent the lifetime of the CordRep*, as the snapshot 'point in time' observation of the cord should ideally be preserved.
PiperOrigin-RevId: 371146151
--
74d77a89774cd6c8ecdeebee0193b294a39383d6 by Martijn Vels <mvels@google.com>:
Instrument std::string consuming methods: ctor, operator=, Append and Prepend
This change moves the 'steal into CordRep' logic into a separate function so we can use it directly in the ctor, operator assign and append and prepend, allowing Cordz instrumentation with the proper method attributes.
The assign operator is implemented in AssignLargeString leaving the dispatch inlined in cord.h (which as a side effects also allows clean tail calls in the AssignLargeString method)
PiperOrigin-RevId: 371094756
--
b39effc45266b7ce2e7f96caa3b16cb6e3acc2dd by Martijn Vels <mvels@google.com>:
Add Cordz instrumentation to CordReader
PiperOrigin-RevId: 370990181
GitOrigin-RevId: 60b8e77be4bab1bbd3b4c3b70054879229634511
Change-Id: I96af62e6f1a643e8b1228ae01e6c84e33706bb05
4 years ago
|
|
|
TEST_P(CordzStringTest, AppendStringToEmpty) {
|
|
|
|
Cord cord;
|
|
|
|
cord.Append(std::string(Length(GetParam()), '.'));
|
|
|
|
if (Length(GetParam()) > kMaxInline) {
|
|
|
|
EXPECT_THAT(cord, HasValidCordzInfoOf(Method::kAppendString));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_P(CordzStringTest, AppendStringToInlined) {
|
|
|
|
Cord cord(MakeString(TestCordSize::kInlined));
|
|
|
|
cord.Append(std::string(Length(GetParam()), '.'));
|
|
|
|
if (Length(TestCordSize::kInlined) + Length(GetParam()) > kMaxInline) {
|
|
|
|
EXPECT_THAT(cord, HasValidCordzInfoOf(Method::kAppendString));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_P(CordzStringTest, AppendStringToCord) {
|
|
|
|
Cord cord(MakeString(TestCordSize::kLarge));
|
|
|
|
cord.Append(std::string(Length(GetParam()), '.'));
|
|
|
|
EXPECT_THAT(cord, HasValidCordzInfoOf(Method::kConstructorString));
|
|
|
|
EXPECT_THAT(cord, CordzMethodCountEq(Method::kAppendString, 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(CordzTest, MakeCordFromExternal) {
|
|
|
|
CordzSamplingIntervalHelper sample_every{1};
|
|
|
|
Cord cord = MakeCordFromExternal("Hello world", [](absl::string_view) {});
|
|
|
|
EXPECT_THAT(cord, HasValidCordzInfoOf(Method::kMakeCordFromExternal));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(CordzTest, MakeCordFromEmptyExternal) {
|
|
|
|
CordzSamplingIntervalHelper sample_every{1};
|
|
|
|
Cord cord = MakeCordFromExternal({}, [](absl::string_view) {});
|
|
|
|
EXPECT_THAT(GetCordzInfoForTesting(cord), Eq(nullptr));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_P(CordzUpdateTest, PrependCord) {
|
|
|
|
Cord src = UnsampledCord(MakeString(TestCordSize::kLarge));
|
|
|
|
cord().Prepend(src);
|
|
|
|
EXPECT_THAT(cord(), HasValidCordzInfoOf(InitialOr(Method::kPrependCord)));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_P(CordzUpdateTest, PrependSmallArray) {
|
|
|
|
cord().Prepend(MakeString(TestCordSize::kSmall));
|
|
|
|
EXPECT_THAT(cord(), HasValidCordzInfoOf(InitialOr(Method::kPrependString)));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_P(CordzUpdateTest, PrependLargeArray) {
|
|
|
|
cord().Prepend(MakeString(TestCordSize::kLarge));
|
|
|
|
EXPECT_THAT(cord(), HasValidCordzInfoOf(InitialOr(Method::kPrependString)));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_P(CordzStringTest, PrependStringToEmpty) {
|
|
|
|
Cord cord;
|
|
|
|
cord.Prepend(std::string(Length(GetParam()), '.'));
|
|
|
|
if (Length(GetParam()) > kMaxInline) {
|
|
|
|
EXPECT_THAT(cord, HasValidCordzInfoOf(Method::kPrependString));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_P(CordzStringTest, PrependStringToInlined) {
|
|
|
|
Cord cord(MakeString(TestCordSize::kInlined));
|
|
|
|
cord.Prepend(std::string(Length(GetParam()), '.'));
|
|
|
|
if (Length(TestCordSize::kInlined) + Length(GetParam()) > kMaxInline) {
|
|
|
|
EXPECT_THAT(cord, HasValidCordzInfoOf(Method::kPrependString));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_P(CordzStringTest, PrependStringToCord) {
|
|
|
|
Cord cord(MakeString(TestCordSize::kLarge));
|
|
|
|
cord.Prepend(std::string(Length(GetParam()), '.'));
|
|
|
|
EXPECT_THAT(cord, HasValidCordzInfoOf(Method::kConstructorString));
|
|
|
|
EXPECT_THAT(cord, CordzMethodCountEq(Method::kPrependString, 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(CordzTest, RemovePrefix) {
|
|
|
|
CordzSamplingIntervalHelper sample_every(1);
|
|
|
|
Cord cord(MakeString(TestCordSize::kLarge));
|
|
|
|
|
|
|
|
// Half the cord
|
|
|
|
cord.RemovePrefix(cord.size() / 2);
|
|
|
|
EXPECT_THAT(cord, HasValidCordzInfoOf(Method::kConstructorString));
|
|
|
|
EXPECT_THAT(cord, CordzMethodCountEq(Method::kRemovePrefix, 1));
|
|
|
|
|
|
|
|
// TODO(mvels): RemovePrefix does not reset to inlined, except if empty?
|
|
|
|
cord.RemovePrefix(cord.size() - kMaxInline);
|
|
|
|
EXPECT_THAT(cord, HasValidCordzInfoOf(Method::kConstructorString));
|
|
|
|
EXPECT_THAT(cord, CordzMethodCountEq(Method::kRemovePrefix, 2));
|
|
|
|
|
|
|
|
cord.RemovePrefix(cord.size());
|
|
|
|
EXPECT_THAT(GetCordzInfoForTesting(cord), Eq(nullptr));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(CordzTest, RemoveSuffix) {
|
|
|
|
CordzSamplingIntervalHelper sample_every(1);
|
|
|
|
Cord cord(MakeString(TestCordSize::kLarge));
|
|
|
|
|
|
|
|
// Half the cord
|
|
|
|
cord.RemoveSuffix(cord.size() / 2);
|
|
|
|
EXPECT_THAT(cord, HasValidCordzInfoOf(Method::kConstructorString));
|
|
|
|
EXPECT_THAT(cord, CordzMethodCountEq(Method::kRemoveSuffix, 1));
|
|
|
|
|
|
|
|
// TODO(mvels): RemoveSuffix does not reset to inlined, except if empty?
|
|
|
|
cord.RemoveSuffix(cord.size() - kMaxInline);
|
|
|
|
EXPECT_THAT(cord, HasValidCordzInfoOf(Method::kConstructorString));
|
|
|
|
EXPECT_THAT(cord, CordzMethodCountEq(Method::kRemoveSuffix, 2));
|
|
|
|
|
|
|
|
cord.RemoveSuffix(cord.size());
|
|
|
|
EXPECT_THAT(GetCordzInfoForTesting(cord), Eq(nullptr));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(CordzTest, SubCord) {
|
|
|
|
CordzSamplingIntervalHelper sample_every{1};
|
|
|
|
Cord src = UnsampledCord(MakeString(TestCordSize::kLarge));
|
|
|
|
Cord cord = src.Subcord(10, src.size() / 2);
|
|
|
|
EXPECT_THAT(cord, HasValidCordzInfoOf(Method::kSubCord));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(CordzTest, SmallSubCord) {
|
|
|
|
CordzSamplingIntervalHelper sample_every{1};
|
|
|
|
Cord src = UnsampledCord(MakeString(TestCordSize::kLarge));
|
|
|
|
Cord cord = src.Subcord(10, kMaxInline + 1);
|
|
|
|
EXPECT_THAT(cord, HasValidCordzInfoOf(Method::kSubCord));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(CordzTest, SubCordFromSampledCord) {
|
|
|
|
CordzSamplingIntervalHelper sample_every{1};
|
|
|
|
Cord src(MakeString(TestCordSize::kLarge));
|
|
|
|
Cord cord = src.Subcord(10, src.size() / 2);
|
|
|
|
EXPECT_THAT(cord, HasValidCordzInfoOf(Method::kSubCord));
|
|
|
|
CordzStatistics stats = GetCordzInfoForTesting(cord)->GetCordzStatistics();
|
|
|
|
EXPECT_THAT(stats.parent_method, Eq(Method::kConstructorString));
|
|
|
|
EXPECT_THAT(stats.update_tracker.Value(Method::kConstructorString), Eq(1));
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
ABSL_NAMESPACE_END
|
|
|
|
} // namespace absl
|
|
|
|
|
|
|
|
#endif // ABSL_INTERNAL_CORDZ_ENABLED
|