Skip to content

Commit

Permalink
Do not report memory utilization as zero for missing PID.
Browse files Browse the repository at this point in the history
  • Loading branch information
gladkova authored and alexgl-github committed Apr 1, 2020
1 parent 4d45a1c commit 70e8f1f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
3 changes: 2 additions & 1 deletion ci/buildspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ phases:
- pip install twine
- pip install pytest-mock -U
- pip install requests
- pip install -U -e .[mxnet]
- pip install -U -e .
- pip install mxnet==1.5.0
- cd model-archiver/ && pip install -U -e . && cd ../

build:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,14 @@ public void run() {
if (tokens.length != 2) {
continue;
}

Integer pid = Integer.valueOf(tokens[0]);
WorkerThread worker = workerMap.get(pid);
worker.setMemory(Long.parseLong(tokens[1]));
try {
Integer pid = Integer.valueOf(tokens[0]);
WorkerThread worker = workerMap.get(pid);
worker.setMemory(Long.parseLong(tokens[1]));
} catch (NumberFormatException e) {
logger.warn("Failed to parse memory utilization metrics: " + line);
continue;
}
}
}
} catch (IOException e) {
Expand Down
10 changes: 7 additions & 3 deletions mms/metrics/process_memory_metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import psutil


def get_cpu_usage(pid):
"""
use psutil for cpu memory
Expand All @@ -27,10 +26,13 @@ def get_cpu_usage(pid):
try:
process = psutil.Process(int(pid))
except psutil.Error:
logging.error("Failed get process for pid: %s", pid, exc_info=True)
logging.error("Failed to get process for pid: %s", pid, exc_info=True)
return 0

mem_utilization = process.memory_info()[0]
if mem_utilization == 0:
logging.error("Failed to get memory utilization for pid: %s", pid, exc_info=True)
return 0
return mem_utilization


Expand All @@ -45,4 +47,6 @@ def check_process_mem_usage(stdin):
for process in process_list:
if not process:
continue
logging.info("%s:%d", process, get_cpu_usage(process))
mem_utilization = get_cpu_usage(process)
if mem_utilization != 0:
logging.info("%s:%d", process, mem_utilization)

0 comments on commit 70e8f1f

Please sign in to comment.