libcryfs/impl/Profiler.h

33 lines
947 B
C
Raw Normal View History

2015-10-15 13:04:57 +02:00
#pragma once
#ifndef MESSMER_FSPP_IMPL_PROFILER_H
#define MESSMER_FSPP_IMPL_PROFILER_H
2015-09-29 21:47:50 +02:00
#include <atomic>
#include <chrono>
2015-10-17 20:35:17 +02:00
#include <messmer/cpp-utils/macros.h>
2015-09-29 21:47:50 +02:00
namespace fspp {
class Profiler {
public:
Profiler(std::atomic_uint_fast64_t *targetForAddingNanosec);
~Profiler();
private:
std::atomic_uint_fast64_t *_targetForAddingNanosec;
std::chrono::high_resolution_clock::time_point _beginTime;
2015-10-17 20:35:17 +02:00
DISALLOW_COPY_AND_ASSIGN(Profiler);
2015-09-29 21:47:50 +02:00
};
inline Profiler::Profiler(std::atomic_uint_fast64_t *targetForAddingNanosec)
: _targetForAddingNanosec(targetForAddingNanosec), _beginTime(std::chrono::high_resolution_clock::now()) {
}
inline Profiler::~Profiler() {
uint64_t timeDiff = std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::high_resolution_clock::now() - _beginTime).count();
*_targetForAddingNanosec += timeDiff;
}
}
#endif