Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: third_party/grpc/test/cpp/qps/qps_interarrival_test.cc

Issue 1932353002: Initial checkin of gRPC to third_party/ Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* Copyright (c) 2005-2007, Google Inc. 1 /*
2 *
3 * Copyright 2015-2016, Google Inc.
2 * All rights reserved. 4 * All rights reserved.
3 * 5 *
4 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 7 * modification, are permitted provided that the following conditions are
6 * met: 8 * met:
7 * 9 *
8 * * Redistributions of source code must retain the above copyright 10 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 12 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer 13 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the 14 * in the documentation and/or other materials provided with the
13 * distribution. 15 * distribution.
14 * * Neither the name of Google Inc. nor the names of its 16 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from 17 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission. 18 * this software without specific prior written permission.
17 * 19 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 * 31 *
30 * ---
31 * Author: Markus Gutschke
32 */ 32 */
33 33
34 #include "config.h" 34 #include <chrono>
35 #include <stdio.h> /* needed for NULL on some powerpc platforms (?!) */ 35 #include <iostream>
36 #ifdef HAVE_SYS_PRCTL
37 # include <sys/prctl.h>
38 #endif
39 #include "base/thread_lister.h"
40 #include "base/linuxthreads.h"
41 /* Include other thread listers here that define THREADS macro
42 * only when they can provide a good implementation.
43 */
44 36
45 #ifndef THREADS 37 // Use the C histogram rather than C++ to avoid depending on proto
38 #include <grpc/support/histogram.h>
46 39
47 /* Default trivial thread lister for single-threaded applications, 40 #include "test/cpp/qps/interarrival.h"
48 * or if the multi-threading code has not been ported, yet.
49 */
50 41
51 int ListAllProcessThreads(void *parameter, 42 using grpc::testing::RandomDistInterface;
52 ListAllProcessThreadsCallBack callback, ...) { 43 using grpc::testing::InterarrivalTimer;
53 int rc;
54 va_list ap;
55 pid_t pid;
56 44
57 #ifdef HAVE_SYS_PRCTL 45 static void RunTest(RandomDistInterface &&r, int threads, std::string title) {
58 int dumpable = prctl(PR_GET_DUMPABLE, 0); 46 InterarrivalTimer timer;
59 if (!dumpable) 47 timer.init(r, threads);
60 prctl(PR_SET_DUMPABLE, 1); 48 gpr_histogram *h(gpr_histogram_create(0.01, 60e9));
61 #endif 49
62 va_start(ap, callback); 50 for (int i = 0; i < 10000000; i++) {
63 pid = getpid(); 51 for (int j = 0; j < threads; j++) {
64 rc = callback(parameter, 1, &pid, ap); 52 gpr_histogram_add(h, timer.next(j));
65 va_end(ap); 53 }
66 #ifdef HAVE_SYS_PRCTL 54 }
67 if (!dumpable) 55
68 prctl(PR_SET_DUMPABLE, 0); 56 std::cout << title << " Distribution" << std::endl;
69 #endif 57 std::cout << "Value, Percentile" << std::endl;
70 return rc; 58 for (double pct = 0.0; pct < 100.0; pct += 1.0) {
59 std::cout << gpr_histogram_percentile(h, pct) << "," << pct << std::endl;
60 }
61
62 gpr_histogram_destroy(h);
71 } 63 }
72 64
73 int ResumeAllProcessThreads(int num_threads, pid_t *thread_pids) { 65 using grpc::testing::ExpDist;
74 return 1; 66 using grpc::testing::DetDist;
67 using grpc::testing::UniformDist;
68 using grpc::testing::ParetoDist;
69
70 int main(int argc, char **argv) {
71 RunTest(ExpDist(10.0), 5, std::string("Exponential(10)"));
72 RunTest(DetDist(5.0), 5, std::string("Det(5)"));
73 RunTest(UniformDist(0.0, 10.0), 5, std::string("Uniform(0,10)"));
74 RunTest(ParetoDist(1.0, 1.0), 5, std::string("Pareto(1,1)"));
75 return 0;
75 } 76 }
76
77 #endif /* ifndef THREADS */
OLDNEW
« no previous file with comments | « third_party/grpc/test/cpp/qps/qps_driver.cc ('k') | third_party/grpc/test/cpp/qps/qps_openloop_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698