Write protos as binary.

We need to write protos as "wb" and not "w", otherwise we get CRLF
on Windows which corrupts the proto.

Bug: chromium:1029452
Change-Id: Iabf841405134d7bc2523ac48219ca7cb9d8214c1
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/170320
Commit-Queue: Patrik Höglund <phoglund@webrtc.org>
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#30772}
This commit is contained in:
Patrik Höglund
2020-03-12 09:39:40 +01:00
committed by Commit Bot
parent f092e4d0ff
commit b8e69efcee
7 changed files with 41 additions and 15 deletions

View File

@ -220,11 +220,29 @@ void PrintPlottableResults(const std::vector<std::string>& desired_graphs) {
GetPlottableCounterPrinter().Print(desired_graphs);
}
void WritePerfResults(const std::string& output_path) {
bool WritePerfResults(const std::string& output_path) {
std::string results = GetPerfResults();
std::fstream output(output_path, std::fstream::out);
output << results;
output.close();
FILE* output;
if (absl::GetFlag(FLAGS_write_histogram_proto_json)) {
output = fopen(output_path.c_str(), "wb");
} else {
output = fopen(output_path.c_str(), "w");
}
if (output == NULL) {
printf("Failed to write to %s.\n", output_path.c_str());
return false;
}
size_t written =
fwrite(results.c_str(), sizeof(char), results.size(), output);
fclose(output);
if (written != results.size()) {
long expected = results.size();
printf("Wrote %zu, tried to write %lu\n", written, expected);
return false;
}
return true;
}
void PrintResult(const std::string& measurement,