448 #ifndef STATISTICS_HPP_
449 #define STATISTICS_HPP_ 1
453 #if defined(ENABLE_STATISTICS)
461 extern bool opt_stat;
476 const char* description;
478 typedef std::deque<const StatEntry*> StatStack;
480 void print_csv_entry(OStream &O,StatStack &s,
unsigned long v)
const {
481 for(StatStack::const_iterator
i = s.begin(),
e = s.end() ;
i !=
e; ++
i) {
482 O << (*i)->name <<
'.';
490 StatEntry(
const char*
name,
const char* description) : name(name), description(description) {}
495 virtual void print(OStream &O)
const = 0;
501 void print_csv(OStream &O)
const {
503 print_csv_intern(O,s);
505 static void print_csv_header(OStream &O) {
506 O <<
"name;description;value" <<
nl;
508 virtual void print_csv_intern(OStream &O,StatStack &s)
const = 0;
513 virtual unsigned long get_value()
const {
return 0; }
515 virtual ~StatEntry() {}
523 class StatGroup :
public StatEntry {
525 typedef std::vector<StatEntry*> StatEntryList;
531 StatEntryList *members;
533 StatGroup(
const char*
name,
const char* description) : StatEntry(name, description) {
534 members =
new StatEntryList();
540 static StatGroup&
root() {
541 static StatGroup rg(
"root",
"Statistics");
551 StatGroup(
const char*
name,
const char* description, StatGroup &group) : StatEntry(name, description) {
552 members =
new StatEntryList();
563 void add(StatEntry *re) {
564 members->push_back(re);
567 virtual void print(OStream &O)
const {
568 O <<
nl << description <<
':' <<
nl;
570 for(StatEntryList::const_iterator
i = members->begin(),
e= members->end();
i !=
e; ++
i) {
577 virtual void print_csv_intern(OStream &O,StatStack &s)
const {
579 for(StatEntryList::const_iterator
i = members->begin(),
e= members->end();
i !=
e; ++
i) {
581 re->print_csv_intern(O,s);
592 class StatSumGroup :
public StatGroup {
601 StatSumGroup(
const char* name,
const char* description, StatGroup &group)
602 : StatGroup(name,description,group) {}
604 virtual void print(OStream &O)
const {
605 unsigned long sum = 0;
609 for(StatEntryList::const_iterator
i = members->begin(),
e= members->end();
i !=
e; ++
i) {
612 sum += se->get_value();
615 O <<
setw(40) <<
"-------" <<
nl;
616 O <<
setw(30) <<
"sum"
618 <<
" : " << description <<
nl;
620 virtual void print_csv_intern(OStream &O,StatStack &s)
const {
621 unsigned long sum = 0;
623 for(StatEntryList::const_iterator
i = members->begin(),
e= members->end();
i !=
e; ++
i) {
625 se->print_csv_intern(O,s);
626 sum += se->get_value();
629 print_csv_entry(O,s,sum);
632 virtual unsigned long get_value()
const {
633 unsigned long sum = 0;
634 for(StatEntryList::const_iterator
i = members->begin(),
e= members->end();
i !=
e; ++
i) {
636 sum += se->get_value();
645 template<
typename _COUNT_TYPE,
typename _INDEX_TYPE>
646 class StatDistAbst :
public StatEntry {
649 const std::size_t table_size;
651 StatDistAbst(
const char* name,
const char* description, StatGroup &
parent,
652 _INDEX_TYPE table_size, _COUNT_TYPE init)
653 : StatEntry(name, description), table_size(table_size) {
655 table =
new _COUNT_TYPE[table_size + 1];
657 for(std::size_t
i = 0;
i <= table_size; ++
i ) {
662 virtual ~StatDistAbst() {
666 virtual void print_header(OStream &O, std::size_t first, std::size_t last)
const = 0;
669 virtual void print(OStream &O)
const {
671 _COUNT_TYPE cumulated = 0;
673 for(
int first = 0, end = table_size +1, last = end;
674 first != end; first = last) {
675 if (end - first > 15) {
680 O << description <<
'(' << name << (first == 0 ?
"):" :
") (cont):") << nl;
682 print_header(O,first,last);
685 for(
int i = first;
i < last; ++
i ) {
686 O <<
setw(6) << table[
i];
690 for(
int i = first;
i < last; ++
i ) {
695 for(
int i = first;
i < last; ++
i ) {
696 cumulated += table[
i];
699 O <<
" cumulated ratio" <<
nl;
703 virtual void print_csv_intern(OStream &O,StatStack &s)
const {
714 template<
typename _COUNT_TYPE,
typename _INDEX_TYPE, _INDEX_TYPE step>
715 class StatDist :
public StatDistAbst<_COUNT_TYPE,_INDEX_TYPE> {
717 const _INDEX_TYPE start;
718 const _INDEX_TYPE end;
721 virtual void print_header(OStream &O, std::size_t first, std::size_t last)
const {
724 for(i = first; i < last && i < this->table_size; ++
i ) {
725 O <<
setw(5) << start + i * step <<
']';
727 if (i == this->table_size) {
728 O <<
'(' <<
setw(4) << start + (this->table_size-1)*step;
743 StatDist(
const char* name,
const char* description, StatGroup &parent,
744 _INDEX_TYPE start, _INDEX_TYPE end, _COUNT_TYPE init)
745 : StatDistAbst<_COUNT_TYPE,_INDEX_TYPE>(name, description, parent,
746 (end - start)/step + 1, init),
747 start(start), end(end) {
752 inline _COUNT_TYPE& operator[](
const _INDEX_TYPE i) {
754 return this->table[0];
757 return this->table[this->table_size];
759 return this->table[( (i-start)%step == 0 ? (i-start)/step : (i-start+step)/step )];
769 template<
typename _COUNT_TYPE,
typename _INDEX_TYPE>
770 class StatDistRange :
public StatDistAbst<_COUNT_TYPE,_INDEX_TYPE> {
772 const _INDEX_TYPE *range;
775 virtual void print_header(OStream &O, std::size_t first, std::size_t last)
const {
778 for(i = first; i < last && i < this->table_size; ++
i ) {
779 O <<
setw(5) << range[
i] <<
']';
781 if (i == this->table_size) {
782 O <<
'(' <<
setw(4) << range[this->table_size-1];
797 StatDistRange(
const char* name,
const char* description, StatGroup &parent,
798 const _INDEX_TYPE range[],
const int range_size, _COUNT_TYPE init)
799 : StatDistAbst<_COUNT_TYPE,_INDEX_TYPE>(name, description, parent,
804 inline _COUNT_TYPE& operator[](
const _INDEX_TYPE v) {
805 for (std::size_t i = 0; i < this->table_size; ++
i ) {
807 return this->table[
i];
809 return this->table[this->table_size];
816 template<
typename _T, _T init>
817 class StatVar :
public StatEntry {
827 StatVar(
const char* name,
const char* description, StatGroup &parent)
828 : StatEntry(name, description), var(init) {
832 virtual unsigned long get_value()
const {
833 return (
unsigned long)var;
840 void print(OStream &O)
const {
841 O <<
setw(30) << name
843 <<
" : " << description <<
nl;
845 virtual void print_csv_intern(OStream &O,StatStack &s)
const {
846 print_csv_entry(O,s,get_value());
849 inline StatVar&
max(
const _T& i) {
856 inline StatVar&
min(
const _T& i) {
863 inline StatVar& operator++() {
868 inline StatVar operator++(
int) {
874 inline StatVar& operator+=(
const _T& i) {
879 inline StatVar& operator--() {
884 inline StatVar operator--(
int) {
890 inline StatVar& operator-=(
const _T& i) {
896 inline StatVar& operator=(
const _T& i) {
908 #define STAT_DECLARE_VAR(type, var, init) \
909 extern cacao::StatVar<type,init> var;
911 #define STAT_REGISTER_VAR_EXTERN(type, var, init, name, description) \
912 cacao::StatVar<type,init> var(name,description,cacao::StatGroup::root());
914 #define STAT_REGISTER_GROUP_VAR_EXTERN(type, var, init, name, description, group) \
915 cacao::StatVar<type,init> var(name,description,group##_group());
917 #define STAT_REGISTER_VAR(type, var, init, name, description) \
918 static cacao::StatVar<type,init> var(name,description,cacao::StatGroup::root());
920 #define STAT_REGISTER_GROUP_VAR(type, var, init, name, description, group) \
921 static cacao::StatVar<type,init> var(name,description,group##_group());
923 #define STAT_REGISTER_DIST(counttype, indextype, var, start, end, step, init, name, description) \
924 static cacao::StatDist<counttype,indextype,step> var(name,description,cacao::StatGroup::root(),start,end,init);
926 #define STAT_REGISTER_DIST_RANGE(counttype, indextype, var, range, range_size, init, name, description) \
927 static cacao::StatDistRange<counttype,indextype> var(name,description,cacao::StatGroup::root(),range,range_size,init);
929 #define STAT_DECLARE_GROUP(var) \
930 cacao::StatGroup& var##_group();
932 #define STAT_DECLARE_SUM_GROUP(var) \
933 cacao::StatSumGroup& var##_group();
935 #define STAT_REGISTER_GROUP(var,name,description) \
936 cacao::StatGroup& var##_group() { \
937 static cacao::StatGroup var(name,description,cacao::StatGroup::root());\
941 #define STAT_REGISTER_SUM_GROUP(var,name,description) \
942 cacao::StatSumGroup& var##_group() { \
943 static cacao::StatSumGroup var(name,description, \
944 cacao::StatGroup::root()); \
948 #define STAT_REGISTER_SUM_SUBGROUP(var,name,description,group) \
949 cacao::StatSumGroup& var##_group() { \
950 static cacao::StatSumGroup var(name,description, group##_group()); \
954 #define STAT_REGISTER_SUBGROUP(var,name,description,group) \
955 cacao::StatGroup& var##_group() { \
956 static cacao::StatGroup var(name,description, group##_group()); \
960 #define STATISTICS(x) do { x; } while (0)
963 #define STAT_DECLARE_VAR(type, var, init)
964 #define STAT_REGISTER_VAR_EXTERN(type, var, init, name, description)
965 #define STAT_REGISTER_GROUP_VAR_EXTERN(type, var, init, name, description, group)
966 #define STAT_REGISTER_VAR(type, var, init, name, description)
967 #define STAT_REGISTER_GROUP_VAR(type, var, init, name, description, group)
968 #define STAT_REGISTER_DIST(counttype, indextype, var, start, end, step, init, name, description)
969 #define STAT_REGISTER_DIST_RANGE(counttype, indextype, var, range, range_size, init, name, description)
970 #define STAT_DECLARE_GROUP(var)
971 #define STAT_REGISTER_GROUP(var,name,description)
972 #define STAT_REGISTER_SUM_GROUP(var,name,description)
973 #define STAT_REGISTER_SUM_SUBGROUP(var,name,description,group)
974 #define STAT_REGISTER_SUBGROUP(var,name,description,group)
975 #define STATISTICS(x)
978 #ifdef ENABLE_STATISTICS
991 void statistics_print_date(
void);
992 void statistics_print_memory_usage(
void);
993 void statistics_print_gc_memory_usage(
void);
1001 #endif // STATISTICS_HPP_
static SetWidth setw(size_t w)
JNIEnv jclass jobject const char * name
static SetPrecision setprecision(int p)
void compilingtime_start(void)
void loadingtime_stop(void)
void compilingtime_stop(void)
void loadingtime_start(void)