|
|
@ -20,7 +20,10 @@ extern "C" { |
|
|
|
#include "src/core/lib/debug/stats.h" |
|
|
|
#include "src/core/lib/debug/stats.h" |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <thread> |
|
|
|
|
|
|
|
|
|
|
|
#include <grpc/grpc.h> |
|
|
|
#include <grpc/grpc.h> |
|
|
|
|
|
|
|
#include <grpc/support/cpu.h> |
|
|
|
#include <grpc/support/log.h> |
|
|
|
#include <grpc/support/log.h> |
|
|
|
#include <gtest/gtest.h> |
|
|
|
#include <gtest/gtest.h> |
|
|
|
|
|
|
|
|
|
|
@ -79,38 +82,51 @@ static int FindExpectedBucket(int i, int j) { |
|
|
|
grpc_stats_histo_bucket_boundaries[i] - 1; |
|
|
|
grpc_stats_histo_bucket_boundaries[i] - 1; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST(StatsTest, IncHistogram) { |
|
|
|
class HistogramTest : public ::testing::TestWithParam<int> {}; |
|
|
|
for (int i = 0; i < GRPC_STATS_HISTOGRAM_COUNT; i++) { |
|
|
|
|
|
|
|
std::vector<int> test_values; |
|
|
|
TEST_P(HistogramTest, IncHistogram) { |
|
|
|
for (int j = -1000; |
|
|
|
const int kHistogram = GetParam(); |
|
|
|
j < |
|
|
|
const int kThreads = std::max(1, (int)gpr_cpu_num_cores()); |
|
|
|
grpc_stats_histo_bucket_boundaries[i] |
|
|
|
std::vector<std::thread> threads; |
|
|
|
[grpc_stats_histo_buckets[i] - 1] + |
|
|
|
for (int thread = 0; thread < kThreads; thread++) { |
|
|
|
1000; |
|
|
|
threads.emplace_back([kHistogram, kThreads, thread]() { |
|
|
|
j++) { |
|
|
|
std::vector<int> test_values; |
|
|
|
test_values.push_back(j); |
|
|
|
for (int j = -1000 + thread; |
|
|
|
} |
|
|
|
j < grpc_stats_histo_bucket_boundaries |
|
|
|
std::random_shuffle(test_values.begin(), test_values.end()); |
|
|
|
[kHistogram][grpc_stats_histo_buckets[kHistogram] - 1] + |
|
|
|
if (test_values.size() > 10000) { |
|
|
|
1000; |
|
|
|
test_values.resize(10000); |
|
|
|
j += kThreads) { |
|
|
|
} |
|
|
|
test_values.push_back(j); |
|
|
|
for (auto j : test_values) { |
|
|
|
} |
|
|
|
Snapshot snapshot; |
|
|
|
std::random_shuffle(test_values.begin(), test_values.end()); |
|
|
|
|
|
|
|
for (auto j : test_values) { |
|
|
|
int expected_bucket = FindExpectedBucket(i, j); |
|
|
|
Snapshot snapshot; |
|
|
|
|
|
|
|
|
|
|
|
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |
|
|
|
int expected_bucket = FindExpectedBucket(kHistogram, j); |
|
|
|
grpc_stats_inc_histogram[i](&exec_ctx, j); |
|
|
|
|
|
|
|
grpc_exec_ctx_finish(&exec_ctx); |
|
|
|
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |
|
|
|
|
|
|
|
grpc_stats_inc_histogram[kHistogram](&exec_ctx, j); |
|
|
|
auto delta = snapshot.delta(); |
|
|
|
grpc_exec_ctx_finish(&exec_ctx); |
|
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(delta.histograms[grpc_stats_histo_start[i] + expected_bucket], |
|
|
|
auto delta = snapshot.delta(); |
|
|
|
1); |
|
|
|
|
|
|
|
} |
|
|
|
EXPECT_GE(delta.histograms[grpc_stats_histo_start[kHistogram] + |
|
|
|
|
|
|
|
expected_bucket], |
|
|
|
|
|
|
|
1) |
|
|
|
|
|
|
|
<< "\nhistogram:" << kHistogram |
|
|
|
|
|
|
|
<< "\nexpected_bucket:" << expected_bucket << "\nthread:" << thread |
|
|
|
|
|
|
|
<< "\nj:" << j; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
for (auto& t : threads) { |
|
|
|
|
|
|
|
t.join(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(HistogramTestCases, HistogramTest, |
|
|
|
|
|
|
|
::testing::Range<int>(0, GRPC_STATS_HISTOGRAM_COUNT)); |
|
|
|
|
|
|
|
|
|
|
|
} // namespace testing
|
|
|
|
} // namespace testing
|
|
|
|
} // namespace grpc
|
|
|
|
} // namespace grpc
|
|
|
|
|
|
|
|
|
|
|
|