Miscellaneous Modules

Supporting modules are grouped here to keep the main navigation focused on the top-level workflows.

Validation

Module for validating an existing input file

validate(config_file_path: str, ui: IUI = NullUI()) bool

Main function to validate config file

Return type:

bool

Returns:

Outcome value :

True if config is valid False if config is invalid or file not exists

Parameters:
  • config_file_path (str)

  • ui (IUI)

Laboratory Assistant

Class that manages and provides toolchains, sysroots and platforms

class LaboratoryAssistant

Bases: object

Manager of toolchains, sysroots and platforms in Amphimixis global config

CONFIG_DIR_PATH = '/home/zst/.config/amphimixis'
TOOLBOX_PATH = '/home/zst/.config/amphimixis/toolbox.yml'
static parse_config_file() dict

Search ~/.config/amphimixis/toolbox.yml and parse or create it

Return type:

dict

Returns:

Toolbox content from Amphimixis global config

static find_platform(platform_name: str) MachineInfo | None

Find platform in Amphimixis global config (toolbox) by name

Parameters:

platform_name (str) – Name of platform

Return type:

MachineInfo | None

Returns:

info about machine if found else None

static find_platform_by_address(address: str) str

Find platform in Amphimixis global config (toolbox) by address

Parameters:

address (str) – Address of platform in network

Return type:

str

Returns:

platform name if platform exists else empty string

static add_platform(name: str, machine: MachineInfo) bool

Add platform to Amphimixis global config (toolbox)

Parameters:
  • name (str) – Name of platform

  • machine (MachineInfo) – Information about machine to write to global config

Return type:

bool

Returns:

True if platform successfully added to global config

static delete_platform(name: str) None

Delete platform from Amphimixis global config by name

Parameters:

name (str) – Name of platform

Return type:

None

static find_toolchain_by_name(name: str) Toolchain | None

Find toolchain by name in global config

Parameters:

name (str) – name of toolchain in global config

Return type:

Toolchain | None

Returns:

Toolchain constructed from Amphimixis global config found by name

if not found then return None

static add_toolchain(toolchain: Toolchain, machine: MachineInfo | str, target_arch: Arch) bool

Add toolchain to Amphimixis global config (toolbox)

Parameters:
  • toolchain (Toolchain) – Toolchain to adding

  • machine (MachineInfo | str) – Platform that contains toolchain

  • target_arch (Arch) – The architecture for that the toolchain generates code

  • machine

Return type:

bool

Returns:

True if toolchain successfully added to global config

static delete_toolchain(name: str) None

Delete toolchain from Amphimixis global config by name

Parameters:

name (str) – Name of toolchain

Return type:

None

Shell

Shell module

class Shell(project: Project, machine: MachineInfo, ui: IUI = NullUI(), connect_timeout=10)

Bases: object

Shell class to manage shell operations.

bash is used as shell.

Parameters:
  • project (Project) – Project object.

  • machine (MachineInfo) – machine to run profiling at.

  • int (connect_timeout) – connection to machine timeout.

  • ui (IUI)

connect() Self

Connect to the shell of the machine.

Return type:

Self

run(*commands: str) Tuple[int, List[List[str]], List[List[str]]]

Run the commands through the shell.

  • Execute commands one by one until:

    non-zero return code occurs or OR all commands have been executed.

Parameters:

*commands (str) –

commands to be executed

Return type:

Tuple[int, List[List[str]], List[List[str]]]

Returns:

A tuple of three :

  • int:

    error code of the last executed command

  • List[List[str]]:

    List[str] is lines of the stdout of an executed command.

  • List[List[str]]:

    List[str] is lines of the stderr of an executed command.

copy_to_remote(source: str, destination: str) bool

Send a file or folder to the target machine.

Absolute paths are needed.

Parameters:
  • source (str) – absolute path to a file or folder on the host machine

  • destination (str) – absolute path to copy a file or folder to on the controlled machine

Returns:

True if successfully copied else False

Return type:

bool

copy_to_host(source: str, destination: str) bool

Gets a file or folder from the target machine.

Absolute paths are needed.

Parameters:
  • source (str) – absolute path to a file or folder on the controlled machine

  • destination (str) – absolute path to copy a file or folder to on the host machine

Returns:

True if successfully copied else False

Return type:

bool

get_project_workdir() str

Gets a working directory for amphimixis.

Return type:

str

Returns:

In case of remote machine: expanded ~/${AMPHIMIXIS_DIRECTORY_NAME}/${PROJECT_NAME}_builds.

In case of local machine: python process current working directory.

get_home() str

Gets a home directory for current connection (user@machine).

Return type:

str

Returns:

Expanded ~ for the current connection (user@machine).

get_source_dir() str

Gets a directory for the project source code on the target machine.

Return type:

str

Returns:

In case of remote machine: expanded

~/${AMPHIMIXIS_DIRECTORY_NAME}/${PROJECT_NAME}.

In case of local machine: project path.

set_paranoid(level: int) tuple[int, bool]

Sets perf_event_paranoid to the given level.

Parameters:

level (int) – The level to set perf_event_paranoid to. Should be an integer between -1 and 3.

Returns:

A tuple of two elements:

  • int: The current level of perf_event_paranoid.

  • bool: True if the level was set successfully, False otherwise.

Return type:

tuple[int, bool]

Logger

Module to operate logging

setup_logger(name: str) Logger

Function to create logger with specified name

Parameters:

name (str)

Return type:

Logger

Build Systems

Module containing dictionary of build systems and implementations of build systems

class CMake(project: Project, runner: ILowLevelBuildSystem = DummyRunner(), ui: IUI = NullUI())

Bases: BuildSystem, IHighLevelBuildSystem

Implementation of working with CMake build system

Parameters:
build(build: Build) tuple[int, str, str]

Configure and build via CMake

Parameters:

build (Build) – Build to build

Return type:

tuple[int, str, str]

Returns:

Tuple of error_code, stdout, stderr

class Make(project: Project, runner: ILowLevelBuildSystem = DummyRunner(), ui: IUI = NullUI())

Bases: BuildSystem, IHighLevelBuildSystem, ILowLevelBuildSystem

Implementation of working with Make build system

Parameters:
build(build: Build) tuple[int, str, str]

Build via Make

Parameters:

build (Build) – Build to build

Return type:

tuple[int, str, str]

Returns:

Tuple of error_code, stdout, stderr

run_building(build: Build) tuple[int, str, str]

Run building via Make

Parameters:

build (Build) – Build to run building

Returns:

Tuple of error code, stdout and stderr

Return type:

tuple[int, str, str]

class Ninja(project: Project, runner: ILowLevelBuildSystem = DummyRunner(), ui: IUI = NullUI())

Bases: BuildSystem, ILowLevelBuildSystem

Implementation of working with Ninja build system

Parameters:
run_building(build: Build) tuple[int, str, str]

Run ninja in the build directory.

Parameters:

build (Build) – Build configuration

Return type:

tuple[int, str, str]

Returns:

Tuple of error_code, stdout, stderr

Performance Analyzer

Compare two perf output files.

class LLMAnalyzer(api_key=None, base_url=None, model_name=None, project=None)

Bases: object

An OpenAI API wrapper

ask(system_prompt, user_prompt, temperature=0.2)

Send a prompt to the LLM and return the response.

print_comparison_table(event_name, data_a, data_b, max_rows, build_a='Build A', build_b='Build B')

Prints statistics comparison for a specific event.

analyze_with_llm(table, samples_a, samples_b)

Analyzes performance data using a Large Language Model (LLM) and saves the output to a file.

main(filename1, filename2, target_events: None | list[str] = None, max_rows=20, use_llm=False) int

Compares two perf output files and prints the top max_rows symbols with the most significant changes for specified events.

Parameters:
  • filename1 (str) – path to baseline build perfdata.scriptout

  • filename2 (str) – path to another build perfdata.scriptout

  • target_events (list[str]) – list of events to compare

  • max_rows (int) – maximum symbols to print per event

  • use_llm (bool) – use LLM

Return type:

int