batched changes

pull/8313/head
Yuxuan Li 9 years ago
parent 3a9f49d409
commit fe21ec90f6
  1. 92
      Makefile
  2. 15
      build.yaml
  3. 3
      src/proto/grpc/testing/control.proto
  4. 6
      src/proto/grpc/testing/stats.proto
  5. 7
      test/cpp/qps/driver.cc
  6. 189
      test/cpp/qps/latency_vs_load.cc
  7. 5
      test/cpp/qps/qps_json_driver.cc
  8. 14
      test/cpp/qps/report.cc
  9. 9
      test/cpp/qps/report.h
  10. 2
      test/cpp/qps/server.h
  11. 28
      test/cpp/qps/usage_timer.cc
  12. 2
      test/cpp/qps/usage_timer.h
  13. 2
      test/cpp/util/benchmark_config.cc
  14. 40
      tools/run_tests/sources_and_headers.json

@ -1059,6 +1059,7 @@ interop_client: $(BINDIR)/$(CONFIG)/interop_client
interop_server: $(BINDIR)/$(CONFIG)/interop_server
interop_test: $(BINDIR)/$(CONFIG)/interop_test
json_run_localhost: $(BINDIR)/$(CONFIG)/json_run_localhost
latency_vs_load: $(BINDIR)/$(CONFIG)/latency_vs_load
metrics_client: $(BINDIR)/$(CONFIG)/metrics_client
mock_test: $(BINDIR)/$(CONFIG)/mock_test
proto_server_reflection_test: $(BINDIR)/$(CONFIG)/proto_server_reflection_test
@ -1077,6 +1078,7 @@ shutdown_test: $(BINDIR)/$(CONFIG)/shutdown_test
status_test: $(BINDIR)/$(CONFIG)/status_test
streaming_throughput_test: $(BINDIR)/$(CONFIG)/streaming_throughput_test
stress_test: $(BINDIR)/$(CONFIG)/stress_test
test_qps: $(BINDIR)/$(CONFIG)/test_qps
thread_stress_test: $(BINDIR)/$(CONFIG)/thread_stress_test
public_headers_must_be_c89: $(BINDIR)/$(CONFIG)/public_headers_must_be_c89
boringssl_aes_test: $(BINDIR)/$(CONFIG)/boringssl_aes_test
@ -1427,6 +1429,7 @@ buildtests_cxx: privatelibs_cxx \
$(BINDIR)/$(CONFIG)/interop_server \
$(BINDIR)/$(CONFIG)/interop_test \
$(BINDIR)/$(CONFIG)/json_run_localhost \
$(BINDIR)/$(CONFIG)/latency_vs_load \
$(BINDIR)/$(CONFIG)/metrics_client \
$(BINDIR)/$(CONFIG)/mock_test \
$(BINDIR)/$(CONFIG)/proto_server_reflection_test \
@ -1445,6 +1448,7 @@ buildtests_cxx: privatelibs_cxx \
$(BINDIR)/$(CONFIG)/status_test \
$(BINDIR)/$(CONFIG)/streaming_throughput_test \
$(BINDIR)/$(CONFIG)/stress_test \
$(BINDIR)/$(CONFIG)/test_qps \
$(BINDIR)/$(CONFIG)/thread_stress_test \
$(BINDIR)/$(CONFIG)/boringssl_aes_test \
$(BINDIR)/$(CONFIG)/boringssl_asn1_test \
@ -1514,6 +1518,7 @@ buildtests_cxx: privatelibs_cxx \
$(BINDIR)/$(CONFIG)/interop_server \
$(BINDIR)/$(CONFIG)/interop_test \
$(BINDIR)/$(CONFIG)/json_run_localhost \
$(BINDIR)/$(CONFIG)/latency_vs_load \
$(BINDIR)/$(CONFIG)/metrics_client \
$(BINDIR)/$(CONFIG)/mock_test \
$(BINDIR)/$(CONFIG)/proto_server_reflection_test \
@ -1532,6 +1537,7 @@ buildtests_cxx: privatelibs_cxx \
$(BINDIR)/$(CONFIG)/status_test \
$(BINDIR)/$(CONFIG)/streaming_throughput_test \
$(BINDIR)/$(CONFIG)/stress_test \
$(BINDIR)/$(CONFIG)/test_qps \
$(BINDIR)/$(CONFIG)/thread_stress_test \
endif
@ -12170,6 +12176,49 @@ endif
endif
LATENCY_VS_LOAD_SRC = \
test/cpp/qps/latency_vs_load.cc \
LATENCY_VS_LOAD_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(LATENCY_VS_LOAD_SRC))))
ifeq ($(NO_SECURE),true)
# You can't build secure targets if you don't have OpenSSL.
$(BINDIR)/$(CONFIG)/latency_vs_load: openssl_dep_error
else
ifeq ($(NO_PROTOBUF),true)
# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+.
$(BINDIR)/$(CONFIG)/latency_vs_load: protobuf_dep_error
else
$(BINDIR)/$(CONFIG)/latency_vs_load: $(PROTOBUF_DEP) $(LATENCY_VS_LOAD_OBJS) $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a
$(E) "[LD] Linking $@"
$(Q) mkdir -p `dirname $@`
$(Q) $(LDXX) $(LDFLAGS) $(LATENCY_VS_LOAD_OBJS) $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/latency_vs_load
endif
endif
$(OBJDIR)/$(CONFIG)/test/cpp/qps/latency_vs_load.o: $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a
deps_latency_vs_load: $(LATENCY_VS_LOAD_OBJS:.o=.dep)
ifneq ($(NO_SECURE),true)
ifneq ($(NO_DEPS),true)
-include $(LATENCY_VS_LOAD_OBJS:.o=.dep)
endif
endif
METRICS_CLIENT_SRC = \
$(GENDIR)/src/proto/grpc/testing/metrics.pb.cc $(GENDIR)/src/proto/grpc/testing/metrics.grpc.pb.cc \
test/cpp/interop/metrics_client.cc \
@ -12996,6 +13045,49 @@ $(OBJDIR)/$(CONFIG)/test/cpp/interop/stress_test.o: $(GENDIR)/src/proto/grpc/tes
$(OBJDIR)/$(CONFIG)/test/cpp/util/metrics_server.o: $(GENDIR)/src/proto/grpc/testing/empty.pb.cc $(GENDIR)/src/proto/grpc/testing/empty.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/messages.pb.cc $(GENDIR)/src/proto/grpc/testing/messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/metrics.pb.cc $(GENDIR)/src/proto/grpc/testing/metrics.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/test.pb.cc $(GENDIR)/src/proto/grpc/testing/test.grpc.pb.cc
TEST_QPS_SRC = \
test/cpp/qps/test_qps.cc \
TEST_QPS_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(TEST_QPS_SRC))))
ifeq ($(NO_SECURE),true)
# You can't build secure targets if you don't have OpenSSL.
$(BINDIR)/$(CONFIG)/test_qps: openssl_dep_error
else
ifeq ($(NO_PROTOBUF),true)
# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+.
$(BINDIR)/$(CONFIG)/test_qps: protobuf_dep_error
else
$(BINDIR)/$(CONFIG)/test_qps: $(PROTOBUF_DEP) $(TEST_QPS_OBJS) $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a
$(E) "[LD] Linking $@"
$(Q) mkdir -p `dirname $@`
$(Q) $(LDXX) $(LDFLAGS) $(TEST_QPS_OBJS) $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/test_qps
endif
endif
$(OBJDIR)/$(CONFIG)/test/cpp/qps/test_qps.o: $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a
deps_test_qps: $(TEST_QPS_OBJS:.o=.dep)
ifneq ($(NO_SECURE),true)
ifneq ($(NO_DEPS),true)
-include $(TEST_QPS_OBJS:.o=.dep)
endif
endif
THREAD_STRESS_TEST_SRC = \
test/cpp/end2end/thread_stress_test.cc \

@ -3032,6 +3032,21 @@ targets:
- gpr_test_util
- gpr
- grpc++_test_config
- name: latency_vs_load
build: test
run: false
language: c++
src:
- test/cpp/qps/latency_vs_load.cc
deps:
- qps
- grpc++_test_util
- grpc_test_util
- grpc++
- grpc
- gpr_test_util
- gpr
- grpc++_test_config
- name: metrics_client
build: test
run: false

@ -213,6 +213,9 @@ message ScenarioResultSummary
double latency_95 = 9;
double latency_99 = 10;
double latency_999 = 11;
// server cpu usage percentage
double server_cpu_usage = 12;
}
// Results of a single benchmark scenario.

@ -41,6 +41,12 @@ message ServerStats {
// change in server time (in seconds) used by the server process and all
// threads since last reset
double time_system = 3;
// change in total cpu time of the server (data from proc/stat)
uint64 total_cpu_time = 4;
// change in idle time of the server (data from proc/stat)
uint64 idle_cpu_time = 5;
}
// Histogram params based on grpc/support/histogram.c

@ -124,6 +124,8 @@ static double UserTime(ClientStats s) { return s.time_user(); }
static double ServerWallTime(ServerStats s) { return s.time_elapsed(); }
static double ServerSystemTime(ServerStats s) { return s.time_system(); }
static double ServerUserTime(ServerStats s) { return s.time_user(); }
static double ServerTotalCpuTime(ServerStats s) { return s.total_cpu_time(); }
static double ServerIdleCpuTime(ServerStats s) { return s.idle_cpu_time(); }
static int Cores(int n) { return n; }
// Postprocess ScenarioResult and populate result summary.
@ -147,6 +149,10 @@ static void postprocess_scenario_result(ScenarioResult* result) {
sum(result->server_stats(), ServerWallTime);
auto server_user_time = 100.0 * sum(result->server_stats(), ServerUserTime) /
sum(result->server_stats(), ServerWallTime);
auto server_cpu_usage = 100 - 100 * average(result->server_stats(), ServerIdleCpuTime) /
average(result->server_stats(), ServerTotalCpuTime);
gpr_log(GPR_INFO, "total cpu: %.1f, idle cpu: %.1f", average(result->server_stats(), ServerTotalCpuTime),
average(result->server_stats(), ServerIdleCpuTime));
auto client_system_time = 100.0 * sum(result->client_stats(), SystemTime) /
sum(result->client_stats(), WallTime);
auto client_user_time = 100.0 * sum(result->client_stats(), UserTime) /
@ -156,6 +162,7 @@ static void postprocess_scenario_result(ScenarioResult* result) {
result->mutable_summary()->set_server_user_time(server_user_time);
result->mutable_summary()->set_client_system_time(client_system_time);
result->mutable_summary()->set_client_user_time(client_user_time);
result->mutable_summary()->set_server_cpu_usage(server_cpu_usage);
}
// Namespace for classes and functions used only in RunScenario

@ -0,0 +1,189 @@
/*
*
* Copyright 2015-2016, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <memory>
#include <set>
#include <grpc++/impl/codegen/config_protobuf.h>
#include <gflags/gflags.h>
#include <grpc/support/log.h>
#include "test/cpp/qps/driver.h"
#include "test/cpp/qps/parse_json.h"
#include "test/cpp/qps/report.h"
#include "test/cpp/util/benchmark_config.h"
DEFINE_string(scenarios_file, "",
"JSON file containing an array of Scenario objects");
DEFINE_string(scenarios_json, "",
"JSON string containing an array of Scenario objects");
DEFINE_bool(quit, false, "Quit the workers");
DEFINE_double(initial_offered_load, 1000.0, "Set up for intial offered load");
DEFINE_double(targeted_cpu_load, 99.0, "targeted cpu load");
namespace grpc {
namespace testing {
static double GetCpuLoad(Scenario * scenario, double offered_load) {
scenario->mutable_client_config()->mutable_load_params()->mutable_poisson()->
set_offered_load(offered_load);
auto result =
RunScenario(scenario->client_config(), scenario->num_clients(),
scenario->server_config(), scenario->num_servers(),
scenario->warmup_seconds(), scenario->benchmark_seconds(),
scenario->spawn_local_worker_count());
GetReporter()->ReportQPS(*result);
GetReporter()->ReportQPSPerCore(*result);
GetReporter()->ReportLatency(*result);
GetReporter()->ReportTimes(*result);
GetReporter()->ReportCpuUsage(*result);
bool success = true;
for (int i = 0; success && i < result->client_success_size(); i++) {
success = result->client_success(i);
}
for (int i = 0; success && i < result->server_success_size(); i++) {
success = result->server_success(i);
}
return success ? result->summary().server_cpu_usage() : -1;
}
static double BinarySearch(Scenario * scenario, double targeted_cpu_load,
double low_offered_load, double high_offered_load) {
int low = int(low_offered_load);
int high = int(high_offered_load);
while (low <= high - 500) {
int mid = low + (high - low) /2;
double current_cpu_load = GetCpuLoad(scenario, double(mid));
gpr_log(GPR_INFO, "binary search: current_offered_load %d", mid);
if (targeted_cpu_load < current_cpu_load) {
high = mid -1;
}
else if (targeted_cpu_load > current_cpu_load) {
low = mid + 1;
}
else {
high = mid - 1;
}
}
return double(low);
}
static double SearchOfferedLoad(double initial_offered_load, double targeted_cpu_load,
Scenario * scenario) {
std::cerr << "RUNNING SCENARIO: " << scenario->name() << "\n";
double current_offered_load = initial_offered_load;
double current_cpu_load = GetCpuLoad(scenario, current_offered_load);
if (current_cpu_load > targeted_cpu_load) {
gpr_log(GPR_ERROR, "Initial offered load too high");
return -1;
}
do {
current_offered_load *= 2;
current_cpu_load = GetCpuLoad(scenario, current_offered_load);
gpr_log(GPR_INFO, "do while: current_offered_load %f", current_offered_load);
} while (current_cpu_load < targeted_cpu_load);
double targeted_offered_load = BinarySearch(scenario, targeted_cpu_load,
current_offered_load / 2,
current_offered_load);
gpr_log(GPR_INFO, "targeted_offered_load %f", targeted_offered_load);
return targeted_offered_load;
}
static bool CpuLoadDriver() {
grpc::string json;
bool scfile = (FLAGS_scenarios_file != "");
bool scjson = (FLAGS_scenarios_json != "");
if ((!scfile && !scjson && !FLAGS_quit) ||
(scfile && (scjson || FLAGS_quit)) || (scjson && FLAGS_quit)) {
gpr_log(GPR_ERROR,
"Exactly one of --scenarios_file, --scenarios_json, "
"or --quit must be set");
abort();
}
if (scfile) {
// Read the json data from disk
FILE *json_file = fopen(FLAGS_scenarios_file.c_str(), "r");
GPR_ASSERT(json_file != NULL);
fseek(json_file, 0, SEEK_END);
long len = ftell(json_file);
char *data = new char[len];
fseek(json_file, 0, SEEK_SET);
GPR_ASSERT(len == (long)fread(data, 1, len, json_file));
fclose(json_file);
json = grpc::string(data, data + len);
delete[] data;
} else if (scjson) {
json = FLAGS_scenarios_json.c_str();
} else if (FLAGS_quit) {
return RunQuit();
}
// Parse into an array of scenarios
Scenarios scenarios;
ParseJson(json.c_str(), "grpc.testing.Scenarios", &scenarios);
// Make sure that there is at least some valid scenario here
GPR_ASSERT(scenarios.scenarios_size() > 0);
bool success = true;
for (int i = 0; i < scenarios.scenarios_size(); i++) {
Scenario *scenario = scenarios.mutable_scenarios(i);
SearchOfferedLoad(FLAGS_initial_offered_load, FLAGS_targeted_cpu_load, scenario);
// GetCpuLoad(scenario, FLAGS_initial_offered_load);
}
return success;
}
} // namespace testing
} // namespace grpc
int main(int argc, char **argv) {
grpc::testing::InitBenchmark(&argc, &argv, true);
bool ok = grpc::testing::CpuLoadDriver();
return ok ? 0 : 1;
}

@ -50,6 +50,10 @@ DEFINE_string(scenarios_json, "",
"JSON string containing an array of Scenario objects");
DEFINE_bool(quit, false, "Quit the workers");
DEFINE_double(initial_offered_load, 1000.0, "Set up for intial offered load");
DEFINE_double(targeted_cpu_load, 99.0, "targeted cpu load");
namespace grpc {
namespace testing {
@ -109,6 +113,7 @@ static bool QpsDriver() {
GetReporter()->ReportQPSPerCore(*result);
GetReporter()->ReportLatency(*result);
GetReporter()->ReportTimes(*result);
GetReporter()->ReportCpuUsage(*result);
for (int i = 0; success && i < result->client_success_size(); i++) {
success = result->client_success(i);

@ -71,6 +71,11 @@ void CompositeReporter::ReportTimes(const ScenarioResult& result) {
}
}
void CompositeReporter::ReportCpuUsage(const ScenarioResult& result) {
for (size_t i = 0; i < reporters_.size(); ++i) {
reporters_[i]->ReportCpuUsage(result);
}
}
void GprLogReporter::ReportQPS(const ScenarioResult& result) {
gpr_log(GPR_INFO, "QPS: %.1f", result.summary().qps());
}
@ -101,6 +106,11 @@ void GprLogReporter::ReportTimes(const ScenarioResult& result) {
result.summary().client_user_time());
}
void GprLogReporter::ReportCpuUsage(const ScenarioResult& result) {
gpr_log(GPR_INFO, "Server CPU usage: %.2f%%",
result.summary().server_cpu_usage());
}
void JsonReporter::ReportQPS(const ScenarioResult& result) {
grpc::string json_string =
SerializeJson(result, "type.googleapis.com/grpc.testing.ScenarioResult");
@ -121,5 +131,9 @@ void JsonReporter::ReportTimes(const ScenarioResult& result) {
// NOP - all reporting is handled by ReportQPS.
}
void JsonReporter::ReportCpuUsage(const ScenarioResult& result) {
// NOP - all reporting is handled by ReportQPS.
}
} // namespace testing
} // namespace grpc

@ -70,6 +70,9 @@ class Reporter {
/** Reports system and user time for client and server systems. */
virtual void ReportTimes(const ScenarioResult& result) = 0;
/** Reports server cpu usage. */
virtual void ReportCpuUsage(const ScenarioResult& result) = 0;
private:
const string name_;
};
@ -86,6 +89,7 @@ class CompositeReporter : public Reporter {
void ReportQPSPerCore(const ScenarioResult& result) GRPC_OVERRIDE;
void ReportLatency(const ScenarioResult& result) GRPC_OVERRIDE;
void ReportTimes(const ScenarioResult& result) GRPC_OVERRIDE;
void ReportCpuUsage(const ScenarioResult& result) GRPC_OVERRIDE;
private:
std::vector<std::unique_ptr<Reporter> > reporters_;
@ -101,6 +105,8 @@ class GprLogReporter : public Reporter {
void ReportQPSPerCore(const ScenarioResult& result) GRPC_OVERRIDE;
void ReportLatency(const ScenarioResult& result) GRPC_OVERRIDE;
void ReportTimes(const ScenarioResult& result) GRPC_OVERRIDE;
void ReportCpuUsage(const ScenarioResult& result) GRPC_OVERRIDE;
};
/** Dumps the report to a JSON file. */
@ -114,7 +120,8 @@ class JsonReporter : public Reporter {
void ReportQPSPerCore(const ScenarioResult& result) GRPC_OVERRIDE;
void ReportLatency(const ScenarioResult& result) GRPC_OVERRIDE;
void ReportTimes(const ScenarioResult& result) GRPC_OVERRIDE;
void ReportCpuUsage(const ScenarioResult& result) GRPC_OVERRIDE;
const string report_file_;
};

@ -75,6 +75,8 @@ class Server {
stats.set_time_elapsed(timer_result.wall);
stats.set_time_system(timer_result.system);
stats.set_time_user(timer_result.user);
stats.set_total_cpu_time(timer_result.total_cpu_time);
stats.set_idle_cpu_time(timer_result.idle_cpu_time);
return stats;
}

@ -33,10 +33,13 @@
#include "test/cpp/qps/usage_timer.h"
#include <fstream>
#include <string>
#include <sstream>
#include <grpc/support/time.h>
#include <sys/resource.h>
#include <sys/time.h>
UsageTimer::UsageTimer() : start_(Sample()) {}
double UsageTimer::Now() {
@ -48,6 +51,23 @@ static double time_double(struct timeval* tv) {
return tv->tv_sec + 1e-6 * tv->tv_usec;
}
static void get_cpu_usage(unsigned long long* total_cpu_time,
unsigned long long* idle_cpu_time) {
std::ifstream proc_stat("/proc/stat");
proc_stat.ignore(5);
std::string cpu_time_str;
std::string first_line;
std::getline(proc_stat, first_line);
std::stringstream first_line_s(first_line);
for(int i = 0; i < 10; ++i) {
std::getline(first_line_s, cpu_time_str, ' ');
*total_cpu_time += std::stoi(cpu_time_str);
if (i == 3) {
*idle_cpu_time = std::stoi(cpu_time_str);
}
}
}
UsageTimer::Result UsageTimer::Sample() {
struct rusage usage;
struct timeval tv;
@ -58,6 +78,9 @@ UsageTimer::Result UsageTimer::Sample() {
r.wall = time_double(&tv);
r.user = time_double(&usage.ru_utime);
r.system = time_double(&usage.ru_stime);
r.total_cpu_time = 0;
r.idle_cpu_time = 0;
get_cpu_usage(&r.total_cpu_time, &r.idle_cpu_time);
return r;
}
@ -67,5 +90,8 @@ UsageTimer::Result UsageTimer::Mark() const {
r.wall = s.wall - start_.wall;
r.user = s.user - start_.user;
r.system = s.system - start_.system;
r.total_cpu_time = s.total_cpu_time - start_.total_cpu_time;
r.idle_cpu_time = s.idle_cpu_time - start_.idle_cpu_time;
return r;
}

@ -42,6 +42,8 @@ class UsageTimer {
double wall;
double user;
double system;
unsigned long long total_cpu_time;
unsigned long long idle_cpu_time;
};
Result Mark() const;

@ -51,6 +51,8 @@ DEFINE_string(server_address, "localhost:50052",
DEFINE_string(tag, "", "Optional tag for the test");
// In some distros, gflags is in the namespace google, and in some others,
// in gflags. This hack is enabling us to find both.
namespace google {}

@ -2710,6 +2710,26 @@
"third_party": false,
"type": "target"
},
{
"deps": [
"gpr",
"gpr_test_util",
"grpc",
"grpc++",
"grpc++_test_config",
"grpc++_test_util",
"grpc_test_util",
"qps"
],
"headers": [],
"language": "c++",
"name": "latency_vs_load",
"src": [
"test/cpp/qps/latency_vs_load.cc"
],
"third_party": false,
"type": "target"
},
{
"deps": [
"gpr",
@ -3111,6 +3131,26 @@
"third_party": false,
"type": "target"
},
{
"deps": [
"gpr",
"gpr_test_util",
"grpc",
"grpc++",
"grpc++_test_config",
"grpc++_test_util",
"grpc_test_util",
"qps"
],
"headers": [],
"language": "c++",
"name": "test_qps",
"src": [
"test/cpp/qps/test_qps.cc"
],
"third_party": false,
"type": "target"
},
{
"deps": [
"gpr",

Loading…
Cancel
Save