kakoune

Fork of kakoune, an acceptable text editor
git clone git://git.laack.co/kakoune.git
Log | Files | Refs

profile.hh (756B)


      1 #ifndef profile_hh_INCLUDED
      2 #define profile_hh_INCLUDED
      3 
      4 #include "clock.hh"
      5 #include "context.hh"
      6 #include "debug.hh"
      7 
      8 namespace Kakoune
      9 {
     10 
     11 template<typename Callback>
     12 class ProfileScope
     13 {
     14 public:
     15     ProfileScope(const DebugFlags debug_flags, Callback&& callback, bool active = true)
     16       : m_active{active and debug_flags & DebugFlags::Profile},
     17         m_start_time(m_active ? Clock::now() : Clock::time_point{}),
     18         m_callback{std::move(callback)}
     19     {}
     20 
     21     ~ProfileScope()
     22     {
     23         if (m_active)
     24             m_callback(std::chrono::duration_cast<std::chrono::microseconds>(Clock::now() - m_start_time));
     25     }
     26 
     27 private:
     28     bool m_active;
     29     Clock::time_point m_start_time;
     30     Callback m_callback;
     31 };
     32 
     33 }
     34 
     35 #endif // profile_hh_INCLUDED