mirror of https://github.com/aria2/aria2
2010-03-02 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Avoid costly BtMessage::toString() if info level log is not required. * src/DefaultBtInteractive.cc * src/Logger.h * src/SimpleBtMessage.ccpull/1/head
parent
18ea756a74
commit
94e306cec4
|
@ -1,3 +1,11 @@
|
||||||
|
2010-03-02 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
|
Avoid costly BtMessage::toString() if info level log is not
|
||||||
|
required.
|
||||||
|
* src/DefaultBtInteractive.cc
|
||||||
|
* src/Logger.h
|
||||||
|
* src/SimpleBtMessage.cc
|
||||||
|
|
||||||
2010-03-02 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
2010-03-02 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
Reserved vector elements based on profiler results.
|
Reserved vector elements based on profiler results.
|
||||||
|
|
|
@ -265,9 +265,11 @@ size_t DefaultBtInteractive::receiveMessages() {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
++msgcount;
|
++msgcount;
|
||||||
logger->info(MSG_RECEIVE_PEER_MESSAGE, cuid,
|
if(logger->info()) {
|
||||||
peer->ipaddr.c_str(), peer->port,
|
logger->info(MSG_RECEIVE_PEER_MESSAGE, cuid,
|
||||||
message->toString().c_str());
|
peer->ipaddr.c_str(), peer->port,
|
||||||
|
message->toString().c_str());
|
||||||
|
}
|
||||||
message->doReceivedAction();
|
message->doReceivedAction();
|
||||||
|
|
||||||
switch(message->getId()) {
|
switch(message->getId()) {
|
||||||
|
|
12
src/Logger.h
12
src/Logger.h
|
@ -71,6 +71,11 @@ private:
|
||||||
std::ofstream _file;
|
std::ofstream _file;
|
||||||
|
|
||||||
int _stdoutField;
|
int _stdoutField;
|
||||||
|
|
||||||
|
inline bool levelEnabled(LEVEL level) const
|
||||||
|
{
|
||||||
|
return (level >= _logLevel && _file.is_open()) || _stdoutField&level;
|
||||||
|
}
|
||||||
protected:
|
protected:
|
||||||
virtual void writeLog
|
virtual void writeLog
|
||||||
(std::ostream& o, LEVEL logLevel, const std::string& logLevelLabel,
|
(std::ostream& o, LEVEL logLevel, const std::string& logLevelLabel,
|
||||||
|
@ -192,7 +197,12 @@ public:
|
||||||
// either file or stdout.
|
// either file or stdout.
|
||||||
bool debug() const
|
bool debug() const
|
||||||
{
|
{
|
||||||
return (DEBUG >= _logLevel && _file.is_open()) || _stdoutField&DEBUG;
|
return levelEnabled(DEBUG);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool info() const
|
||||||
|
{
|
||||||
|
return levelEnabled(INFO);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -55,8 +55,10 @@ void SimpleBtMessage::send() {
|
||||||
if(!sendingInProgress) {
|
if(!sendingInProgress) {
|
||||||
const unsigned char* msg = getMessage();
|
const unsigned char* msg = getMessage();
|
||||||
size_t msgLength = getMessageLength();
|
size_t msgLength = getMessageLength();
|
||||||
logger->info(MSG_SEND_PEER_MESSAGE,
|
if(logger->info()) {
|
||||||
cuid, peer->ipaddr.c_str(), peer->port, toString().c_str());
|
logger->info(MSG_SEND_PEER_MESSAGE,
|
||||||
|
cuid, peer->ipaddr.c_str(), peer->port, toString().c_str());
|
||||||
|
}
|
||||||
if(logger->debug()) {
|
if(logger->debug()) {
|
||||||
logger->debug("msglength = %lu bytes",
|
logger->debug("msglength = %lu bytes",
|
||||||
static_cast<unsigned long>(msgLength));
|
static_cast<unsigned long>(msgLength));
|
||||||
|
|
Loading…
Reference in New Issue