|
ACAV f0ba4b7c9529
Abstract Syntax Tree (AST) visualization tool for C, C++, and Objective-C
|
Generic parallel process runner for executing multiple instances of a program. More...
#include <ParallelProcessRunner.h>
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_ |
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:
Usage pattern:
Definition at line 61 of file ParallelProcessRunner.h.
|
explicit |
Definition at line 33 of file ParallelProcessRunner.cpp.
|
override |
Definition at line 37 of file ParallelProcessRunner.cpp.
| void acav::ParallelProcessRunner::cancel | ( | ) |
Cancel all running processes.
Definition at line 60 of file ParallelProcessRunner.cpp.
References cancel().
Referenced by cancel().
|
signal |
Emitted when a single chunk completes successfully.
| chunkIndex | Index of the completed chunk |
| totalChunks | Total number of chunks |
|
signal |
Emitted when a single chunk fails.
| chunkIndex | Index of the failed chunk |
| errorMessage | Error description |
|
protectedvirtual |
Divide input data into chunks for parallel processing.
| inputData | Generic input data (e.g., list of files, list of tasks) |
| chunkCount | Number of chunks to create |
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().
|
inline |
Get current parallel count setting.
Definition at line 75 of file ParallelProcessRunner.h.
|
protected |
Get path to temporary output file for a chunk.
| chunkIndex | Index of the chunk |
Definition at line 170 of file ParallelProcessRunner.cpp.
References getTempOutputPath(), and tempDir_.
Referenced by getTempOutputPath(), and runParallel().
| 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().
|
protectedpure virtual |
Merge outputs from all chunks into final result.
| tempOutputPaths | Paths to temporary output files (one per chunk) |
| finalOutputPath | Path where merged result should be written |
| errorMessage | Output parameter for error details |
Must be implemented by subclasses to define result merging logic
Implemented in acav::QueryDependenciesParallelRunner.
Referenced by onAllCompleted().
|
protectedvirtual |
Called when all processes have completed (success or failure).
| successCount | Number of chunks that completed successfully |
| failureCount | Number of chunks that failed |
| totalCount | Total 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().
|
protectedpure virtual |
Prepare command-line arguments for a specific chunk.
| chunkIndex | Index of the chunk being processed |
| chunkData | Data items in this chunk |
| tempOutputPath | Temporary file path for this chunk's output |
Must be implemented by subclasses to define program-specific arguments
Implemented in acav::QueryDependenciesParallelRunner.
Referenced by runParallel().
|
protected |
Start parallel execution.
| programPath | Path to executable to run |
| inputData | Input data to be chunked and processed |
| finalOutputPath | Where 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().
| 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().
|
protected |
Definition at line 163 of file ParallelProcessRunner.h.
|
protected |
Aggregated error messages.
Definition at line 161 of file ParallelProcessRunner.h.
Referenced by acav::QueryDependenciesParallelRunner::onAllCompleted(), and runParallel().
|
protected |
Final output file path.
Definition at line 160 of file ParallelProcessRunner.h.
Referenced by onAllCompleted(), acav::QueryDependenciesParallelRunner::onAllCompleted(), and runParallel().
|
protected |
Temporary directory for chunk outputs.
Definition at line 162 of file ParallelProcessRunner.h.
Referenced by getTempOutputPath(), and runParallel().