Code improvements
This commit is contained in:
parent
90cc54ea67
commit
016330685b
|
@ -498,7 +498,9 @@ void MainWindow::update_MakeStats_labels()
|
|||
// update values
|
||||
int size, secs;
|
||||
// size and lines
|
||||
this->craplog.collectPerfData();
|
||||
if ( this->craplog.isParsing() == true ) {
|
||||
this->craplog.collectPerfData();
|
||||
}
|
||||
size = this->craplog.getParsedSize();
|
||||
this->ui->label_MakeStats_Size->setText( this->printableSize( size ) );
|
||||
this->ui->label_MakeStats_Lines->setText( QString::fromStdString(std::to_string(this->craplog.getParsedLines())) );
|
||||
|
@ -507,6 +509,7 @@ void MainWindow::update_MakeStats_labels()
|
|||
this->craplog_timer_elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
this->craplog_timer_start - this->craplog_timer_lapse
|
||||
);
|
||||
size = this->craplog.getPerfSize();
|
||||
secs = this->craplog_timer_elapsed.count() / -1000000000;
|
||||
this->ui->label_MakeStats_Time->setText( this->printableTime( secs ));
|
||||
this->ui->label_MakeStats_Speed->setText( this->printableSpeed( size, secs ));
|
||||
|
@ -542,6 +545,8 @@ void MainWindow::craplogStarted()
|
|||
this->ui->label_MakeStats_Time->setEnabled(true);
|
||||
this->ui->icon_MakeStats_Speed->setEnabled(false);
|
||||
this->ui->label_MakeStats_Speed->setEnabled(true);
|
||||
// disable the settings tab
|
||||
this->ui->Set->setEnabled(false);
|
||||
}
|
||||
|
||||
void MainWindow::craplogFinished()
|
||||
|
@ -555,10 +560,12 @@ void MainWindow::craplogFinished()
|
|||
this->on_button_LogFiles_RefreshList_clicked();
|
||||
// enable the LogFiles section
|
||||
this->ui->LogBoxFiles->setEnabled(true);
|
||||
// enable all labels (needed only the first time)
|
||||
// enable all labels (needed only the first time each session)
|
||||
this->ui->icon_MakeStats_Size->setEnabled(true);
|
||||
this->ui->icon_MakeStats_Lines->setEnabled(true);
|
||||
this->ui->icon_MakeStats_Time->setEnabled(true);
|
||||
this->ui->icon_MakeStats_Speed->setEnabled(true);
|
||||
// enable the settings tab
|
||||
this->ui->Set->setEnabled(true);
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,6 @@ FormatOps::FormatOps()
|
|||
this->APACHE_ALF["%q"] = "request_query";
|
||||
this->APACHE_ALF["%s"] = "response_code";
|
||||
this->APACHE_ALF["%>s"] = "response_code";
|
||||
this->APACHE_ALF["%p"] = "port";
|
||||
this->APACHE_ALF["%O"] = "bytes_sent";
|
||||
this->APACHE_ALF["%I"] = "bytes_received";
|
||||
this->APACHE_ALF["%T"] = "time_taken_s";
|
||||
|
@ -63,6 +62,7 @@ FormatOps::FormatOps()
|
|||
this->APACHE_ALF["%k"] = "NONE";
|
||||
this->APACHE_ALF["%l"] = "NONE";
|
||||
this->APACHE_ALF["%L"] = "NONE";
|
||||
this->APACHE_ALF["%p"] = "NONE";
|
||||
this->APACHE_ALF["%P"] = "NONE";
|
||||
this->APACHE_ALF["%R"] = "NONE";
|
||||
this->APACHE_ALF["%S"] = "NONE";
|
||||
|
|
|
@ -41,10 +41,10 @@ std::string HashOps::digestFile( const std::string& file_path )
|
|||
|
||||
|
||||
// check if the given hash is from a file which has been used already
|
||||
bool HashOps::hasBeenUsed( const std::string &file_hash, const int web_server_id )
|
||||
bool HashOps::hasBeenUsed(const std::string &file_hash, const int web_server_id, const int log_type )
|
||||
{
|
||||
bool found = false;
|
||||
for ( const std::string &hash : this->hashes.at( web_server_id ) ) {
|
||||
for ( const std::string &hash : this->hashes.at( web_server_id ).at( log_type ) ) {
|
||||
if ( file_hash == hash ) {
|
||||
found = true;
|
||||
break;
|
||||
|
@ -55,12 +55,12 @@ bool HashOps::hasBeenUsed( const std::string &file_hash, const int web_server_id
|
|||
|
||||
|
||||
// insert the given hash/es in the relative list
|
||||
bool HashOps::insertUsedHash( const std::string &hash, const int web_server_id )
|
||||
bool HashOps::insertUsedHash( const std::string& hash, const int web_server_id, const int log_type )
|
||||
{
|
||||
bool proceed = true;
|
||||
try {
|
||||
if( VecOps::contains( this->hashes.at( web_server_id ), hash )) {
|
||||
this->hashes.at( web_server_id ).push_back( hash );
|
||||
if( VecOps::contains( this->hashes.at( web_server_id ).at( log_type ), hash ) == false ) {
|
||||
this->hashes.at( web_server_id ).at( log_type ).push_back( hash );
|
||||
}
|
||||
} catch (...) {
|
||||
// failed to insert the hash
|
||||
|
@ -71,13 +71,15 @@ bool HashOps::insertUsedHash( const std::string &hash, const int web_server_id )
|
|||
}
|
||||
|
||||
|
||||
bool HashOps::insertUsedHashes( const std::unordered_map<std::string, std::string>& hashes, const int web_server_id )
|
||||
bool HashOps::insertUsedHashes( const std::unordered_map<int, std::vector<std::string>>& hashes, const int web_server_id )
|
||||
{
|
||||
bool proceed = true;
|
||||
for ( /*const string &hash*/ const auto& [ name, hash ] : hashes ) {
|
||||
if ( this->insertUsedHash( hash, web_server_id ) == false ) {
|
||||
proceed = false;
|
||||
break;
|
||||
for ( const auto& [ log_type, data ] : hashes ) {
|
||||
for ( const std::string& hash : data ) {
|
||||
if ( this->insertUsedHash( hash, web_server_id, log_type ) == false ) {
|
||||
proceed = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return proceed;
|
||||
|
|
|
@ -17,16 +17,16 @@ public:
|
|||
// returns the hash
|
||||
std::string digestFile( const std::string& file_path );
|
||||
// check if the given hash is from a file which has been used already
|
||||
bool hasBeenUsed( const std::string& file_hash, const int web_server_id );
|
||||
bool hasBeenUsed( const std::string& file_hash, const int web_server_id, const int log_type );
|
||||
// insert the given hash/es in the relative list
|
||||
bool insertUsedHash( const std::string& hash, const int web_server_id );
|
||||
bool insertUsedHashes( const std::unordered_map<std::string, std::string>& hashes, const int web_server_id );
|
||||
bool insertUsedHash( const std::string& hash, const int web_server_id, const int log_type );
|
||||
bool insertUsedHashes( const std::unordered_map<int, std::vector<std::string>>& hashes, const int web_server_id );
|
||||
|
||||
private:
|
||||
// id constants
|
||||
const unsigned int APACHE_ID=11, NGINX_ID=12, IIS_ID=13;
|
||||
// lists of used files' hashes
|
||||
std::unordered_map<int, std::vector<std::string>> hashes;
|
||||
std::unordered_map<int, std::unordered_map<int, std::vector<std::string>>> hashes;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -369,7 +369,6 @@ LogOps::LogType LogOps::comparativeTypeCheck( const std::string& line, const For
|
|||
std::unordered_map<int, std::string> LogOps::parseLine( const std::string& line, const FormatOps::LogsFormat& format )
|
||||
{
|
||||
std::unordered_map<int, std::string> data;
|
||||
|
||||
std::string sep, fld, fld_str, aux_fld_str, aux_sep1, aux_sep2;
|
||||
bool missing=false, add_pm=false;
|
||||
int start, stop=0, i=0, aux_start1, aux_start2, aux_stop;
|
||||
|
@ -646,6 +645,9 @@ std::unordered_map<int, std::string> LogOps::parseLine( const std::string& line,
|
|||
}
|
||||
}
|
||||
|
||||
// set the default warning mark ( 0=false )
|
||||
data.emplace( 99, "0" );
|
||||
|
||||
this->lines ++;
|
||||
|
||||
return data;
|
||||
|
|
|
@ -8,7 +8,7 @@ RichText::RichText()
|
|||
}
|
||||
|
||||
|
||||
QString RichText::enrichLogs(const std::string& content, const FormatOps::LogsFormat& logs_format, const TextBrowser &TB )
|
||||
QString RichText::enrichLogs(const std::string& content, const FormatOps::LogsFormat& logs_format, const TextBrowser& TB )
|
||||
{
|
||||
std::unordered_map<std::string, QString> colors = TB.getColorScheme();
|
||||
int color_scheme = TB.getColorSchemeID();
|
||||
|
|
Loading…
Reference in a new issue