LCOV - code coverage report
Current view: top level - test/cpp/qps - perf_db_client.cc (source / functions) Hit Total Coverage
Test: tmp.zDYK9MVh93 Lines: 1 60 1.7 %
Date: 2015-10-10 Functions: 2 8 25.0 %

          Line data    Source code
       1             : /*
       2             :  *
       3             :  * Copyright 2015, Google Inc.
       4             :  * All rights reserved.
       5             :  *
       6             :  * Redistribution and use in source and binary forms, with or without
       7             :  * modification, are permitted provided that the following conditions are
       8             :  * met:
       9             :  *
      10             :  *     * Redistributions of source code must retain the above copyright
      11             :  * notice, this list of conditions and the following disclaimer.
      12             :  *     * Redistributions in binary form must reproduce the above
      13             :  * copyright notice, this list of conditions and the following disclaimer
      14             :  * in the documentation and/or other materials provided with the
      15             :  * distribution.
      16             :  *     * Neither the name of Google Inc. nor the names of its
      17             :  * contributors may be used to endorse or promote products derived from
      18             :  * this software without specific prior written permission.
      19             :  *
      20             :  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
      21             :  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
      22             :  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
      23             :  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
      24             :  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
      25             :  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
      26             :  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
      27             :  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
      28             :  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
      29             :  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
      30             :  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
      31             :  *
      32             :  */
      33             : 
      34             : #include "test/cpp/qps/perf_db_client.h"
      35             : 
      36             : namespace grpc {
      37             : namespace testing {
      38             : 
      39             : // sets the client and server config information
      40           0 : void PerfDbClient::setConfigs(const ClientConfig& client_config,
      41             :                               const ServerConfig& server_config) {
      42           0 :   client_config_ = client_config;
      43           0 :   server_config_ = server_config;
      44           0 : }
      45             : 
      46             : // sets the QPS
      47           0 : void PerfDbClient::setQps(double qps) { qps_ = qps; }
      48             : 
      49             : // sets the QPS per core
      50           0 : void PerfDbClient::setQpsPerCore(double qps_per_core) {
      51           0 :   qps_per_core_ = qps_per_core;
      52           0 : }
      53             : 
      54             : // sets the 50th, 90th, 95th, 99th and 99.9th percentile latency
      55           0 : void PerfDbClient::setLatencies(double perc_lat_50, double perc_lat_90,
      56             :                                 double perc_lat_95, double perc_lat_99,
      57             :                                 double perc_lat_99_point_9) {
      58           0 :   perc_lat_50_ = perc_lat_50;
      59           0 :   perc_lat_90_ = perc_lat_90;
      60           0 :   perc_lat_95_ = perc_lat_95;
      61           0 :   perc_lat_99_ = perc_lat_99;
      62           0 :   perc_lat_99_point_9_ = perc_lat_99_point_9;
      63           0 : }
      64             : 
      65             : // sets the server and client, user and system times
      66           0 : void PerfDbClient::setTimes(double server_system_time, double server_user_time,
      67             :                             double client_system_time,
      68             :                             double client_user_time) {
      69           0 :   server_system_time_ = server_system_time;
      70           0 :   server_user_time_ = server_user_time;
      71           0 :   client_system_time_ = client_system_time;
      72           0 :   client_user_time_ = client_user_time;
      73           0 : }
      74             : 
      75             : // sends the data to the performance database server
      76           0 : bool PerfDbClient::sendData(std::string hashed_id, std::string test_name,
      77             :                             std::string sys_info, std::string tag) {
      78             :   // Data record request object
      79           0 :   SingleUserRecordRequest single_user_record_request;
      80             : 
      81             :   // setting access token, name of the test and the system information
      82           0 :   single_user_record_request.set_hashed_id(hashed_id);
      83           0 :   single_user_record_request.set_test_name(test_name);
      84           0 :   single_user_record_request.set_sys_info(sys_info);
      85           0 :   single_user_record_request.set_tag(tag);
      86             : 
      87             :   // setting configs
      88           0 :   *(single_user_record_request.mutable_client_config()) = client_config_;
      89           0 :   *(single_user_record_request.mutable_server_config()) = server_config_;
      90             : 
      91           0 :   Metrics* metrics = single_user_record_request.mutable_metrics();
      92             : 
      93             :   // setting metrcs in data record request
      94           0 :   if (qps_ != DBL_MIN) {
      95           0 :     metrics->set_qps(qps_);
      96             :   }
      97           0 :   if (qps_per_core_ != DBL_MIN) {
      98           0 :     metrics->set_qps_per_core(qps_per_core_);
      99             :   }
     100           0 :   if (perc_lat_50_ != DBL_MIN) {
     101           0 :     metrics->set_perc_lat_50(perc_lat_50_);
     102             :   }
     103           0 :   if (perc_lat_90_ != DBL_MIN) {
     104           0 :     metrics->set_perc_lat_90(perc_lat_90_);
     105             :   }
     106           0 :   if (perc_lat_95_ != DBL_MIN) {
     107           0 :     metrics->set_perc_lat_95(perc_lat_95_);
     108             :   }
     109           0 :   if (perc_lat_99_ != DBL_MIN) {
     110           0 :     metrics->set_perc_lat_99(perc_lat_99_);
     111             :   }
     112           0 :   if (perc_lat_99_point_9_ != DBL_MIN) {
     113           0 :     metrics->set_perc_lat_99_point_9(perc_lat_99_point_9_);
     114             :   }
     115           0 :   if (server_system_time_ != DBL_MIN) {
     116           0 :     metrics->set_server_system_time(server_system_time_);
     117             :   }
     118           0 :   if (server_user_time_ != DBL_MIN) {
     119           0 :     metrics->set_server_user_time(server_user_time_);
     120             :   }
     121           0 :   if (client_system_time_ != DBL_MIN) {
     122           0 :     metrics->set_client_system_time(client_system_time_);
     123             :   }
     124           0 :   if (client_user_time_ != DBL_MIN) {
     125           0 :     metrics->set_client_user_time(client_user_time_);
     126             :   }
     127             : 
     128           0 :   SingleUserRecordReply single_user_record_reply;
     129           0 :   ClientContext context;
     130             : 
     131             :   Status status = stub_->RecordSingleClientData(
     132           0 :       &context, single_user_record_request, &single_user_record_reply);
     133           0 :   if (status.ok()) {
     134           0 :     return true;  // data sent to database successfully
     135             :   } else {
     136           0 :     return false;  // error in data sending
     137           0 :   }
     138             : }
     139             : }  // testing
     140          18 : }  // grpc

Generated by: LCOV version 1.10