Index: third_party/grpc/test/cpp/qps/qps_interarrival_test.cc |
diff --git a/third_party/tcmalloc/chromium/src/base/thread_lister.c b/third_party/grpc/test/cpp/qps/qps_interarrival_test.cc |
similarity index 54% |
copy from third_party/tcmalloc/chromium/src/base/thread_lister.c |
copy to third_party/grpc/test/cpp/qps/qps_interarrival_test.cc |
index bc180dba7a9f2ba3b8261009c8af85f0b1d4a023..77e81fb84bc1a92dfcf4f4d307d584d716d73c8c 100644 |
--- a/third_party/tcmalloc/chromium/src/base/thread_lister.c |
+++ b/third_party/grpc/test/cpp/qps/qps_interarrival_test.cc |
@@ -1,4 +1,6 @@ |
-/* Copyright (c) 2005-2007, Google Inc. |
+/* |
+ * |
+ * Copyright 2015-2016, Google Inc. |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
@@ -27,51 +29,48 @@ |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
* |
- * --- |
- * Author: Markus Gutschke |
*/ |
-#include "config.h" |
-#include <stdio.h> /* needed for NULL on some powerpc platforms (?!) */ |
-#ifdef HAVE_SYS_PRCTL |
-# include <sys/prctl.h> |
-#endif |
-#include "base/thread_lister.h" |
-#include "base/linuxthreads.h" |
-/* Include other thread listers here that define THREADS macro |
- * only when they can provide a good implementation. |
- */ |
+#include <chrono> |
+#include <iostream> |
-#ifndef THREADS |
+// Use the C histogram rather than C++ to avoid depending on proto |
+#include <grpc/support/histogram.h> |
-/* Default trivial thread lister for single-threaded applications, |
- * or if the multi-threading code has not been ported, yet. |
- */ |
+#include "test/cpp/qps/interarrival.h" |
-int ListAllProcessThreads(void *parameter, |
- ListAllProcessThreadsCallBack callback, ...) { |
- int rc; |
- va_list ap; |
- pid_t pid; |
+using grpc::testing::RandomDistInterface; |
+using grpc::testing::InterarrivalTimer; |
-#ifdef HAVE_SYS_PRCTL |
- int dumpable = prctl(PR_GET_DUMPABLE, 0); |
- if (!dumpable) |
- prctl(PR_SET_DUMPABLE, 1); |
-#endif |
- va_start(ap, callback); |
- pid = getpid(); |
- rc = callback(parameter, 1, &pid, ap); |
- va_end(ap); |
-#ifdef HAVE_SYS_PRCTL |
- if (!dumpable) |
- prctl(PR_SET_DUMPABLE, 0); |
-#endif |
- return rc; |
-} |
+static void RunTest(RandomDistInterface &&r, int threads, std::string title) { |
+ InterarrivalTimer timer; |
+ timer.init(r, threads); |
+ gpr_histogram *h(gpr_histogram_create(0.01, 60e9)); |
-int ResumeAllProcessThreads(int num_threads, pid_t *thread_pids) { |
- return 1; |
+ for (int i = 0; i < 10000000; i++) { |
+ for (int j = 0; j < threads; j++) { |
+ gpr_histogram_add(h, timer.next(j)); |
+ } |
+ } |
+ |
+ std::cout << title << " Distribution" << std::endl; |
+ std::cout << "Value, Percentile" << std::endl; |
+ for (double pct = 0.0; pct < 100.0; pct += 1.0) { |
+ std::cout << gpr_histogram_percentile(h, pct) << "," << pct << std::endl; |
+ } |
+ |
+ gpr_histogram_destroy(h); |
} |
-#endif /* ifndef THREADS */ |
+using grpc::testing::ExpDist; |
+using grpc::testing::DetDist; |
+using grpc::testing::UniformDist; |
+using grpc::testing::ParetoDist; |
+ |
+int main(int argc, char **argv) { |
+ RunTest(ExpDist(10.0), 5, std::string("Exponential(10)")); |
+ RunTest(DetDist(5.0), 5, std::string("Det(5)")); |
+ RunTest(UniformDist(0.0, 10.0), 5, std::string("Uniform(0,10)")); |
+ RunTest(ParetoDist(1.0, 1.0), 5, std::string("Pareto(1,1)")); |
+ return 0; |
+} |