Coverage for procpath/utility.py: 100%
31 statements
« prev ^ index » next coverage.py v6.5.0, created at 2025-04-05 18:56 +0000
« prev ^ index » next coverage.py v6.5.0, created at 2025-04-05 18:56 +0000
1import json
2import logging
3import os.path
4import platform
5import resource
6import subprocess
7from typing import Dict, List, Tuple
9from . import __version__
12__all__ = 'evaluate', 'get_meta'
14logger = logging.getLogger(__package__)
17def evaluate(var_cmd_list: List[Tuple[str, str]]) -> Dict[str, str]:
18 """Evaluate given 2-tuple named list of shell commands."""
20 script = [] (empty)procpath.test.cmd.TestPlayCommand.test_play_queryprocpath.test.cmd.TestPlayCommand.test_play_watchprocpath.test.cmd.TestPlayCommand.test_play_watch_overrideprocpath.test.cmd.TestQueryCommand.test_query_with_envrionmentprocpath.test.cmd.TestRecordCommand.test_record_environmentprocpath.test.cmd.TestRecordCommand.test_record_environment_database_fileprocpath.test.cmd.TestRecordCommand.test_record_pid_list_onlyprocpath.test.cmd.TestWatchCommand.test_watch_empty_env_command_resultprocpath.test.cmd.TestWatchCommand.test_watch_no_restart_no_reevalprocpath.test.unit.TestUtility.test_evaluate
21 var_set = set() (empty)procpath.test.cmd.TestPlayCommand.test_play_queryprocpath.test.cmd.TestPlayCommand.test_play_watchprocpath.test.cmd.TestPlayCommand.test_play_watch_overrideprocpath.test.cmd.TestQueryCommand.test_query_with_envrionmentprocpath.test.cmd.TestRecordCommand.test_record_environmentprocpath.test.cmd.TestRecordCommand.test_record_environment_database_fileprocpath.test.cmd.TestRecordCommand.test_record_pid_list_onlyprocpath.test.cmd.TestWatchCommand.test_watch_empty_env_command_resultprocpath.test.cmd.TestWatchCommand.test_watch_no_restart_no_reevalprocpath.test.unit.TestUtility.test_evaluate
22 for var_name, command in var_cmd_list: (empty)procpath.test.cmd.TestPlayCommand.test_play_queryprocpath.test.cmd.TestPlayCommand.test_play_watchprocpath.test.cmd.TestPlayCommand.test_play_watch_overrideprocpath.test.cmd.TestQueryCommand.test_query_with_envrionmentprocpath.test.cmd.TestRecordCommand.test_record_environmentprocpath.test.cmd.TestRecordCommand.test_record_environment_database_fileprocpath.test.cmd.TestRecordCommand.test_record_pid_list_onlyprocpath.test.cmd.TestWatchCommand.test_watch_empty_env_command_resultprocpath.test.cmd.TestWatchCommand.test_watch_no_restart_no_reevalprocpath.test.unit.TestUtility.test_evaluate
23 var_set.add(var_name) (empty)procpath.test.cmd.TestPlayCommand.test_play_queryprocpath.test.cmd.TestPlayCommand.test_play_watchprocpath.test.cmd.TestPlayCommand.test_play_watch_overrideprocpath.test.cmd.TestQueryCommand.test_query_with_envrionmentprocpath.test.cmd.TestRecordCommand.test_record_environmentprocpath.test.cmd.TestRecordCommand.test_record_environment_database_fileprocpath.test.cmd.TestRecordCommand.test_record_pid_list_onlyprocpath.test.cmd.TestWatchCommand.test_watch_empty_env_command_resultprocpath.test.cmd.TestWatchCommand.test_watch_no_restart_no_reevalprocpath.test.unit.TestUtility.test_evaluate
24 script.append(f'{var_name}=$({command})') (empty)procpath.test.cmd.TestPlayCommand.test_play_queryprocpath.test.cmd.TestPlayCommand.test_play_watchprocpath.test.cmd.TestPlayCommand.test_play_watch_overrideprocpath.test.cmd.TestQueryCommand.test_query_with_envrionmentprocpath.test.cmd.TestRecordCommand.test_record_environmentprocpath.test.cmd.TestRecordCommand.test_record_environment_database_fileprocpath.test.cmd.TestRecordCommand.test_record_pid_list_onlyprocpath.test.cmd.TestWatchCommand.test_watch_empty_env_command_resultprocpath.test.cmd.TestWatchCommand.test_watch_no_restart_no_reevalprocpath.test.unit.TestUtility.test_evaluate
25 script.append(f'export {var_name}') (empty)procpath.test.cmd.TestPlayCommand.test_play_queryprocpath.test.cmd.TestPlayCommand.test_play_watchprocpath.test.cmd.TestPlayCommand.test_play_watch_overrideprocpath.test.cmd.TestQueryCommand.test_query_with_envrionmentprocpath.test.cmd.TestRecordCommand.test_record_environmentprocpath.test.cmd.TestRecordCommand.test_record_environment_database_fileprocpath.test.cmd.TestRecordCommand.test_record_pid_list_onlyprocpath.test.cmd.TestWatchCommand.test_watch_empty_env_command_resultprocpath.test.cmd.TestWatchCommand.test_watch_no_restart_no_reevalprocpath.test.unit.TestUtility.test_evaluate
27 script.append('env') (empty)procpath.test.cmd.TestPlayCommand.test_play_queryprocpath.test.cmd.TestPlayCommand.test_play_watchprocpath.test.cmd.TestPlayCommand.test_play_watch_overrideprocpath.test.cmd.TestQueryCommand.test_query_with_envrionmentprocpath.test.cmd.TestRecordCommand.test_record_environmentprocpath.test.cmd.TestRecordCommand.test_record_environment_database_fileprocpath.test.cmd.TestRecordCommand.test_record_pid_list_onlyprocpath.test.cmd.TestWatchCommand.test_watch_empty_env_command_resultprocpath.test.cmd.TestWatchCommand.test_watch_no_restart_no_reevalprocpath.test.unit.TestUtility.test_evaluate
28 env = subprocess.check_output('\n'.join(script), shell=True, encoding='utf-8') (empty)procpath.test.cmd.TestPlayCommand.test_play_queryprocpath.test.cmd.TestPlayCommand.test_play_watchprocpath.test.cmd.TestPlayCommand.test_play_watch_overrideprocpath.test.cmd.TestQueryCommand.test_query_with_envrionmentprocpath.test.cmd.TestRecordCommand.test_record_environmentprocpath.test.cmd.TestRecordCommand.test_record_environment_database_fileprocpath.test.cmd.TestRecordCommand.test_record_pid_list_onlyprocpath.test.cmd.TestWatchCommand.test_watch_empty_env_command_resultprocpath.test.cmd.TestWatchCommand.test_watch_no_restart_no_reevalprocpath.test.unit.TestUtility.test_evaluate
30 result = {} (empty)procpath.test.cmd.TestPlayCommand.test_play_queryprocpath.test.cmd.TestPlayCommand.test_play_watchprocpath.test.cmd.TestPlayCommand.test_play_watch_overrideprocpath.test.cmd.TestQueryCommand.test_query_with_envrionmentprocpath.test.cmd.TestRecordCommand.test_record_environmentprocpath.test.cmd.TestRecordCommand.test_record_environment_database_fileprocpath.test.cmd.TestRecordCommand.test_record_pid_list_onlyprocpath.test.cmd.TestWatchCommand.test_watch_empty_env_command_resultprocpath.test.cmd.TestWatchCommand.test_watch_no_restart_no_reevalprocpath.test.unit.TestUtility.test_evaluate
31 for line in env.splitlines(): (empty)procpath.test.cmd.TestPlayCommand.test_play_queryprocpath.test.cmd.TestPlayCommand.test_play_watchprocpath.test.cmd.TestPlayCommand.test_play_watch_overrideprocpath.test.cmd.TestQueryCommand.test_query_with_envrionmentprocpath.test.cmd.TestRecordCommand.test_record_environmentprocpath.test.cmd.TestRecordCommand.test_record_environment_database_fileprocpath.test.cmd.TestRecordCommand.test_record_pid_list_onlyprocpath.test.cmd.TestWatchCommand.test_watch_empty_env_command_resultprocpath.test.cmd.TestWatchCommand.test_watch_no_restart_no_reevalprocpath.test.unit.TestUtility.test_evaluate
32 k, v = line.split('=', 1) (empty)procpath.test.cmd.TestPlayCommand.test_play_queryprocpath.test.cmd.TestPlayCommand.test_play_watchprocpath.test.cmd.TestPlayCommand.test_play_watch_overrideprocpath.test.cmd.TestQueryCommand.test_query_with_envrionmentprocpath.test.cmd.TestRecordCommand.test_record_environmentprocpath.test.cmd.TestRecordCommand.test_record_environment_database_fileprocpath.test.cmd.TestRecordCommand.test_record_pid_list_onlyprocpath.test.cmd.TestWatchCommand.test_watch_empty_env_command_resultprocpath.test.cmd.TestWatchCommand.test_watch_no_restart_no_reevalprocpath.test.unit.TestUtility.test_evaluate
33 if k in var_set: (empty)procpath.test.cmd.TestPlayCommand.test_play_queryprocpath.test.cmd.TestPlayCommand.test_play_watchprocpath.test.cmd.TestPlayCommand.test_play_watch_overrideprocpath.test.cmd.TestQueryCommand.test_query_with_envrionmentprocpath.test.cmd.TestRecordCommand.test_record_environmentprocpath.test.cmd.TestRecordCommand.test_record_environment_database_fileprocpath.test.cmd.TestRecordCommand.test_record_pid_list_onlyprocpath.test.cmd.TestWatchCommand.test_watch_empty_env_command_resultprocpath.test.cmd.TestWatchCommand.test_watch_no_restart_no_reevalprocpath.test.unit.TestUtility.test_evaluate
34 result[k] = v (empty)procpath.test.cmd.TestPlayCommand.test_play_queryprocpath.test.cmd.TestPlayCommand.test_play_watchprocpath.test.cmd.TestPlayCommand.test_play_watch_overrideprocpath.test.cmd.TestQueryCommand.test_query_with_envrionmentprocpath.test.cmd.TestRecordCommand.test_record_environmentprocpath.test.cmd.TestRecordCommand.test_record_environment_database_fileprocpath.test.cmd.TestRecordCommand.test_record_pid_list_onlyprocpath.test.cmd.TestWatchCommand.test_watch_empty_env_command_resultprocpath.test.cmd.TestWatchCommand.test_watch_no_restart_no_reevalprocpath.test.unit.TestUtility.test_evaluate
35 if not v: (empty)procpath.test.cmd.TestPlayCommand.test_play_queryprocpath.test.cmd.TestPlayCommand.test_play_watchprocpath.test.cmd.TestPlayCommand.test_play_watch_overrideprocpath.test.cmd.TestQueryCommand.test_query_with_envrionmentprocpath.test.cmd.TestRecordCommand.test_record_environmentprocpath.test.cmd.TestRecordCommand.test_record_environment_database_fileprocpath.test.cmd.TestRecordCommand.test_record_pid_list_onlyprocpath.test.cmd.TestWatchCommand.test_watch_empty_env_command_resultprocpath.test.cmd.TestWatchCommand.test_watch_no_restart_no_reevalprocpath.test.unit.TestUtility.test_evaluate
36 logger.warning('Variable %s evaluated empty', k) (empty)procpath.test.cmd.TestWatchCommand.test_watch_empty_env_command_result
37 if len(result) == len(var_set): (empty)procpath.test.cmd.TestPlayCommand.test_play_queryprocpath.test.cmd.TestPlayCommand.test_play_watchprocpath.test.cmd.TestPlayCommand.test_play_watch_overrideprocpath.test.cmd.TestQueryCommand.test_query_with_envrionmentprocpath.test.cmd.TestRecordCommand.test_record_environmentprocpath.test.cmd.TestRecordCommand.test_record_environment_database_fileprocpath.test.cmd.TestRecordCommand.test_record_pid_list_onlyprocpath.test.cmd.TestWatchCommand.test_watch_empty_env_command_resultprocpath.test.cmd.TestWatchCommand.test_watch_no_restart_no_reevalprocpath.test.unit.TestUtility.test_evaluate
38 break (empty)procpath.test.cmd.TestPlayCommand.test_play_queryprocpath.test.cmd.TestPlayCommand.test_play_watchprocpath.test.cmd.TestPlayCommand.test_play_watch_overrideprocpath.test.cmd.TestQueryCommand.test_query_with_envrionmentprocpath.test.cmd.TestRecordCommand.test_record_environmentprocpath.test.cmd.TestRecordCommand.test_record_environment_database_fileprocpath.test.cmd.TestRecordCommand.test_record_pid_list_onlyprocpath.test.cmd.TestWatchCommand.test_watch_empty_env_command_resultprocpath.test.cmd.TestWatchCommand.test_watch_no_restart_no_reevalprocpath.test.unit.TestUtility.test_evaluate
40 return result (empty)procpath.test.cmd.TestPlayCommand.test_play_queryprocpath.test.cmd.TestPlayCommand.test_play_watchprocpath.test.cmd.TestPlayCommand.test_play_watch_overrideprocpath.test.cmd.TestQueryCommand.test_query_with_envrionmentprocpath.test.cmd.TestRecordCommand.test_record_environmentprocpath.test.cmd.TestRecordCommand.test_record_environment_database_fileprocpath.test.cmd.TestRecordCommand.test_record_pid_list_onlyprocpath.test.cmd.TestWatchCommand.test_watch_empty_env_command_resultprocpath.test.cmd.TestWatchCommand.test_watch_no_restart_no_reevalprocpath.test.unit.TestUtility.test_evaluate
43def get_meta(procfile_list: List[str], procfs: str, procfs_target: str) -> Dict[str, object]:
44 """Get machine and recording metadata."""
46 return { (empty)procpath.test.cmd.TestPlayCommand.test_play_queryprocpath.test.cmd.TestPlayCommand.test_play_record_plotprocpath.test.cmd.TestQueryCommand.test_query_only_sqlprocpath.test.cmd.TestQueryCommand.test_query_sql_syntax_errorprocpath.test.cmd.TestQueryCommand.test_query_with_envrionmentprocpath.test.cmd.TestQueryCommand.test_query_with_sqlprocpath.test.cmd.TestRecordCommand.test_record_allprocpath.test.cmd.TestRecordCommand.test_record_environmentprocpath.test.cmd.TestRecordCommand.test_record_environment_database_fileprocpath.test.cmd.TestRecordCommand.test_record_n_timesprocpath.test.cmd.TestRecordCommand.test_record_pid_listprocpath.test.cmd.TestRecordCommand.test_record_pid_list_onlyprocpath.test.cmd.TestRecordCommand.test_record_queryprocpath.test.cmd.TestRecordCommand.test_record_syntax_errorprocpath.test.unit.TestProcrecSqliteStorage.test_create_schema_allprocpath.test.unit.TestProcret.test_query_procfile_requiredprocpath.test.unit.TestProcret.test_query_procfile_required_missingprocpath.test.unit.TestProcret.test_query_procfile_required_missing_old_dbprocpath.test.unit.TestProcret.test_rss_filter_pid_short_and_longprocpath.test.unit.TestSqlitevizQuery.test_total_cpu_usageprocpath.test.unit.TestSqlitevizQuery.test_total_memory_consumptionprocpath.test.unit.TestUtility.test_get_meta
47 'platform_node': platform.node(),
48 'platform_platform': platform.platform(),
49 'page_size': resource.getpagesize(),
50 'clock_ticks': os.sysconf('SC_CLK_TCK'),
51 'physical_pages': os.sysconf('SC_PHYS_PAGES'),
52 'cpu_count': os.cpu_count(),
53 'procfile_list': json.dumps(procfile_list),
54 'procpath_version': __version__,
55 'procfs_path': os.path.abspath(procfs),
56 'procfs_target': procfs_target,
57 }