1 // ========================================================================== 2 // $Source: /var/lib/cvs/Givaro/src/kernel/system/givperf.h,v $ 3 // Copyright(c)'1994-2009 by The Givaro group 4 // This file is part of Givaro. 5 // Givaro is governed by the CeCILL-B license under French law 6 // and abiding by the rules of distribution of free software. 7 // see the COPYRIGHT file for more details. 8 // Authors: T. Gautier 9 // $Id: givperf.h,v 1.3 2011-02-02 16:23:56 briceboyer Exp $ 10 // ========================================================================== 11 /** @file givperf.h 12 * @ingroup system 13 * @brief performance analysis 14 */ 15 #ifndef __GIVARO_perf_H 16 #define __GIVARO_perf_H 17 18 #ifdef GIVARO_PERF 19 #include <stddef> 20 #include <iostream> 21 22 namespace Givaro { 23 24 //! cout counter 25 struct __CoutCounter { 26 void (*print)(ostream&); __CoutCounter__CoutCounter27 __CoutCounter( void (*prn)(ostream& ) ) : print(prn) 28 { 29 cout << "New Counter" << endl; 30 } ~__CoutCounter__CoutCounter31 ~__CoutCounter( ) 32 { 33 cout << "Destroy a counter" << endl; 34 (*print)(cout << endl); cout << endl; 35 } 36 }; 37 38 } // namespace Givaro 39 40 41 namespace Givaro { 42 /*!@internal 43 * @brief Class that store a set of counters. 44 * - _count_cstor: \#cstor calls except the recopy constructor calls 45 * - _count_cstor_recopy: \#recopy cstor calls 46 * - _count_assign: \#assignment calls 47 * - _count_dstor: \#dstor calls 48 * . 49 */ 50 51 #define GIVARO_PERF_DEFCLASS(Name,Type) \ 52 template<class Type> \ 53 struct _Giv_perf##Name { \ 54 static size_t _count_cstor; \ 55 static size_t _count_cstor_recopy; \ 56 static size_t _count_assign; \ 57 static size_t _count_dstor; \ 58 static void print(ostream& o); \ 59 static __CoutCounter _coutcout; \ 60 _Giv_perf##Name() { ++_count_cstor; } \ 61 _Giv_perf##Name(const _Giv_perf##Name<Type>& S ) \ 62 { ++_count_cstor_recopy; } \ 63 ~_Giv_perf##Name() { ++_count_dstor; } \ 64 _Giv_perf##Name<Type>& operator=(const _Giv_perf##Name<Type>& S ) \ 65 { ++_count_assign; } \ 66 }; \ 67 template<class Type> \ 68 size_t _Giv_perf##Name<Type>::_count_cstor =0; \ 69 template<class Type> \ 70 size_t _Giv_perf##Name<Type>::_count_cstor_recopy =0; \ 71 template<class Type> \ 72 size_t _Giv_perf##Name<Type>::_count_assign =0; \ 73 template<class Type> \ 74 size_t _Giv_perf##Name<Type>::_count_dstor =0; \ 75 template<class Type> \ 76 void _Giv_perf##Name<Type>::print(ostream& o ) { \ 77 o << #Name ": #cstor=" << _count_cstor \ 78 << ", #recopy=" << _count_cstor_recopy \ 79 << ", #destor=" << _count_dstor \ 80 << ", #assign=" << _count_assign; \ 81 } \ 82 template<class Type> \ 83 __CoutCounter _Giv_perf##Name<Type>::_coutcout= &_Giv_perf##Name<Type>::print; 84 85 #define GIVARO_PERF_CSTOR(Name,Type) _Giv_perf##Name<Type>::_count_cstor++; 86 #define GIVARO_PERF_RECOPY(Name,Type) _Giv_perf##Name<Type>::_count_cstor_recopy++; 87 #define GIVARO_PERF_DSTOR(Name,Type) _Giv_perf##Name<Type>::_count_dstor++; 88 #define GIVARO_PERF_ASSIGN(Name,Type) _Giv_perf##Name<Type>::_count_assign++; 89 90 #define GIVARO_PERF_INEHERIT(Name,Type) \ 91 : public _Giv_perf##Name<Type> 92 93 #define GIVARO_PERF_DISPLAY(Name,Type) _Giv_perf##Name<Type>::print(cout), cout << endl; 94 95 } // namespace Givaro 96 97 #else // #ifdef GIVARO_PERF 98 99 // namespace Givaro { 100 101 #define GIVARO_PERF_DEFCLASS(N,T) 102 #define GIVARO_PERF_INEHERIT(N,T) 103 #define GIVARO_PERF_CSTOR(Name,Type) 104 #define GIVARO_PERF_RECOPY(Name,Type) 105 #define GIVARO_PERF_DSTOR(Name,Type) 106 #define GIVARO_PERF_ASSIGN(Name,Type) 107 #define GIVARO_PERF_DISPLAY(Name,Type) 108 109 // } // namespace Givaro 110 111 #endif 112 #endif // __GIVARO_perf_H 113 114 /* -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 115 // vim:sts=4:sw=4:ts=4:et:sr:cino=>s,f0,{0,g0,(0,\:0,t0,+0,=s 116