fabric/runstatistics.h

fabric/runstatistics.h

fabric/runstatistics.h

Namespaces

Name
Syntalos

Classes

Name
structSyntalos::ModuleRunStats
Statistics for a single module that took part in a run.
structSyntalos::EventThreadRunStats
Statistics for a shared event thread.
structSyntalos::ConnectionRunStats
Statistics for a single connection (stream subscription) between two ports.
structSyntalos::RunStatistics
Statistics collected by the engine over one experiment run.

Source code

/*
 * Copyright (C) 2025-2026 Matthias Klumpp <matthias@tenstral.net>
 *
 * Licensed under the GNU Lesser General Public License Version 3
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the license, or
 * (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this software.  If not, see <http://www.gnu.org/licenses/>.
 */

#pragma once

#include <QDateTime>
#include <QJsonObject>
#include <QList>
#include <QMap>
#include <QString>
#include <QStringList>
#include <expected>
#include <vector>

#include "datactl/datatypes.h"
#include "fabric/moduleapi.h"
#include "utils/resourceinfo.h"

namespace Syntalos
{

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpadded"

struct ModuleRunStats {
    QString id;
    QString name;
    ModuleDriverKind driver = ModuleDriverKind::NONE;
    ModuleState finalState = ModuleState::UNKNOWN;
    bool outOfProcess = false;
    QString eventThreadKey; 
    QString errorMessage;

    // priority elevation granted for this run
    bool realtimeRequested = false;
    int niceness = 0;
    std::optional<bool> priorityApplied;
    std::vector<uint> cpuAffinity;

    std::optional<ThreadUsageStats> thread;

    qint64 workerPid = 0;
    std::optional<ThreadUsageStats> worker;

    QVariantHash moduleStats;
};

struct EventThreadRunStats {
    QString key;
    QStringList moduleNames;
    bool realtimeRequested = false;
    int niceness = 0;
    bool priorityApplied = false; 
    std::optional<ThreadUsageStats> thread;
};

struct ConnectionRunStats {
    QString srcModule;
    QString srcPort;
    QString dstModule;
    QString dstPort;
    QString dataType;
    quint64 itemsReceived = 0;
    quint64 peakPending = 0;   
    quint64 pendingAtStop = 0; 
    ConnectionHeatLevel maxHeat = ConnectionHeatLevel::NONE;

    bool directIpc = false;
};

struct RunStatistics {
    static constexpr int FormatVersion = 1;

    QDateTime started;
    QString runId;
    QString experimentId;
    QString exportDir;
    bool ephemeral = false;
    bool failed = false;
    QString failReason;
    double durationSec = 0.0;    
    double usageWindowSec = 0.0; 
    qint64 bytesWritten = -1;

    int cpuCoreCount = 0;         
    int cpuPhysicalCoreCount = 0; 
    uint priorityBudget = 0;      
    int threadsElevated = 0;      
    int threadsTotal = 0;         

    std::optional<ThreadUsageStats> mainThread; 
    std::optional<ThreadUsageStats> process;    
    qint64 peakRssKiB = -1;                     

    QList<ModuleRunStats> modules;
    QList<EventThreadRunStats> eventThreads;
    QList<ConnectionRunStats> connections;

    QMap<QString, QString> system;

    QJsonObject toJson() const;
    QByteArray toJsonData() const;

    QString toHtml() const;

    auto saveJson(const QString &path) const -> std::expected<void, QString>;

    static auto fromJson(const QJsonObject &root) -> std::expected<RunStatistics, QString>;

    static auto loadJson(const QString &path) -> std::expected<RunStatistics, QString>;
};

#pragma GCC diagnostic pop

} // namespace Syntalos

Updated on 2026-11-26 at 18:54:14 +0000