memory_usage_test.cc
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2015 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 #include <stdio.h>
20 #include <string.h>
21 
22 #include "absl/flags/flag.h"
23 #include "absl/flags/parse.h"
24 #include "absl/strings/str_cat.h"
25 
26 #include <grpc/support/alloc.h>
27 #include <grpc/support/log.h>
29 
32 #include "test/core/util/port.h"
34 
35 ABSL_FLAG(int, warmup, 100, "Warmup iterations");
36 ABSL_FLAG(int, benchmark, 1000, "Benchmark iterations");
37 ABSL_FLAG(bool, minstack, false, "Use minimal stack");
38 
39 class Subprocess {
40  public:
41  explicit Subprocess(std::vector<std::string> args) {
42  std::vector<const char*> args_c;
43  args_c.reserve(args.size());
44  for (const auto& arg : args) {
45  args_c.push_back(arg.c_str());
46  }
47  process_ = gpr_subprocess_create(args_c.size(), args_c.data());
48  }
49 
50  int Join() { return gpr_subprocess_join(process_); }
52 
54 
55  private:
57 };
58 
59 int main(int argc, char** argv) {
60  absl::ParseCommandLine(argc, argv);
61 
62  char* me = argv[0];
63  char* lslash = strrchr(me, '/');
64  char root[1024];
66  std::vector<const char*> args;
67  int status;
68  /* figure out where we are */
69  if (lslash) {
70  memcpy(root, me, static_cast<size_t>(lslash - me));
71  root[lslash - me] = 0;
72  } else {
73  strcpy(root, ".");
74  }
75  /* start the server */
76  Subprocess svr({absl::StrCat(root, "/memory_usage_server",
78  "--bind", grpc_core::JoinHostPort("::", port), "--nosecure",
79  absl::StrCat("--minstack=", absl::GetFlag(FLAGS_minstack))});
80 
81  /* start the client */
82  Subprocess cli({absl::StrCat(root, "/memory_usage_client",
84  "--target", grpc_core::JoinHostPort("127.0.0.1", port),
85  absl::StrCat("--warmup=", absl::GetFlag(FLAGS_warmup)),
86  absl::StrCat("--benchmark=", absl::GetFlag(FLAGS_benchmark)),
87  absl::StrCat("--minstack=", absl::GetFlag(FLAGS_minstack))});
88 
89  /* wait for completion */
90  if ((status = cli.Join()) != 0) {
91  printf("client failed with: %d", status);
92  return 1;
93  }
94 
95  svr.Interrupt();
96  return svr.Join() == 0 ? 0 : 2;
97 }
log.h
port.h
benchmark
Definition: bm_alarm.cc:55
absl::StrCat
std::string StrCat(const AlphaNum &a, const AlphaNum &b)
Definition: abseil-cpp/absl/strings/str_cat.cc:98
main
int main(int argc, char **argv)
Definition: memory_usage_test.cc:59
string.h
Subprocess
Definition: memory_usage_test.cc:39
printf
_Use_decl_annotations_ int __cdecl printf(const char *_Format,...)
Definition: cs_driver.c:91
ABSL_FLAG
ABSL_FLAG(int, warmup, 100, "Warmup iterations")
gpr_subprocess_binary_extension
const char * gpr_subprocess_binary_extension()
absl::ParseCommandLine
std::vector< char * > ParseCommandLine(int argc, char *argv[])
Definition: abseil-cpp/absl/flags/parse.cc:815
status
absl::Status status
Definition: rls.cc:251
Subprocess::Subprocess
Subprocess(std::vector< std::string > args)
Definition: memory_usage_test.cc:41
warmup
static void warmup(const char *path)
Definition: benchmark-fs-stat.c:46
gpr_subprocess_interrupt
void gpr_subprocess_interrupt(gpr_subprocess *p)
string_util.h
memcpy
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
asyncio_get_stats.args
args
Definition: asyncio_get_stats.py:40
root
RefCountedPtr< grpc_tls_certificate_provider > root
Definition: xds_server_config_fetcher.cc:223
grpc_core::JoinHostPort
std::string JoinHostPort(absl::string_view host, int port)
Definition: host_port.cc:32
Subprocess::process_
gpr_subprocess * process_
Definition: memory_usage_test.cc:56
arg
Definition: cmdline.cc:40
absl::GetFlag
ABSL_MUST_USE_RESULT T GetFlag(const absl::Flag< T > &flag)
Definition: abseil-cpp/absl/flags/flag.h:98
host_port.h
grpc_pick_unused_port_or_die
int grpc_pick_unused_port_or_die(void)
gpr_subprocess
struct gpr_subprocess gpr_subprocess
Definition: test/core/util/subprocess.h:24
subprocess.h
tests.unit._exit_scenarios.port
port
Definition: _exit_scenarios.py:179
Subprocess::Join
int Join()
Definition: memory_usage_test.cc:50
gpr_subprocess_create
gpr_subprocess * gpr_subprocess_create(int argc, const char **argv)
alloc.h
gpr_subprocess_join
int gpr_subprocess_join(gpr_subprocess *p)
gpr_subprocess_destroy
void gpr_subprocess_destroy(gpr_subprocess *p)
Subprocess::~Subprocess
~Subprocess()
Definition: memory_usage_test.cc:53
Subprocess::Interrupt
void Interrupt()
Definition: memory_usage_test.cc:51


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:00:36