Skip to content
Snippets Groups Projects
Commit ae5e7ade authored by Florian Fischer's avatar Florian Fischer
Browse files

[Echoclient] improve output file handling

* Open file only when the benchmark was successful
* Append to existing files without writing the header
parent 7629dff4
No related branches found
No related tags found
No related merge requests found
Pipeline #59078 passed
...@@ -212,15 +212,7 @@ auto main(int argc, char* argv[]) -> int { ...@@ -212,15 +212,7 @@ auto main(int argc, char* argv[]) -> int {
} }
int out_fd = STDOUT_FILENO; int out_fd = STDOUT_FILENO;
char* output_file = getOption(argc, argv, "-f"); char* output_file = getOption(argc, argv, "-f");
if (output_file) {
out_fd = open(output_file, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
if (out_fd < 0) {
DIE_MSG_ERRNO("opening output file failed");
}
}
int err = getaddrinfo(host.c_str(), port.c_str(), nullptr, &server); int err = getaddrinfo(host.c_str(), port.c_str(), nullptr, &server);
if (err) { if (err) {
...@@ -281,7 +273,26 @@ auto main(int argc, char* argv[]) -> int { ...@@ -281,7 +273,26 @@ auto main(int argc, char* argv[]) -> int {
auto total_duration = duration_cast<nanoseconds>(echo_end - connect_start).count(); auto total_duration = duration_cast<nanoseconds>(echo_end - connect_start).count();
std::stringstream sst; std::stringstream sst;
sst << "clients,iterations,size,avg_ns,connect,echo,total" << std::endl; bool exists = true;
if (output_file) {
exists = access(output_file, W_OK) == 0;
int openflags;
int mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH;
if (!exists) {
openflags = O_CREAT | O_WRONLY;
} else {
openflags = O_APPEND;
}
out_fd = emper::io::openAndWait(output_file, openflags, mode);
if (out_fd < 0) {
DIE_MSG_ERRNO("opening output file failed");
}
}
if (!exists) {
sst << "clients,iterations,size,avg_ns,connect,echo,total" << std::endl;
}
sst << clients << "," << iterations << "," << size << "," << avg_ns << "," << connect_duration sst << clients << "," << iterations << "," << size << "," << avg_ns << "," << connect_duration
<< "," << echo_duration << "," << total_duration << std::endl; << "," << echo_duration << "," << total_duration << std::endl;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment