[~] Refactor
This commit is contained in:
parent
40350d128a
commit
14b499637b
@ -23,7 +23,7 @@ import tempfile
|
||||
import time
|
||||
import traceback
|
||||
|
||||
from typing import (Literal, Optional, TypedDict, Callable, Generator, TypeAlias,)
|
||||
from typing import (Literal, Optional, TypedDict, Callable, Generator, TypeAlias, Any,)
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@ -258,8 +258,8 @@ def memory_stats() -> memory_stats_t.res_t:
|
||||
raise NotImplementedError
|
||||
|
||||
def chrome(
|
||||
argv
|
||||
):
|
||||
argv: list[str]
|
||||
) -> int:
|
||||
assert isinstance(argv, list) and all([isinstance(o, str) for o in argv])
|
||||
parser = optparse.OptionParser()
|
||||
parser.add_option(
|
||||
@ -281,7 +281,7 @@ def chrome(
|
||||
#assert os.path.exists(options.user_data_dir)
|
||||
|
||||
if sys.platform == 'linux':
|
||||
subprocess.check_call([
|
||||
return subprocess.check_call([
|
||||
'google-chrome-stable',
|
||||
'--enable-features=useOzonePlatform',
|
||||
'--ozone-platform=wayland',
|
||||
@ -292,7 +292,7 @@ def chrome(
|
||||
else:
|
||||
raise NotImplementedError
|
||||
|
||||
def eternal_oom(argv):
|
||||
def eternal_oom(argv: list[str]) -> None:
|
||||
import signal
|
||||
import re
|
||||
import time
|
||||
@ -412,12 +412,15 @@ def eternal_oom(argv):
|
||||
)
|
||||
return
|
||||
|
||||
cpu_count = os.cpu_count()
|
||||
assert isinstance(cpu_count, int)
|
||||
|
||||
if options.period is None:
|
||||
options.period = 1
|
||||
if options.memory_limit is None:
|
||||
options.memory_limit = 3 * 1024 * 1024
|
||||
if options.cpu_limit is None:
|
||||
options.cpu_limit = 0.6 * os.cpu_count()
|
||||
options.cpu_limit = 0.6 * cpu_count
|
||||
if options.cpu_wait is None:
|
||||
options.cpu_wait = 10
|
||||
if options.mean_size is None:
|
||||
@ -431,24 +434,40 @@ def eternal_oom(argv):
|
||||
and options.memory_limit > 512 * 1024
|
||||
|
||||
assert isinstance(options.cpu_limit, float) \
|
||||
and options.cpu_limit > 0.2 * os.cpu_count() and \
|
||||
options.cpu_limit < os.cpu_count() * 0.95
|
||||
and options.cpu_limit > 0.2 * cpu_count and \
|
||||
options.cpu_limit < cpu_count * 0.95
|
||||
|
||||
assert options.period >= 1
|
||||
|
||||
assert options.cpu_wait >= 10
|
||||
assert options.mean_size >= 16
|
||||
|
||||
def pandas_data_frame(lines, groups_regex, header_regex, extra_columns):
|
||||
header = re.compile(header_regex).search(lines[0]).groups()
|
||||
rows = [
|
||||
re.compile(groups_regex).search(row).groups()
|
||||
for row in lines[1:]
|
||||
]
|
||||
columns = {
|
||||
def pandas_data_frame(
|
||||
lines: list[str],
|
||||
groups_regex: re.Pattern[str],
|
||||
header_regex: re.Pattern[str],
|
||||
extra_columns: dict[
|
||||
str,
|
||||
Callable[
|
||||
[dict[str, str]],
|
||||
Any
|
||||
]
|
||||
],
|
||||
) -> dict[str, list[Any]]:
|
||||
header_match = re.compile(header_regex).search(lines[0])
|
||||
assert not header_match is None
|
||||
header = header_match.groups()
|
||||
rows = []
|
||||
for line in lines[1:]:
|
||||
row_match = re.compile(groups_regex).search(line)
|
||||
assert not row_match is None
|
||||
rows.append(row_match.groups())
|
||||
|
||||
columns: dict[str, list[Any]] = {
|
||||
column: []
|
||||
for column in header
|
||||
}
|
||||
|
||||
for row in rows:
|
||||
for value, column in zip(row, header):
|
||||
columns[column].append(value)
|
||||
|
Loading…
Reference in New Issue
Block a user