diff options
Diffstat (limited to 'sinksh/syntax_modules/sink_stat.cpp')
-rw-r--r-- | sinksh/syntax_modules/sink_stat.cpp | 75 |
1 files changed, 37 insertions, 38 deletions
diff --git a/sinksh/syntax_modules/sink_stat.cpp b/sinksh/syntax_modules/sink_stat.cpp index d6fcc62..926c744 100644 --- a/sinksh/syntax_modules/sink_stat.cpp +++ b/sinksh/syntax_modules/sink_stat.cpp | |||
@@ -36,52 +36,49 @@ | |||
36 | namespace SinkStat | 36 | namespace SinkStat |
37 | { | 37 | { |
38 | 38 | ||
39 | void statResources(const QStringList &resources, const State &state) | 39 | void statResource(const QString &resource, const State &state) |
40 | { | 40 | { |
41 | for (const auto &resource : resources) { | 41 | qint64 total = 0; |
42 | qint64 total = 0; | 42 | Sink::Storage::DataStore storage(Sink::storageLocation(), resource, Sink::Storage::DataStore::ReadOnly); |
43 | Sink::Storage::DataStore storage(Sink::storageLocation(), resource, Sink::Storage::DataStore::ReadOnly); | 43 | auto transaction = storage.createTransaction(Sink::Storage::DataStore::ReadOnly); |
44 | auto transaction = storage.createTransaction(Sink::Storage::DataStore::ReadOnly); | 44 | |
45 | 45 | QList<QByteArray> databases = transaction.getDatabaseNames(); | |
46 | QList<QByteArray> databases = transaction.getDatabaseNames(); | 46 | for (const auto &databaseName : databases) { |
47 | for (const auto &databaseName : databases) { | 47 | auto db = transaction.openDatabase(databaseName); |
48 | state.printLine(QObject::tr("Database: %1").arg(QString(databaseName)), 1); | 48 | qint64 size = db.getSize() / 1024; |
49 | auto db = transaction.openDatabase(databaseName); | 49 | state.printLine(QObject::tr("%1:\t%2 [kb]").arg(QString(databaseName)).arg(size), 1); |
50 | qint64 size = db.getSize() / 1024; | 50 | total += size; |
51 | state.printLine(QObject::tr("Size [kb]: %1").arg(size), 1); | ||
52 | total += size; | ||
53 | } | ||
54 | state.printLine(QObject::tr("Resource total in database [kb]: %1").arg(total), 1); | ||
55 | int diskUsage = 0; | ||
56 | |||
57 | QDir dir(Sink::storageLocation()); | ||
58 | for (const auto &folder : dir.entryList(QStringList() << resource + "*")) { | ||
59 | state.printLine(QObject::tr("Accumulating %1").arg(folder), 1); | ||
60 | diskUsage += Sink::Storage::DataStore(Sink::storageLocation(), folder, Sink::Storage::DataStore::ReadOnly).diskUsage(); | ||
61 | } | ||
62 | auto size = diskUsage / 1024; | ||
63 | state.printLine(QObject::tr("Actual database file sizes [kb]: %1").arg(size), 1); | ||
64 | |||
65 | QDir dataDir{Sink::resourceStorageLocation(resource.toLatin1()) + "/blob/"}; | ||
66 | Q_ASSERT(dataDir.exists()); | ||
67 | qint64 dataSize = 0; | ||
68 | for (const auto &e : dataDir.entryInfoList(QDir::Files | QDir::NoSymLinks | QDir::NoDotAndDotDot)) { | ||
69 | dataSize += e.size(); | ||
70 | } | ||
71 | state.printLine(QObject::tr("Total BLOB size [kb]: %1").arg(dataSize / 1024), 1); | ||
72 | state.printLine(); | ||
73 | } | 51 | } |
74 | 52 | state.printLine(); | |
53 | state.printLine(QObject::tr("Calculated named database sizes total of main database: %1 [kb]").arg(total), 1); | ||
54 | state.printLine(QObject::tr("Write amplification of main database: %1").arg(float(storage.diskUsage() / 1024)/float(total)), 1); | ||
55 | int diskUsage = 0; | ||
56 | |||
57 | QDir dir(Sink::storageLocation()); | ||
58 | for (const auto &folder : dir.entryList(QStringList() << resource + "*")) { | ||
59 | auto size = Sink::Storage::DataStore(Sink::storageLocation(), folder, Sink::Storage::DataStore::ReadOnly).diskUsage(); | ||
60 | diskUsage += size; | ||
61 | state.printLine(QObject::tr("...Accumulating %1: %2 [kb]").arg(folder).arg(size / 1024), 1); | ||
62 | } | ||
63 | auto size = diskUsage / 1024; | ||
64 | state.printLine(QObject::tr("Actual database file sizes total: %1 [kb]").arg(size), 1); | ||
65 | |||
66 | QDir dataDir{Sink::resourceStorageLocation(resource.toLatin1()) + "/blob/"}; | ||
67 | Q_ASSERT(dataDir.exists()); | ||
68 | qint64 dataSize = 0; | ||
69 | for (const auto &e : dataDir.entryInfoList(QDir::Files | QDir::NoSymLinks | QDir::NoDotAndDotDot)) { | ||
70 | dataSize += e.size(); | ||
71 | } | ||
72 | state.printLine(QObject::tr("Total BLOB size [kb]: %1").arg(dataSize / 1024), 1); | ||
73 | state.printLine(); | ||
75 | } | 74 | } |
76 | 75 | ||
77 | bool statAllResources(State &state) | 76 | bool statAllResources(State &state) |
78 | { | 77 | { |
79 | Sink::Query query; | 78 | Sink::Query query; |
80 | QStringList resources; | ||
81 | for (const auto &r : SinkshUtils::getStore("resource").read(query)) { | 79 | for (const auto &r : SinkshUtils::getStore("resource").read(query)) { |
82 | resources << r.identifier(); | 80 | statResource(r.identifier(), state); |
83 | } | 81 | } |
84 | statResources(resources, state); | ||
85 | return false; | 82 | return false; |
86 | } | 83 | } |
87 | 84 | ||
@@ -91,7 +88,9 @@ bool stat(const QStringList &args, State &state) | |||
91 | return statAllResources(state); | 88 | return statAllResources(state); |
92 | } | 89 | } |
93 | 90 | ||
94 | statResources(args, state); | 91 | for (const auto &r : args) { |
92 | statResource(r, state); | ||
93 | } | ||
95 | return false; | 94 | return false; |
96 | } | 95 | } |
97 | 96 | ||