提交 dccdcb4b 编写于 作者: A Aaron Xiao 提交者: Dong Li

Common: Export runtime flag values for data collection purpose. (#1160)

上级 c386e141
......@@ -18,14 +18,18 @@
#include <csignal>
#include <string>
#include <vector>
#include "gflags/gflags.h"
#include "modules/common/log.h"
#include "modules/common/status/status.h"
#include "modules/common/util/string_util.h"
#include "modules/hmi/utils/hmi_status_helper.h"
#include "ros/include/ros/ros.h"
DECLARE_string(log_dir);
namespace apollo {
namespace common {
......@@ -41,6 +45,21 @@ void ApolloApp::ReportModuleStatus(
hmi::HMIStatusHelper::ReportModuleStatus(status_);
}
void ApolloApp::ExportFlags() const {
const auto export_file = util::StrCat(FLAGS_log_dir, "/", Name(), ".flags");
std::ofstream fout(export_file);
CHECK(fout) << "Cannot open file " << export_file;
std::vector<gflags::CommandLineFlagInfo> flags;
gflags::GetAllFlags(&flags);
for (const auto &flag : flags) {
fout << "# " << flag.type << ", default=" << flag.default_value << "\n"
<< "# " << flag.description << "\n"
<< "--" << flag.name << "=" << flag.current_value << "\n"
<< std::endl;
}
}
int ApolloApp::Spin() {
ros::AsyncSpinner spinner(callback_thread_num_);
auto status = Init();
......@@ -56,6 +75,7 @@ int ApolloApp::Spin() {
ReportModuleStatus(apollo::hmi::ModuleStatus::STOPPED);
return -2;
}
ExportFlags();
ReportModuleStatus(apollo::hmi::ModuleStatus::STARTED);
spinner.start();
ros::waitForShutdown();
......
......@@ -110,6 +110,12 @@ class ApolloApp {
/** The callback thread number
*/
uint32_t callback_thread_num_ = 1;
private:
/**
* @brief Export flag values to <FLAGS_log_dir>/<name>.flags.
*/
void ExportFlags() const;
};
void apollo_app_sigint_handler(int signal_num);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册