ACAV f0ba4b7c9529
Abstract Syntax Tree (AST) visualization tool for C, C++, and Objective-C
Loading...
Searching...
No Matches
acav::ParallelProcessRunner Class Referenceabstract

Generic parallel process runner for executing multiple instances of a program. More...

#include <ParallelProcessRunner.h>

Inheritance diagram for acav::ParallelProcessRunner:
[legend]

Signals

void error (const QString &errorMessage)
 Emitted when an error occurs that prevents execution.
void progress (const QString &message)
 Emitted with progress updates (e.g., "Completed 3/8 chunks").
void chunkCompleted (int chunkIndex, int totalChunks)
 Emitted when a single chunk completes successfully.
void chunkFailed (int chunkIndex, const QString &errorMessage)
 Emitted when a single chunk fails.
void logMessage (const LogEntry &entry)
 Emitted when a chunk process produces log output.

Public Member Functions

 ParallelProcessRunner (QObject *parent=nullptr)
bool isRunning () const
 Check if any process is currently running.
void setParallelCount (int count)
 Set number of parallel processes (0 = auto-detect from CPU cores).
int getParallelCount () const
 Get current parallel count setting.
void cancel ()
 Cancel all running processes.

Protected Member Functions

virtual std::vector< QStringList > chunkInputData (const QStringList &inputData, int chunkCount) const
 Divide input data into chunks for parallel processing.
virtual QStringList prepareProcessArguments (int chunkIndex, const QStringList &chunkData, const QString &tempOutputPath)=0
 Prepare command-line arguments for a specific chunk.
virtual bool mergeResults (const QStringList &tempOutputPaths, const QString &finalOutputPath, QString &errorMessage)=0
 Merge outputs from all chunks into final result.
virtual void onAllCompleted (int successCount, int failureCount, int totalCount)
 Called when all processes have completed (success or failure).
QString getTempOutputPath (int chunkIndex) const
 Get path to temporary output file for a chunk.
void runParallel (const QString &programPath, const QStringList &inputData, const QString &finalOutputPath)
 Start parallel execution.

Protected Attributes

QString finalOutputPath_
 Final output file path.
QStringList errorMessages_
 Aggregated error messages.
QTemporaryDir tempDir_
 Temporary directory for chunk outputs.
QElapsedTimer elapsed_

Detailed Description

Generic parallel process runner for executing multiple instances of a program.

This class provides a reusable framework for running multiple processes in parallel, managing their lifecycle, and aggregating results. It's designed to be extended for specific use cases (e.g., query-dependencies, make-ast, custom analyzers).

Key features:

  • Automatic chunking of input data
  • Process lifecycle management
  • Error aggregation
  • Progress tracking
  • Graceful degradation on partial failures

Usage pattern:

  1. Subclass ParallelProcessRunner
  2. Override virtual methods to customize behavior:
  3. Call run() with input data

Definition at line 61 of file ParallelProcessRunner.h.

Constructor & Destructor Documentation

◆ ParallelProcessRunner()

acav::ParallelProcessRunner::ParallelProcessRunner ( QObject * parent = nullptr)
explicit

Definition at line 33 of file ParallelProcessRunner.cpp.

◆ ~ParallelProcessRunner()

acav::ParallelProcessRunner::~ParallelProcessRunner ( )
override

Definition at line 37 of file ParallelProcessRunner.cpp.

Member Function Documentation

◆ cancel()

void acav::ParallelProcessRunner::cancel ( )

Cancel all running processes.

Definition at line 60 of file ParallelProcessRunner.cpp.

References cancel().

Referenced by cancel().

◆ chunkCompleted

void acav::ParallelProcessRunner::chunkCompleted ( int chunkIndex,
int totalChunks )
signal

Emitted when a single chunk completes successfully.

Parameters
chunkIndexIndex of the completed chunk
totalChunksTotal number of chunks

◆ chunkFailed

void acav::ParallelProcessRunner::chunkFailed ( int chunkIndex,
const QString & errorMessage )
signal

Emitted when a single chunk fails.

Parameters
chunkIndexIndex of the failed chunk
errorMessageError description

◆ chunkInputData()

std::vector< QStringList > acav::ParallelProcessRunner::chunkInputData ( const QStringList & inputData,
int chunkCount ) const
protectedvirtual

Divide input data into chunks for parallel processing.

Parameters
inputDataGeneric input data (e.g., list of files, list of tasks)
chunkCountNumber of chunks to create
Returns
Vector of chunks, each chunk is a list of input items

Default implementation: Round-robin distribution Override for custom chunking strategies (e.g., size-based, complexity-based)

Definition at line 69 of file ParallelProcessRunner.cpp.

References chunkInputData().

Referenced by chunkInputData(), and runParallel().

◆ getParallelCount()

int acav::ParallelProcessRunner::getParallelCount ( ) const
inline

Get current parallel count setting.

Definition at line 75 of file ParallelProcessRunner.h.

◆ getTempOutputPath()

QString acav::ParallelProcessRunner::getTempOutputPath ( int chunkIndex) const
protected

Get path to temporary output file for a chunk.

Parameters
chunkIndexIndex of the chunk
Returns
Full path to temporary file

Definition at line 170 of file ParallelProcessRunner.cpp.

References getTempOutputPath(), and tempDir_.

Referenced by getTempOutputPath(), and runParallel().

◆ isRunning()

bool acav::ParallelProcessRunner::isRunning ( ) const

Check if any process is currently running.

Definition at line 51 of file ParallelProcessRunner.cpp.

References isRunning().

Referenced by isRunning(), and runParallel().

◆ mergeResults()

virtual bool acav::ParallelProcessRunner::mergeResults ( const QStringList & tempOutputPaths,
const QString & finalOutputPath,
QString & errorMessage )
protectedpure virtual

Merge outputs from all chunks into final result.

Parameters
tempOutputPathsPaths to temporary output files (one per chunk)
finalOutputPathPath where merged result should be written
errorMessageOutput parameter for error details
Returns
true on success, false on failure

Must be implemented by subclasses to define result merging logic

Implemented in acav::QueryDependenciesParallelRunner.

Referenced by onAllCompleted().

◆ onAllCompleted()

void acav::ParallelProcessRunner::onAllCompleted ( int successCount,
int failureCount,
int totalCount )
protectedvirtual

Called when all processes have completed (success or failure).

Parameters
successCountNumber of chunks that completed successfully
failureCountNumber of chunks that failed
totalCountTotal number of chunks

Override to perform final processing, emit custom signals, etc. Default implementation: Calls mergeResults() if any chunks succeeded

Reimplemented in acav::QueryDependenciesParallelRunner.

Definition at line 290 of file ParallelProcessRunner.cpp.

References error(), finalOutputPath_, mergeResults(), onAllCompleted(), and progress().

Referenced by onAllCompleted(), and acav::QueryDependenciesParallelRunner::onAllCompleted().

◆ prepareProcessArguments()

virtual QStringList acav::ParallelProcessRunner::prepareProcessArguments ( int chunkIndex,
const QStringList & chunkData,
const QString & tempOutputPath )
protectedpure virtual

Prepare command-line arguments for a specific chunk.

Parameters
chunkIndexIndex of the chunk being processed
chunkDataData items in this chunk
tempOutputPathTemporary file path for this chunk's output
Returns
QStringList of command-line arguments

Must be implemented by subclasses to define program-specific arguments

Implemented in acav::QueryDependenciesParallelRunner.

Referenced by runParallel().

◆ runParallel()

void acav::ParallelProcessRunner::runParallel ( const QString & programPath,
const QStringList & inputData,
const QString & finalOutputPath )
protected

Start parallel execution.

Parameters
programPathPath to executable to run
inputDataInput data to be chunked and processed
finalOutputPathWhere to write final merged output

Definition at line 82 of file ParallelProcessRunner.cpp.

References chunkInputData(), error(), errorMessages_, finalOutputPath_, getTempOutputPath(), isRunning(), prepareProcessArguments(), progress(), runParallel(), and tempDir_.

Referenced by acav::QueryDependenciesParallelRunner::run(), and runParallel().

◆ setParallelCount()

void acav::ParallelProcessRunner::setParallelCount ( int count)

Set number of parallel processes (0 = auto-detect from CPU cores).

Definition at line 47 of file ParallelProcessRunner.cpp.

References setParallelCount().

Referenced by setParallelCount().

Member Data Documentation

◆ elapsed_

QElapsedTimer acav::ParallelProcessRunner::elapsed_
protected

Definition at line 163 of file ParallelProcessRunner.h.

◆ errorMessages_

QStringList acav::ParallelProcessRunner::errorMessages_
protected

Aggregated error messages.

Definition at line 161 of file ParallelProcessRunner.h.

Referenced by acav::QueryDependenciesParallelRunner::onAllCompleted(), and runParallel().

◆ finalOutputPath_

QString acav::ParallelProcessRunner::finalOutputPath_
protected

Final output file path.

Definition at line 160 of file ParallelProcessRunner.h.

Referenced by onAllCompleted(), acav::QueryDependenciesParallelRunner::onAllCompleted(), and runParallel().

◆ tempDir_

QTemporaryDir acav::ParallelProcessRunner::tempDir_
protected

Temporary directory for chunk outputs.

Definition at line 162 of file ParallelProcessRunner.h.

Referenced by getTempOutputPath(), and runParallel().


The documentation for this class was generated from the following files: