Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
psemiletov committed Feb 6, 2023
1 parent 5205d42 commit 312699b
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 140 deletions.
47 changes: 20 additions & 27 deletions cycle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@
#include <chrono>
#include <iostream>


#include "cycle.h"

using namespace std::chrono;



namespace
{
volatile std::sig_atomic_t g_signal;
Expand Down Expand Up @@ -58,15 +55,14 @@ CGenCycle::CGenCycle (CParameters *prms, const string &fname)
test_string_size = test_string.size();

if (params->debug)
cout << "size_needed, bytes: " << size_needed << endl;
cout << "size_needed, bytes: " << size_needed << endl;

if (size_needed >= free_space)
{
cout << "Output files will not fit to the available disk space with current parameters!" << endl;
no_free_space = true;
}
}

}


Expand Down Expand Up @@ -166,7 +162,7 @@ void CGenCycleRated::loop()
if (! params->pure)
{
if (params->bstdout)
cout << log_string << "\n";
cout << log_string << "\n";

if (! file_out_error && ! no_free_space)
{
Expand Down Expand Up @@ -217,33 +213,33 @@ CGenCycleUnrated::CGenCycleUnrated (CParameters *prms, const string &fname): CGe

void CGenCycleUnrated::loop()
{
auto start = high_resolution_clock::now();
auto start = high_resolution_clock::now();

size_t lines_counter = 0;
size_t lines_counter = 0;

// using clock = std::chrono::steady_clock;

while (true)
{
if (g_signal == SIGINT)
break;
while (true)
{
if (g_signal == SIGINT)
break;

lines_counter++;
lines_counter++;

if (params->lines != 0 && lines_counter > params->lines)
if (params->lines != 0 && lines_counter > params->lines)
break;

if (params->size != 0 && file_size_total > params->size)
break;
if (params->size != 0 && file_size_total > params->size)
break;

if (params->duration != 0)
{
auto stop = high_resolution_clock::now();
if (params->duration != 0)
{
auto stop = high_resolution_clock::now();
// auto duration = duration_cast<microseconds>(stop - start);
auto duration_s = duration_cast<seconds>(stop - start);
if (duration_s >= chrono::seconds(params->duration))
break;
}
auto duration_s = duration_cast<seconds>(stop - start);
if (duration_s >= chrono::seconds(params->duration))
break;
}

// std::cout << "seconds_counter: " << seconds_counter << endl;
// std::cout << "frame_counter: " << frame_counter << endl;
Expand All @@ -259,6 +255,7 @@ void CGenCycleUnrated::loop()
if (! file_out_error && ! no_free_space)
{
file_out << log_string << "\n";

log_current_size += log_string.size();
file_size_total += log_string.size();

Expand Down Expand Up @@ -293,9 +290,6 @@ void CGenCycleUnrated::loop()

if (params->stats)
{
// cout << "lines_counter : " << lines_counter << endl;
// cout << "duration_s.count : " << duration_s.count() << endl;

double lines_per_second = (double) lines_counter / duration_s.count();
cout << "Statistics, lines per seconds: " << lines_per_second << endl;
}
Expand All @@ -307,6 +301,5 @@ void CGenCycleUnrated::loop()
cout << "duration_s.count (seconds): " << duration_s.count() << endl;
}


file_out.close();
}
2 changes: 0 additions & 2 deletions logrot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ void CLogRotator::rotate()

if (has_gzip && use_gzip)
{

for (size_t i = filenames.size() - 1; i > 0; i--)
{
string oldname = filenames[i-1] + ".gz";
Expand All @@ -58,4 +57,3 @@ void CLogRotator::rotate()
}
}
}

43 changes: 2 additions & 41 deletions pairfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* this code by Peter Semiletov is Public Domain *
**********************************************************/


#include <fstream>
#include <iostream>
#include <sstream>
Expand All @@ -11,7 +10,6 @@
#include <cstring>
#include <algorithm>


#include "pairfile.h"
#include "utl.h"

Expand Down Expand Up @@ -98,7 +96,7 @@ int CPairFile::get_int (const string &key, int def_value)
int result = def_value;

if (values.find (key) == values.end())
return result;
return result;

const char *s = values[key].c_str();
if (s)
Expand All @@ -107,43 +105,6 @@ int CPairFile::get_int (const string &key, int def_value)
return result;
}

/*
unsigned int CPairFile::get_uint (const string &key, unsigned int def_value)
{
unsigned int result = def_value;
if (values.find (key) == values.end())
return result;
const char *s = values[key].c_str();
if (! s)
return result;
char* end;
result = strtoul (s, &end, 10);
return result;
}
*/
/*
unsigned long long CPairFile::get_uulong (const string &key, unsigned long long def_value)
{
unsigned long long result = def_value;
if (values.find (key) == values.end())
return result;
const char *s = values[key].c_str();
if (! s)
return result;
char* end;
result = strtoull (s, &end, 10);
return result;
}
*/


size_t CPairFile::get_num (const string &key, unsigned long long def_value)
{
Expand Down Expand Up @@ -267,7 +228,7 @@ CPairFile::CPairFile (int argc, char *argv[])
continue;
}

if (pos > line.size()) //????
if (pos >= line.size())
continue;

string a = line.substr (0, pos);
Expand Down
1 change: 0 additions & 1 deletion pairfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class CPairFile

bool get_bool (const string &key, bool def_value = false);
int get_int (const string &key, int def_value = 0);
// unsigned int get_uint (const string &key, unsigned int def_value = 0);
size_t get_num (const string &key, unsigned long long def_value = 0);

float get_float (const string &key, float def_value = 0.0f);
Expand Down
2 changes: 1 addition & 1 deletion params.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void CParameters::print()
cout << "lines: " << lines << endl;
cout << "logfile: " << logfile << endl;
cout << "logsize: " << max_log_file_size << endl;
cout << "max_log_files: " << max_log_files << endl;
cout << "logfiles: " << max_log_files << endl;
cout << "mode: " << mode << endl;
cout << "pure: " << pure << endl;
cout << "rate: " << rate << endl;
Expand Down
1 change: 0 additions & 1 deletion params.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class CParameters
bool benchmark;
bool stats;


void print();
};

Expand Down
15 changes: 5 additions & 10 deletions tpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
#include "tpl.h"
#include "utl.h"



//full nginx vars see at
//http://nginx.org/en/docs/varindex.html
//Apache:
//https://httpd.apache.org/docs/current/mod/mod_log_config.html


void CTpl::replace_value_by_key (const string &key, const string &value)
Expand All @@ -30,7 +32,6 @@ void CTpl::replace_value_by_key (const string &key, const string &value)
}



CTpl::~CTpl()
{
delete pf;
Expand All @@ -44,7 +45,6 @@ CTpl::~CTpl()

CTpl::CTpl (const string &fname, const string &amode)
{

pf = new CPairFile (fname, false);

mode = amode;
Expand Down Expand Up @@ -101,8 +101,6 @@ CTpl::CTpl (const string &fname, const string &amode)

vars.insert (std::make_pair ("%>s", new CVar ("%>s", "200|400")));
vars.insert (std::make_pair ("%b", new CVar ("%b", "1..9999")));


}


Expand Down Expand Up @@ -146,12 +144,9 @@ string CTpl::prepare_log_string()
i = logstring.find (variable);
if (i != string::npos)
// logstring = logstring.replace (i, variable.length(), it->second->get_val());
logstring.replace (i, variable.length(), it->second->get_val());

logstring.replace (i, variable.length(), it->second->get_val());
}
while (i != string::npos);


}

return logstring;
Expand Down
2 changes: 0 additions & 2 deletions tpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,4 @@ class CTpl

};


#endif

46 changes: 1 addition & 45 deletions utl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ bool is_path_abs (const string &path)
}



string str_replace (string &source, const string &text_to_find, const string &replace_with)
{
if (source.empty())
Expand All @@ -187,7 +186,6 @@ string str_replace (string &source, const string &text_to_find, const string &re
}



string string_replace_all (const string &s, const string &from, const string &to)
{
string result = s;
Expand Down Expand Up @@ -239,7 +237,7 @@ string string_to_lower (const string &s)
{
string result = s;

std::for_each (
std::for_each (
result.begin(),
result.end(),
[](char & c) {
Expand All @@ -261,7 +259,6 @@ size_t string_to_file_size (const string &val)
if (st)
result = strtoull (st, &end, 10);


string s = string_to_lower (val);

if (s.find ("k") != string::npos)
Expand All @@ -276,7 +273,6 @@ size_t string_to_file_size (const string &val)
return result;
}


string string_file_load (const string &fname)
{
std::ifstream t (fname.c_str());
Expand Down Expand Up @@ -312,7 +308,6 @@ vector <string> vector_file_load (const string &fname)
}



string get_macro_name (const string &value)
{
size_t pos = value.find_first_of (':');
Expand All @@ -321,42 +316,3 @@ string get_macro_name (const string &value)

return value.substr (0, pos);
}



vector <string> split_string_to_vector_aware (const string& s, const string& delimeter, const bool keep_empty)
{
vector <string> result;

if (delimeter.empty())
{
result.push_back (s);
return result;
}

string::const_iterator substart = s.begin(), subend;

while (true)
{
subend = search (substart, s.end(), delimeter.begin(), delimeter.end());

string::const_iterator nxt = std::next (subend);
if (*nxt == '/')
subend = search (substart, s.end(), delimeter.begin(), delimeter.end());

string temp (substart, subend);

if (keep_empty || ! temp.empty())
result.push_back (temp);

if (subend == s.end())
break;



substart = subend + delimeter.size();
}

return result;
}

1 change: 0 additions & 1 deletion utl.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ size_t string_to_file_size (const string &val);
string string_file_load (const string &fname);
vector <string> vector_file_load (const string &fname);
string get_macro_name (const string &value);
vector <string> split_string_to_vector_aware (const string& s, const string& delimeter, const bool keep_empty);


#endif
5 changes: 0 additions & 5 deletions vars.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
//full nginx vars see at
//http://nginx.org/en/docs/varindex.html
//Apache:
//https://httpd.apache.org/docs/current/mod/mod_log_config.html

#include <fstream>
#include <iostream>
#include <sstream>
Expand Down
Loading

0 comments on commit 312699b

Please sign in to comment.