File indexing completed on 2024-05-05 03:52:20

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         const QStringView str(line);
0029 
0030         const QString rchar(QStringLiteral("rchar: "));
0031         if (str.startsWith(rchar)) {
0032             const ulong amount = str.mid(rchar.size()).toULong();
0033             qDebug() << "Read:" << amount / 1024  << "kb";
0034         }
0035 
0036         const QString wchar(QStringLiteral("wchar: "));
0037         if (str.startsWith(wchar)) {
0038             const ulong amount = str.mid(wchar.size()).toULong();
0039             qDebug() << "Write:" << amount / 1024  << "kb";
0040         }
0041 
0042         const QString read(QStringLiteral("read_bytes: "));
0043         if (str.startsWith(read)) {
0044             const ulong amount = str.mid(read.size()).toULong();
0045             qDebug() << "Actual Reads:" << amount / 1024  << "kb";
0046         }
0047 
0048         const QString write(QStringLiteral("write_bytes: "));
0049         if (str.startsWith(write)) {
0050             const ulong amount = str.mid(write.size()).toULong();
0051             qDebug() << "Actual Writes:" << amount / 1024  << "kb";
0052         }
0053     }
0054     qDebug() << "\nThe actual read/writes may be 0 because of an existing"
0055              << "cache and /tmp being memory mapped";
0056 }
0057 
0058 #endif