fabric/utils/resourceinfo.h

fabric/utils/resourceinfo.h

fabric/utils/resourceinfo.h

Namespaces

Name
Syntalos

Classes

Name
structSyntalos::MemInfo
structSyntalos::MemPressure
Memory pressure stall information as reported by the kernel (PSI).
structSyntalos::DiskSpaceInfo
Information about the storage a path is located on.
classSyntalos::ResourceTrend
Estimate how fast a finite resource is being used up.

Source code

/*
 * Copyright (C) 2019-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 <QString>
#include <QElapsedTimer>

namespace Syntalos
{

typedef struct {
    long long memTotalKiB;
    long long memAvailableKiB;
    long long memAvailableMiB;
    double memAvailablePercent;
    long long swapTotalKiB;
    long long swapFreeKiB;
} MemInfo;

typedef struct {
    bool available; 
    double someAvg10;
    double someAvg60;
    double fullAvg10;
    double fullAvg60;
} MemPressure;

MemInfo readMemInfo();
MemPressure readMemPressure();

struct DiskSpaceInfo {
    bool valid = false;         
    quint64 deviceId = 0;       
    QString mountPoint;         
    qint64 bytesAvailable = -1; 
    qint64 bytesTotal = -1;
};

DiskSpaceInfo diskSpaceInfo(const QString &path);

qint64 directoryTotalSize(const QString &path);

class ResourceTrend
{
public:
    explicit ResourceTrend(double minRelevantRate = 0.0, double smoothing = 0.5);

    void reset();

    void addSample(qint64 remaining);

    void addSample(qint64 remaining, double elapsedSec);

    bool hasRate() const;

    double consumptionRate() const;

    double secondsUntilDepleted() const;

    qint64 lastRemaining() const;

private:
    double m_minRelevantRate;
    double m_smoothing;
    qint64 m_lastRemaining;
    double m_rate;
    QElapsedTimer m_timer;
};

} // namespace Syntalos

Updated on 2026-09-06 at 20:30:11 +0000