some logging shizzle
This commit is contained in:
parent
aee4b7204a
commit
6d3cf83dc0
4 changed files with 62 additions and 14 deletions
|
@ -37,11 +37,12 @@ public:
|
|||
}
|
||||
|
||||
void init_range() {
|
||||
ProgressIndicator p(LOG_VERBOSE, std::cout, "searching for parameters");
|
||||
for(unsigned int i = 0; i < 1000000; i++) {
|
||||
iterate();
|
||||
if(kernel->convergent() || kernel->divergent()){
|
||||
kernel->generate_random_parameters();
|
||||
LogDebug("Generating new parameters.\n");
|
||||
p.update();
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
|
@ -49,6 +50,9 @@ public:
|
|||
|
||||
void iterate() {
|
||||
(*kernel)();
|
||||
}
|
||||
|
||||
void project() {
|
||||
projector->plot(kernel->vector());
|
||||
}
|
||||
|
||||
|
|
58
Logger.hpp
58
Logger.hpp
|
@ -22,22 +22,32 @@ extern int verbose;
|
|||
#define LogError(s, ...) \
|
||||
if ( verbose >= 0 ) { printf("%s, %s(), %d: ", __FILE__, __func__, __LINE__); printf(s, ##__VA_ARGS__); }
|
||||
|
||||
enum LoggingLevels {
|
||||
LOG_ERROR,
|
||||
LOG_INFO,
|
||||
LOG_VERBOSE,
|
||||
LOG_DEBUG
|
||||
};
|
||||
|
||||
/*
|
||||
Imported from Astrant:
|
||||
Questions/Suggestions mail nick@astrant.net
|
||||
*/
|
||||
|
||||
struct Logger {
|
||||
Logger(std::ostream& logging_stream_, std::string prefix_ = std::string(""))
|
||||
Logger(LoggingLevels level, std::ostream& logging_stream_, std::string prefix_ = std::string(""))
|
||||
: logging_stream(&logging_stream_)
|
||||
, prefix(prefix_)
|
||||
, level(level)
|
||||
{}
|
||||
|
||||
void log(std::string what){
|
||||
if (verbose < level) return;
|
||||
*logging_stream << get_prefix() << "(" << what << ") took place at (" << boost::posix_time::microsec_clock::local_time() << std::endl;
|
||||
}
|
||||
|
||||
void start(std::string what){
|
||||
if (verbose < level) return;
|
||||
Event e;
|
||||
e.start = boost::posix_time::microsec_clock::local_time();
|
||||
e.name = what;
|
||||
|
@ -53,6 +63,7 @@ struct Logger {
|
|||
}
|
||||
|
||||
void stop() {
|
||||
if (verbose < level) return;
|
||||
assert(!event_name_stack.empty());
|
||||
stop(event_name_stack.top());
|
||||
}
|
||||
|
@ -99,6 +110,8 @@ private:
|
|||
return prefix + ": ";
|
||||
}
|
||||
}
|
||||
|
||||
LoggingLevels level;
|
||||
};
|
||||
|
||||
/*
|
||||
|
@ -106,12 +119,14 @@ private:
|
|||
*/
|
||||
|
||||
struct Progressbar {
|
||||
Progressbar(std::ostream & out, std::string prefix = "", std::string begin = "", std::string end = "")
|
||||
Progressbar(LoggingLevels level, std::ostream & out, std::string prefix = "", std::string begin = "", std::string end = "")
|
||||
: out(out)
|
||||
, begin(begin)
|
||||
, prefix(prefix)
|
||||
, end(end)
|
||||
, level(level)
|
||||
{
|
||||
if (verbose < level) return;
|
||||
if (begin != "") {
|
||||
out << begin << std::endl;
|
||||
}
|
||||
|
@ -120,6 +135,7 @@ struct Progressbar {
|
|||
}
|
||||
|
||||
~Progressbar(){
|
||||
if (verbose < level) return;
|
||||
show(1, 1, '=');
|
||||
|
||||
if (end != "") {
|
||||
|
@ -130,10 +146,11 @@ struct Progressbar {
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
void show(T const & progress, T const & max, char delim = '>'){
|
||||
void show(T const & progress, T const & max, char delim = '>', char filling = '='){
|
||||
if (verbose < level) return;
|
||||
out << "\r";
|
||||
|
||||
size_t width = 80; // default terminal size :D
|
||||
size_t width = 79; // default terminal size :D
|
||||
width -= prefix.size();
|
||||
width -= 3; // [, > and ]
|
||||
|
||||
|
@ -145,7 +162,7 @@ struct Progressbar {
|
|||
double ratio = (double) progress / (double) max;
|
||||
size_t length = width * ratio;
|
||||
|
||||
std::string fill(length, '=');
|
||||
std::string fill(length, filling);
|
||||
std::string empty(width - length, ' ');
|
||||
out << '[' << fill << delim << empty << ']' << std::flush;
|
||||
}
|
||||
|
@ -155,6 +172,37 @@ private:
|
|||
std::string begin;
|
||||
std::string prefix;
|
||||
std::string end;
|
||||
|
||||
LoggingLevels level;
|
||||
};
|
||||
|
||||
struct ProgressIndicator : private Progressbar {
|
||||
ProgressIndicator(LoggingLevels level, std::ostream & out, std::string prefix = "", std::string begin = "", std::string end = "")
|
||||
: Progressbar(level, out, prefix, begin, end)
|
||||
, progress(0.0)
|
||||
, backwards(false)
|
||||
{}
|
||||
|
||||
void update(double dt = 0.037){
|
||||
if(!backwards){
|
||||
progress += dt;
|
||||
if(progress >= 1.0){
|
||||
progress = 1.0;
|
||||
backwards = true;
|
||||
}
|
||||
} else {
|
||||
progress -= dt;
|
||||
if(progress <= 0.0){
|
||||
progress = 0.0;
|
||||
backwards = false;
|
||||
}
|
||||
}
|
||||
show(progress, 1.0, backwards ? '<' : '>', ' ');
|
||||
}
|
||||
|
||||
private:
|
||||
double progress;
|
||||
bool backwards;
|
||||
};
|
||||
|
||||
|
||||
|
|
10
main.cpp
10
main.cpp
|
@ -17,7 +17,7 @@
|
|||
#include <boost/program_options.hpp>
|
||||
namespace po = boost::program_options;
|
||||
|
||||
int verbose = 3;
|
||||
int verbose = 4;
|
||||
|
||||
std::string generate_filename(){
|
||||
char filename[64];
|
||||
|
@ -29,10 +29,11 @@ std::string generate_filename(){
|
|||
}
|
||||
|
||||
void render(Attractor & myAttractor, Canvas2D & canvas, unsigned int iterations){
|
||||
Progressbar progress(std::cout, "rendering");
|
||||
Progressbar progress(LOG_INFO, std::cout, "rendering");
|
||||
for(unsigned int j = 1; j <= iterations; ++j) {
|
||||
for(unsigned int i = 0; i < 1000000; ++i) {
|
||||
myAttractor.iterate();
|
||||
myAttractor.project();
|
||||
canvas.plot(myAttractor.projector->projectedPoint);
|
||||
}
|
||||
progress.show(j, iterations);
|
||||
|
@ -40,9 +41,6 @@ void render(Attractor & myAttractor, Canvas2D & canvas, unsigned int iterations)
|
|||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
LogInfo("Awesome Attractor, version %s\n", __DATE__);
|
||||
|
||||
verbose = 0;
|
||||
std::string attractorFile;
|
||||
std::string output_path;
|
||||
bool generate_random = false;
|
||||
|
@ -79,7 +77,7 @@ int main(int argc, char* argv[]) {
|
|||
|
||||
std::string filename = output_path + generate_filename();
|
||||
|
||||
Logger logger(std::cout);
|
||||
Logger logger(LOG_VERBOSE, std::cout);
|
||||
Canvas2D canvas(width, height);
|
||||
{
|
||||
Attractor* my_attractor_ptr = 0;
|
||||
|
|
|
@ -97,8 +97,6 @@ void Normalizer::finish_range() {
|
|||
double dist = range_max[i] - range_min[i];
|
||||
if(factor * dist > 1.0) {
|
||||
factor = 1.0 / dist;
|
||||
//teh_size = canvas->size[i];
|
||||
LogDebug("Crap for dimension %d\n", i);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue