File indexing completed on 2024-05-12 15:32:28

0001 /*
0002     This file is part of the KDE Baloo Project
0003     SPDX-FileCopyrightText: 2014 Vishesh Handa <me@vhanda.in>
0004 
0005     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0006 */
0007 
0008 #ifndef BALOO_FILE_TEST_UTIL_H
0009 #define BALOO_FILE_TEST_UTIL_H
0010 
0011 #include <QDebug>
0012 #include <QFile>
0013 
0014 inline void printIOUsage()
0015 {
0016     // Print the io usage
0017     QFile file(QStringLiteral("/proc/self/io"));
0018     file.open(QIODevice::ReadOnly | QIODevice::Text);
0019 
0020     QTextStream fs(&file);
0021     QString fileContents = fs.readAll();
0022 
0023     qDebug() << "------- IO ---------";
0024     QTextStream stream(&fileContents);
0025     while (!stream.atEnd()) {
0026         const QString line = stream.readLine();
0027 
0028 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
0029         const QStringView str(line);
0030 #else
0031         const QStringRef str(&line);
0032 #endif
0033 
0034         const QString rchar(QStringLiteral("rchar: "));
0035         if (str.startsWith(rchar)) {
0036             const ulong amount = str.mid(rchar.size()).toULong();
0037             qDebug() << "Read:" << amount / 1024  << "kb";
0038         }
0039 
0040         const QString wchar(QStringLiteral("wchar: "));
0041         if (str.startsWith(wchar)) {
0042             const ulong amount = str.mid(wchar.size()).toULong();
0043             qDebug() << "Write:" << amount / 1024  << "kb";
0044         }
0045 
0046         const QString read(QStringLiteral("read_bytes: "));
0047         if (str.startsWith(read)) {
0048             const ulong amount = str.mid(read.size()).toULong();
0049             qDebug() << "Actual Reads:" << amount / 1024  << "kb";
0050         }
0051 
0052         const QString write(QStringLiteral("write_bytes: "));
0053         if (str.startsWith(write)) {
0054             const ulong amount = str.mid(write.size()).toULong();
0055             qDebug() << "Actual Writes:" << amount / 1024  << "kb";
0056         }
0057     }
0058     qDebug() << "\nThe actual read/writes may be 0 because of an existing"
0059              << "cache and /tmp being memory mapped";
0060 }
0061 
0062 #endif