40 {
41
42 std::vector<std::string> running_processes;
43 for (
const auto& cmd_file : cyber::common::
Glob(
"/proc/*/cmdline")) {
44
45 std::string cmd_string;
47 !cmd_string.empty()) {
48
49
50 std::replace(cmd_string.begin(), cmd_string.end(), '\0', ' ');
51 running_processes.push_back(cmd_string);
52 }
53 }
54
55 auto manager = MonitorManager::Instance();
56 const auto& mode = manager->GetHMIMode();
57
58
59 auto* hmi_modules = manager->GetStatus()->mutable_hmi_modules();
60 for (
const auto& iter : mode.
modules()) {
61 const std::string& module_name = iter.first;
62 const auto& config = iter.second.process_monitor_config();
63 UpdateStatus(running_processes, config, &hmi_modules->at(module_name));
64 }
65
66
67 auto* components = manager->GetStatus()->mutable_components();
68 for (const auto& iter : mode.monitored_components()) {
69 const std::string& name = iter.first;
70 if (iter.second.has_process() &&
71 apollo::common::util::ContainsKey(*components, name)) {
72 const auto& config = iter.second.process();
73 auto* status = components->at(name).mutable_process_status();
74 UpdateStatus(running_processes, config, status);
75 }
76 }
77
78
79 auto* other_components = manager->GetStatus()->mutable_other_components();
80 for (const auto& iter : mode.other_components()) {
81 const std::string& name = iter.first;
82 const auto& config = iter.second;
83 UpdateStatus(running_processes, config, &other_components->at(name));
84 }
85
86
87 auto* global_components = manager->GetStatus()->mutable_global_components();
88 for (const auto& iter : mode.global_components()) {
89 const std::string& name = iter.first;
90 if (iter.second.has_process() &&
91 apollo::common::util::ContainsKey(*global_components, name)) {
92 const auto& config = iter.second.process();
93 auto* status = global_components->at(name).mutable_process_status();
94 UpdateStatus(running_processes, config, status);
95 }
96 }
97}
std::vector< std::string > Glob(const std::string &pattern)
Expand path pattern to matched paths.
bool GetContent(const std::string &file_name, std::string *content)
Get file content as string.