feat(ingest): track thread count in ingestion report (#9566)

This commit is contained in:
Harshal Sheth 2024-01-04 16:36:09 -05:00 committed by GitHub
parent 20b7dd3642
commit 2268c0c5b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 1 deletions

View File

@ -5,6 +5,7 @@ import os
import platform
import shutil
import sys
import threading
import time
from dataclasses import dataclass
from typing import Any, Dict, Iterable, Iterator, List, Optional, cast
@ -129,9 +130,18 @@ class CliReport(Report):
py_version: str = sys.version
py_exec_path: str = sys.executable
os_details: str = platform.platform()
mem_info: Optional[str] = None
peak_memory_usage: Optional[str] = None
_peak_memory_usage: int = 0
disk_info: Optional[dict] = None
peak_disk_usage: Optional[str] = None
_peak_disk_usage: int = 0
thread_count: Optional[int] = None
peak_thread_count: Optional[int] = None
def compute_stats(self) -> None:
try:
mem_usage = psutil.Process(os.getpid()).memory_info().rss
@ -141,7 +151,10 @@ class CliReport(Report):
self._peak_memory_usage
)
self.mem_info = humanfriendly.format_size(mem_usage)
except Exception as e:
logger.warning(f"Failed to compute memory usage: {e}")
try:
disk_usage = shutil.disk_usage("/")
if self._peak_disk_usage < disk_usage.used:
self._peak_disk_usage = disk_usage.used
@ -152,7 +165,13 @@ class CliReport(Report):
"free": humanfriendly.format_size(disk_usage.free),
}
except Exception as e:
logger.warning(f"Failed to compute report memory usage: {e}")
logger.warning(f"Failed to compute disk usage: {e}")
try:
self.thread_count = threading.active_count()
self.peak_thread_count = max(self.peak_thread_count or 0, self.thread_count)
except Exception as e:
logger.warning(f"Failed to compute thread count: {e}")
return super().compute_stats()

View File

@ -4,6 +4,7 @@
# 3) Entity timeseries stat by user
import concurrent
import concurrent.futures
import dataclasses
import datetime
import logging