Arduino Libraries
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
speed_report.hpp
Go to the documentation of this file.
1 // Author: Mario S. Könz <mskoenz@gmx.net>
2 // Date: 25.05.2013 21:47:03 EDT
3 // File: speed_report.hpp
4 
5 /* This program is free software. It comes without any warranty, to
6  * the extent permitted by applicable law. You can redistribute it
7  * and/or modify it under the terms of the Do What The Fuck You Want
8  * To Public License, Version 2, as published by Sam Hocevar. See
9  * http://www.wtfpl.net/ or COPYING for more details. */
10 
11 #ifndef __SPEED_REPORT_HEADER
12 #define __SPEED_REPORT_HEADER
13 
14 #include <ustd/iostream.hpp>
15 #include "../tool/clock.hpp"
16 
17 namespace diag {
19  const int lower_time_limit = 1;
20  const int upper_time_limit = 3;
21  public:
22  frequency_class(): last_print_(0), mod_(2), i_(0), n_(0) {
23  }
24  inline void speed_report() {
25  ++i_;
26  if((i_&(mod_-1)) == 0) {
27  n_ += mod_;
28  double e = tool::clock.millis();
29  if(e - last_print_ > lower_time_limit * 1000) {
30  if(e - last_print_ > upper_time_limit * 1000) {
31  mod_ >>= 1;
32  }
33 
34  auto fl = mod_ / (e - last_print_);
35  last_print_ = e;
36  auto f = n_ / e;
37 
39  ustd::cout << F("----------------------") << ustd::endl;
40  ustd::cout << F(" Speed Report ") << ustd::endl;
41  ustd::cout << F("----------------------") << ustd::endl;
42  if(f < 1)
43  ustd::cout << GREEN << F(" mean freq: ") << GREENB << f * 1000 << F(" Hz") << ustd::endl;
44  else
45  ustd::cout << YELLOW << F(" mean freq: ") << YELLOWB << f << F(" kHz") << ustd::endl;
46  if(fl < 1)
47  ustd::cout << GREEN << F(" loop freq: ") << GREENB << fl * 1000 << F(" Hz") << ustd::endl;
48  else
49  ustd::cout << YELLOW << F(" loop freq: ") << YELLOWB << fl << F(" kHz") << ustd::endl;
50  if(f < 1)
51  ustd::cout << GREEN << F(" loop time: ") << GREENB << 1 / f << F(" ms") << NONE << ustd::endl;
52  else
53  ustd::cout << YELLOW << F(" loop time: ") << YELLOWB << 1000 / f << F(" us") << NONE << ustd::endl;
54 
55  ustd::cout << F(" modulo : ") << mod_ << ustd::endl;
56  ustd::cout << F("----------------------") << ustd::endl;
57 
58  }
59  else {
60  n_ -= mod_;
61  mod_ <<= 1;
62  }
63  }
64  }
65  private:
66  double last_print_;
67  uint32_t mod_;
68  uint32_t i_;
69  double n_;
70  } freq;
71 
72  inline void speed_report() {
74  }
75 }
76 
77 #endif //__SPEED_REPORT_HEADER
#define GREEN
Definition: color.hpp:15
#define YELLOWB
Definition: color.hpp:18
class tool::clock_class clock
#define GREENB
Definition: color.hpp:16
frequency_class()
Definition: speed_report.hpp:22
Definition: speed_report.hpp:18
uint32_t millis() const
Definition: clock.hpp:35
#define NONE
Definition: color.hpp:37
struct ustd::endl_class endl
void speed_report()
Definition: speed_report.hpp:24
class diag::frequency_class freq
#define F(x)
Definition: ustd_generic.hpp:15
void speed_report()
Definition: speed_report.hpp:72
ustd::cout_class cout
#define YELLOW
Definition: color.hpp:17