Skip to content

Commit

Permalink
fix(system_usage_monitor): change the node search method (#137)
Browse files Browse the repository at this point in the history
* Fixed the node search method

Signed-off-by: Shintaro Sakoda <[email protected]>

* Added a comment

Signed-off-by: Shintaro Sakoda <[email protected]>

---------

Signed-off-by: Shintaro Sakoda <[email protected]>
  • Loading branch information
SakodaShintaro authored Oct 23, 2024
1 parent 7eb78cf commit af16f8c
Showing 1 changed file with 27 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,32 @@ def get_system_usage(pid, system_usages, interval):
)
if component == "":
component = "others"
container = process_name.split("__node:=", 1)[1].split(" ")[0]
system_usages[pid] = {
"component": component,
"container": container,
"cpu_usage": cpu_usage,
"memory_usage": memory_usage,
}

elements = process_name.split("__node:=", 1)

# If `process_name`` can be split by "__node:=", get the container name from the second element.
# Otherwise, get the container name from the file name in the first element.
# An example of `process_name` is as follows:
# `/path/to/autoware/install/topic_state_monitor/lib/topic_state_monitor/topic_state_monitor_node
# --ros-args -r __node:=topic_state_monitor_scenario_planning_trajectory -r __ns:=/system ...`
if len(elements) < 2:
container = process_name.split(" ")[0].split("/")[-1]
if container.startswith("autoware_"):
container = container.split("_", 1)[1]
system_usages[pid] = {
"component": component,
"container": container,
"cpu_usage": cpu_usage,
"memory_usage": memory_usage,
}
else:
container = elements[1].split(" ")[0]
system_usages[pid] = {
"component": component,
"container": container,
"cpu_usage": cpu_usage,
"memory_usage": memory_usage,
}
except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess, IndexError):
pass

Expand Down Expand Up @@ -128,7 +147,7 @@ def main(args=None):
system_usages = {}
while True:
# create thread to calculate cpu usage of each process since it takes time
process_name_keyword = "__node:="
process_name_keyword = "--ros-args"
threads = []
for proc in psutil.process_iter(["pid", "name", "cpu_percent", "cmdline"]):
try:
Expand Down

0 comments on commit af16f8c

Please sign in to comment.