aboutsummaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/core/debug/stats_test.cc123
-rw-r--r--test/core/iomgr/fd_conservation_posix_test.c5
-rw-r--r--test/cpp/microbenchmarks/helpers.cc13
-rw-r--r--test/cpp/qps/BUILD1
-rw-r--r--test/cpp/qps/client.h5
-rw-r--r--test/cpp/qps/report.cc28
-rw-r--r--test/cpp/qps/report.h3
-rw-r--r--test/cpp/qps/server.h5
8 files changed, 177 insertions, 6 deletions
diff --git a/test/core/debug/stats_test.cc b/test/core/debug/stats_test.cc
new file mode 100644
index 0000000000..c85ab3598a
--- /dev/null
+++ b/test/core/debug/stats_test.cc
@@ -0,0 +1,123 @@
+/*
+ *
+ * Copyright 2017 gRPC 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
+ *
+ * http://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.
+ *
+ */
+
+extern "C" {
+#include "src/core/lib/debug/stats.h"
+}
+
+#include <grpc/grpc.h>
+#include <grpc/support/log.h>
+#include <gtest/gtest.h>
+
+namespace grpc {
+namespace testing {
+
+class Snapshot {
+ public:
+ Snapshot() { grpc_stats_collect(&begin_); }
+
+ grpc_stats_data delta() {
+ grpc_stats_data now;
+ grpc_stats_collect(&now);
+ grpc_stats_data delta;
+ grpc_stats_diff(&now, &begin_, &delta);
+ return delta;
+ }
+
+ private:
+ grpc_stats_data begin_;
+};
+
+TEST(StatsTest, IncCounters) {
+ for (int i = 0; i < GRPC_STATS_COUNTER_COUNT; i++) {
+ Snapshot snapshot;
+
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ GRPC_STATS_INC_COUNTER(&exec_ctx, (grpc_stats_counters)i);
+ grpc_exec_ctx_finish(&exec_ctx);
+
+ EXPECT_EQ(snapshot.delta().counters[i], 1);
+ }
+}
+
+TEST(StatsTest, IncSpecificCounter) {
+ Snapshot snapshot;
+
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ GRPC_STATS_INC_SYSCALL_POLL(&exec_ctx);
+ grpc_exec_ctx_finish(&exec_ctx);
+
+ EXPECT_EQ(snapshot.delta().counters[GRPC_STATS_COUNTER_SYSCALL_POLL], 1);
+}
+
+static int FindExpectedBucket(int i, int j) {
+ if (j < 0) {
+ return 0;
+ }
+ if (j >= grpc_stats_histo_bucket_boundaries[i][grpc_stats_histo_buckets[i]]) {
+ return grpc_stats_histo_buckets[i] - 1;
+ }
+ return std::upper_bound(grpc_stats_histo_bucket_boundaries[i],
+ grpc_stats_histo_bucket_boundaries[i] +
+ grpc_stats_histo_buckets[i],
+ j) -
+ grpc_stats_histo_bucket_boundaries[i] - 1;
+}
+
+TEST(StatsTest, IncHistogram) {
+ for (int i = 0; i < GRPC_STATS_HISTOGRAM_COUNT; i++) {
+ std::vector<int> test_values;
+ for (int j = -1000;
+ j <
+ grpc_stats_histo_bucket_boundaries[i]
+ [grpc_stats_histo_buckets[i] - 1] +
+ 1000;
+ j++) {
+ test_values.push_back(j);
+ }
+ std::random_shuffle(test_values.begin(), test_values.end());
+ if (test_values.size() > 10000) {
+ test_values.resize(10000);
+ }
+ for (auto j : test_values) {
+ Snapshot snapshot;
+
+ int expected_bucket = FindExpectedBucket(i, j);
+
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_stats_inc_histogram[i](&exec_ctx, j);
+ grpc_exec_ctx_finish(&exec_ctx);
+
+ auto delta = snapshot.delta();
+
+ EXPECT_EQ(delta.histograms[grpc_stats_histo_start[i] + expected_bucket],
+ 1);
+ }
+ }
+}
+
+} // namespace testing
+} // namespace grpc
+
+int main(int argc, char** argv) {
+ ::testing::InitGoogleTest(&argc, argv);
+ grpc_init();
+ int ret = RUN_ALL_TESTS();
+ grpc_shutdown();
+ return ret;
+}
diff --git a/test/core/iomgr/fd_conservation_posix_test.c b/test/core/iomgr/fd_conservation_posix_test.c
index 3c61173ecd..d29b1e8e41 100644
--- a/test/core/iomgr/fd_conservation_posix_test.c
+++ b/test/core/iomgr/fd_conservation_posix_test.c
@@ -30,9 +30,8 @@ int main(int argc, char **argv) {
grpc_endpoint_pair p;
grpc_test_init(argc, argv);
+ grpc_init();
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
- grpc_iomgr_init(&exec_ctx);
- grpc_iomgr_start(&exec_ctx);
/* set max # of file descriptors to a low value, and
verify we can create and destroy many more than this number
@@ -51,7 +50,7 @@ int main(int argc, char **argv) {
grpc_resource_quota_unref(resource_quota);
- grpc_iomgr_shutdown(&exec_ctx);
grpc_exec_ctx_finish(&exec_ctx);
+ grpc_shutdown();
return 0;
}
diff --git a/test/cpp/microbenchmarks/helpers.cc b/test/cpp/microbenchmarks/helpers.cc
index 415d27445f..b0caa48cd0 100644
--- a/test/cpp/microbenchmarks/helpers.cc
+++ b/test/cpp/microbenchmarks/helpers.cc
@@ -31,10 +31,17 @@ void TrackCounters::Finish(benchmark::State &state) {
void TrackCounters::AddToLabel(std::ostream &out, benchmark::State &state) {
grpc_stats_data stats_end;
grpc_stats_collect(&stats_end);
+ grpc_stats_data stats;
+ grpc_stats_diff(&stats_end, &stats_begin_, &stats);
for (int i = 0; i < GRPC_STATS_COUNTER_COUNT; i++) {
- out << " " << grpc_stats_counter_name[i] << "/iter:"
- << ((double)(stats_end.counters[i] - stats_begin_.counters[i]) /
- (double)state.iterations());
+ out << " " << grpc_stats_counter_name[i]
+ << "/iter:" << ((double)stats.counters[i] / (double)state.iterations());
+ }
+ for (int i = 0; i < GRPC_STATS_HISTOGRAM_COUNT; i++) {
+ out << " " << grpc_stats_histogram_name[i] << "-median:"
+ << grpc_stats_histo_percentile(&stats, (grpc_stats_histograms)i, 50.0)
+ << " " << grpc_stats_histogram_name[i] << "-99p:"
+ << grpc_stats_histo_percentile(&stats, (grpc_stats_histograms)i, 99.0);
}
#ifdef GPR_LOW_LEVEL_COUNTERS
grpc_memory_counters counters_at_end = grpc_memory_counters_snapshot();
diff --git a/test/cpp/qps/BUILD b/test/cpp/qps/BUILD
index 31f210dec0..3352269517 100644
--- a/test/cpp/qps/BUILD
+++ b/test/cpp/qps/BUILD
@@ -46,6 +46,7 @@ grpc_cc_library(
":usage_timer",
"//:grpc",
"//:grpc++",
+ "//:grpc++_core_stats",
"//src/proto/grpc/testing:control_proto",
"//src/proto/grpc/testing:payloads_proto",
"//src/proto/grpc/testing:services_proto",
diff --git a/test/cpp/qps/client.h b/test/cpp/qps/client.h
index b1d90aa9c4..7fbaf63492 100644
--- a/test/cpp/qps/client.h
+++ b/test/cpp/qps/client.h
@@ -34,6 +34,7 @@
#include "src/proto/grpc/testing/payloads.pb.h"
#include "src/proto/grpc/testing/services.grpc.pb.h"
+#include "src/cpp/util/core_stats.h"
#include "test/cpp/qps/histogram.h"
#include "test/cpp/qps/interarrival.h"
#include "test/cpp/qps/usage_timer.h"
@@ -172,6 +173,9 @@ class Client {
timer_result = timer_->Mark();
}
+ grpc_stats_data core_stats;
+ grpc_stats_collect(&core_stats);
+
ClientStats stats;
latencies.FillProto(stats.mutable_latencies());
for (StatusHistogram::const_iterator it = statuses.begin();
@@ -184,6 +188,7 @@ class Client {
stats.set_time_system(timer_result.system);
stats.set_time_user(timer_result.user);
stats.set_cq_poll_count(poll_count);
+ CoreStatsToProto(core_stats, stats.mutable_core_stats());
return stats;
}
diff --git a/test/cpp/qps/report.cc b/test/cpp/qps/report.cc
index a45b10bcb8..3c99bda144 100644
--- a/test/cpp/qps/report.cc
+++ b/test/cpp/qps/report.cc
@@ -26,6 +26,7 @@
#include "test/cpp/qps/stats.h"
#include <grpc++/client_context.h>
+#include "src/cpp/util/core_stats.h"
#include "src/proto/grpc/testing/services.grpc.pb.h"
namespace grpc {
@@ -85,6 +86,33 @@ void GprLogReporter::ReportQPS(const ScenarioResult& result) {
gpr_log(GPR_INFO, "successful requests/second: %.1f",
result.summary().successful_requests_per_second());
}
+ for (int i = 0; i < result.client_stats_size(); i++) {
+ if (result.client_stats(i).has_core_stats()) {
+ ReportCoreStats("CLIENT", i, result.client_stats(i).core_stats());
+ }
+ }
+ for (int i = 0; i < result.server_stats_size(); i++) {
+ if (result.server_stats(i).has_core_stats()) {
+ ReportCoreStats("SERVER", i, result.server_stats(i).core_stats());
+ }
+ }
+}
+
+void GprLogReporter::ReportCoreStats(const char* name, int idx,
+ const grpc::core::Stats& stats) {
+ grpc_stats_data data;
+ ProtoToCoreStats(stats, &data);
+ for (int i = 0; i < GRPC_STATS_COUNTER_COUNT; i++) {
+ gpr_log(GPR_DEBUG, "%s[%d].%s = %" PRIdPTR, name, idx,
+ grpc_stats_counter_name[i], data.counters[i]);
+ }
+ for (int i = 0; i < GRPC_STATS_HISTOGRAM_COUNT; i++) {
+ gpr_log(GPR_DEBUG, "%s[%d].%s = %lf/%lf/%lf (50/95/99%%-ile)", name, idx,
+ grpc_stats_histogram_name[i],
+ grpc_stats_histo_percentile(&data, (grpc_stats_histograms)i, 50),
+ grpc_stats_histo_percentile(&data, (grpc_stats_histograms)i, 95),
+ grpc_stats_histo_percentile(&data, (grpc_stats_histograms)i, 99));
+ }
}
void GprLogReporter::ReportQPSPerCore(const ScenarioResult& result) {
diff --git a/test/cpp/qps/report.h b/test/cpp/qps/report.h
index 321be2a97f..1d7b2b54e7 100644
--- a/test/cpp/qps/report.h
+++ b/test/cpp/qps/report.h
@@ -104,6 +104,9 @@ class GprLogReporter : public Reporter {
void ReportCpuUsage(const ScenarioResult& result) override;
void ReportPollCount(const ScenarioResult& result) override;
void ReportQueriesPerCpuSec(const ScenarioResult& result) override;
+
+ void ReportCoreStats(const char* name, int idx,
+ const grpc::core::Stats& stats);
};
/** Dumps the report to a JSON file. */
diff --git a/test/cpp/qps/server.h b/test/cpp/qps/server.h
index 3d6f347cae..16d101d5e6 100644
--- a/test/cpp/qps/server.h
+++ b/test/cpp/qps/server.h
@@ -26,6 +26,7 @@
#include <grpc/support/log.h>
#include <vector>
+#include "src/cpp/util/core_stats.h"
#include "src/proto/grpc/testing/control.pb.h"
#include "src/proto/grpc/testing/messages.pb.h"
#include "test/core/end2end/data/ssl_test_data.h"
@@ -63,6 +64,9 @@ class Server {
timer_result = timer_->Mark();
}
+ grpc_stats_data core_stats;
+ grpc_stats_collect(&core_stats);
+
ServerStats stats;
stats.set_time_elapsed(timer_result.wall);
stats.set_time_system(timer_result.system);
@@ -70,6 +74,7 @@ class Server {
stats.set_total_cpu_time(timer_result.total_cpu_time);
stats.set_idle_cpu_time(timer_result.idle_cpu_time);
stats.set_cq_poll_count(poll_count);
+ CoreStatsToProto(core_stats, stats.mutable_core_stats());
return stats;
}