mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-02 06:35:52 +08:00
Ref T698, functions to count network VATLIB calls to identify packets
* functions in network classes * context functions
This commit is contained in:
committed by
Mat Sutcliffe
parent
92baa16536
commit
f754154455
46
src/blackcore/network.cpp
Normal file
46
src/blackcore/network.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
/* Copyright (C) 2019
|
||||
* swift Project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution. No part of swift project, including this file, may be copied, modified, propagated,
|
||||
* or distributed except according to the terms contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "network.h"
|
||||
#include "blackmisc/range.h"
|
||||
#include <QStringBuilder>
|
||||
|
||||
using namespace BlackMisc;
|
||||
|
||||
namespace BlackCore
|
||||
{
|
||||
int INetwork::increaseStatisticsValue(const QString &identifier, const QString &appendix)
|
||||
{
|
||||
if (identifier.isEmpty() || !m_statistics) { return -1; }
|
||||
int &v = appendix.isEmpty() ? m_callStatistics[identifier] : m_callStatistics[identifier % u"." % appendix];
|
||||
v++;
|
||||
return v;
|
||||
}
|
||||
|
||||
QString INetwork::getNetworkStatisticsAsText(bool reset, const QString &separator)
|
||||
{
|
||||
QMap<int, QString> transformed;
|
||||
for (const auto pair : makePairsRange(as_const(m_callStatistics)))
|
||||
{
|
||||
// key is pair.first, value is pair.second
|
||||
transformed.insertMulti(pair.second, pair.first);
|
||||
}
|
||||
|
||||
if (reset) { this->clearStatistics(); }
|
||||
|
||||
// sorted by value
|
||||
QString stats;
|
||||
for (const auto pair : makePairsRange(as_const(transformed)))
|
||||
{
|
||||
stats +=
|
||||
(stats.isEmpty() ? QString() : separator) %
|
||||
pair.second % u": " % QString::number(pair.first);
|
||||
}
|
||||
return stats;
|
||||
}
|
||||
} // ns
|
||||
Reference in New Issue
Block a user