Skip to content

fix(autoware_processing_time_checker): fix bugprone-exception-escape #9780

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 25, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -103,45 +103,51 @@
return;
}

// generate json data
nlohmann::json j;
for (const auto & accumulator_iterator : processing_time_accumulator_map_) {
const auto module_name = accumulator_iterator.first;
const auto processing_time_accumulator = accumulator_iterator.second;
j[module_name + "/min"] = processing_time_accumulator.min();
j[module_name + "/max"] = processing_time_accumulator.max();
j[module_name + "/mean"] = processing_time_accumulator.mean();
j[module_name + "/count"] = processing_time_accumulator.count();
j[module_name + "/description"] = "processing time of " + module_name + "[ms]";
}
try {
// generate json data
nlohmann::json j;
for (const auto & accumulator_iterator : processing_time_accumulator_map_) {
const auto module_name = accumulator_iterator.first;
const auto processing_time_accumulator = accumulator_iterator.second;
j[module_name + "/min"] = processing_time_accumulator.min();
j[module_name + "/max"] = processing_time_accumulator.max();
j[module_name + "/mean"] = processing_time_accumulator.mean();
j[module_name + "/count"] = processing_time_accumulator.count();
j[module_name + "/description"] = "processing time of " + module_name + "[ms]";

Check warning on line 116 in system/autoware_processing_time_checker/src/processing_time_checker.cpp

View check run for this annotation

Codecov / codecov/patch

system/autoware_processing_time_checker/src/processing_time_checker.cpp#L111-L116

Added lines #L111 - L116 were not covered by tests
}

// get output folder
const std::string output_folder_str =
rclcpp::get_logging_directory().string() + "/autoware_metrics";
if (!std::filesystem::exists(output_folder_str)) {
if (!std::filesystem::create_directories(output_folder_str)) {
RCLCPP_ERROR(
this->get_logger(), "Failed to create directories: %s", output_folder_str.c_str());
return;
// get output folder
const std::string output_folder_str =
rclcpp::get_logging_directory().string() + "/autoware_metrics";

Check warning on line 121 in system/autoware_processing_time_checker/src/processing_time_checker.cpp

View check run for this annotation

Codecov / codecov/patch

system/autoware_processing_time_checker/src/processing_time_checker.cpp#L121

Added line #L121 was not covered by tests
if (!std::filesystem::exists(output_folder_str)) {
if (!std::filesystem::create_directories(output_folder_str)) {
RCLCPP_ERROR(

Check warning on line 124 in system/autoware_processing_time_checker/src/processing_time_checker.cpp

View check run for this annotation

Codecov / codecov/patch

system/autoware_processing_time_checker/src/processing_time_checker.cpp#L124

Added line #L124 was not covered by tests
this->get_logger(), "Failed to create directories: %s", output_folder_str.c_str());
return;

Check warning on line 126 in system/autoware_processing_time_checker/src/processing_time_checker.cpp

View check run for this annotation

Codecov / codecov/patch

system/autoware_processing_time_checker/src/processing_time_checker.cpp#L126

Added line #L126 was not covered by tests
}
}
}

// get time stamp
std::time_t now_time_t = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
std::tm * local_time = std::localtime(&now_time_t);
std::ostringstream oss;
oss << std::put_time(local_time, "%Y-%m-%d-%H-%M-%S");
std::string cur_time_str = oss.str();

// Write metrics .json to file
const std::string output_file_str =
output_folder_str + "/autoware_processing_time_checker-" + cur_time_str + ".json";
std::ofstream f(output_file_str);
if (f.is_open()) {
f << j.dump(4);
f.close();
} else {
RCLCPP_ERROR(this->get_logger(), "Failed to open file: %s", output_file_str.c_str());
// get time stamp
std::time_t now_time_t = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
std::tm * local_time = std::localtime(&now_time_t);
std::ostringstream oss;
oss << std::put_time(local_time, "%Y-%m-%d-%H-%M-%S");

Check warning on line 134 in system/autoware_processing_time_checker/src/processing_time_checker.cpp

View check run for this annotation

Codecov / codecov/patch

system/autoware_processing_time_checker/src/processing_time_checker.cpp#L131-L134

Added lines #L131 - L134 were not covered by tests
std::string cur_time_str = oss.str();

// Write metrics .json to file
const std::string output_file_str =
output_folder_str + "/autoware_processing_time_checker-" + cur_time_str + ".json";
std::ofstream f(output_file_str);

Check warning on line 140 in system/autoware_processing_time_checker/src/processing_time_checker.cpp

View check run for this annotation

Codecov / codecov/patch

system/autoware_processing_time_checker/src/processing_time_checker.cpp#L139-L140

Added lines #L139 - L140 were not covered by tests
if (f.is_open()) {
f << j.dump(4);
f.close();

Check warning on line 143 in system/autoware_processing_time_checker/src/processing_time_checker.cpp

View check run for this annotation

Codecov / codecov/patch

system/autoware_processing_time_checker/src/processing_time_checker.cpp#L142-L143

Added lines #L142 - L143 were not covered by tests
} else {
RCLCPP_ERROR(this->get_logger(), "Failed to open file: %s", output_file_str.c_str());

Check warning on line 145 in system/autoware_processing_time_checker/src/processing_time_checker.cpp

View check run for this annotation

Codecov / codecov/patch

system/autoware_processing_time_checker/src/processing_time_checker.cpp#L145

Added line #L145 was not covered by tests
}
} catch (const std::exception & e) {
std::cerr << "Exception in ProcessingTimeChecker: " << e.what() << std::endl;
} catch (...) {

Check warning on line 149 in system/autoware_processing_time_checker/src/processing_time_checker.cpp

View check run for this annotation

Codecov / codecov/patch

system/autoware_processing_time_checker/src/processing_time_checker.cpp#L147-L149

Added lines #L147 - L149 were not covered by tests
std::cerr << "Unknown exception in ProcessingTimeChecker" << std::endl;
}
}

Expand Down
Loading