8#ifndef ARCANE_PERFCOUNTERMNG_H_
9#define ARCANE_PERFCOUNTERMNG_H_
24#ifdef ACTIVATE_PERF_COUNTER
25#define CHECKPERF(instruction) (instruction);
27#define CHECKPERF(instruction)
39#if defined(__x86_64__)
41static inline void rdtsc(
volatile unsigned long long int* counter)
44 asm volatile(
"rdtsc \n\t"
47 :
"=m"(((
unsigned*)counter)[0]),
"=m"(((
unsigned*)counter)[1])
52#define RDTSC(X) asm volatile("rdtsc \n\t" \
53 "movl %%eax,%0 \n\t" \
54 "movl %%edx,%1 \n\t" \
55 : "=m"(((unsigned*)(X))[0]), "=m"(((unsigned*)(X))[1]) \
61#pragma intrinsic(__rdtsc)
63static inline void rdtsc(
volatile unsigned long long int* counter)
68#define RDTSC(X) *X = __rdtsc()
75static inline void rdtsc(
volatile unsigned long long int* counter)
88template <
typename PerfCounterT>
93 typedef unsigned long long int ValueType;
94 typedef typename PerfCounterT::eType PhaseType;
95 typedef std::pair<ValueType, ValueType> CountType;
96 typedef std::vector<CountType> CountListType;
102 m_counts.resize(PerfCounterT::NbCounters);
106 virtual ~PerfCounterMng() {}
110 for (std::size_t i = 0; i < m_counts.size(); ++i) {
111 m_counts[i].first = 0;
112 m_counts[i].second = 0;
116 void init(PhaseType
const& phase)
118 CountType& count = m_counts[phase];
122 void start(PhaseType
const& phase)
124 rdtsc(&m_counts[phase].second);
126 void stop(PhaseType
const& phase)
128 CountType& count = m_counts[phase];
129 rdtsc(&m_last_value);
130 m_last_value = m_last_value - count.second;
131 count.first += m_last_value;
134 ValueType getLastValue()
139 ValueType getValue(PhaseType
const& phase)
141 return m_counts[phase].first;
144 double getValueInSeconds(PhaseType
const& phase)
146 return m_counts[phase].first / m_cpu_frec * 1E-6;
149 void printInfo()
const
151 std::cout <<
"PERF INFO : " << std::endl;
152 std::cout << std::setw(10) <<
"COUNT" <<
" : " <<
"VALUE" << std::endl;
154 for (std::size_t i = 0; i < m_counts.size(); ++i) {
155 std::cout << std::setw(10) << PerfCounterT::m_names[i] <<
" : " << m_counts[i].first / m_cpu_frec * 1E-6 <<
'\n';
159 void printInfo(std::ostream& stream)
const
161 stream <<
"PERF INFO : " << std::endl;
162 stream << std::setw(10) <<
"COUNT" <<
" : " <<
"VALUE" << std::endl;
164 for (std::size_t i = 0; i < m_counts.size(); ++i) {
165 stream << std::setw(10) << PerfCounterT::m_names[i] <<
" : " << m_counts[i].first / m_cpu_frec * 1E-6 <<
'\n';
171 ValueType m_last_value;
172 CountListType m_counts;
186#define CHECKPERF(instruction)
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
int arcaneGetCpuBaseFrequency()
Returns the CPU frequency in MHz.