// Copyright 2016 Google Inc. All Rights Reserved. #ifndef WVCDM_PROFILER_SESSION_H_ #define WVCDM_PROFILER_SESSION_H_ #include #include #include #include #include "circular_buffer.h" #include "entry_writer.h" #include "oem_functions.h" #include "stats.h" namespace wvcdm { namespace oemprofiler { class ProfilerSession { public: ProfilerSession(); void Submit( OEM_FUNCTION fid, uint64_t start_time, uint64_t end_time, const uint8_t* meta_data, size_t meta_data_length); // clear all samples and stats void Clear(); void ReadHistory(std::vector& output) const; void ReadAllStats(std::vector& output) const; const Stat& ReadStat(OEM_FUNCTION fid) const; static void Open(int64_t sid); static void Close(int64_t sid); static ProfilerSession* Find(int64_t sid); private: Stat stats_[OEM_FUNCTION_COUNT]; CircularBuffer buffer_; uint64_t time_at_head_; uint64_t time_at_tail_; bool RequestSpace(uint8_t num_bytes); bool ReadNextEntryRealEndTime(uint64_t* output); bool DropLastEntry(); // Read a variable length value. This is the read that matches // EntryWriter's WriteVLV. int ReadVLV(size_t offset, uint64_t* output) const; ProfilerSession(const ProfilerSession&); void operator=(const ProfilerSession&); static uint8_t GetByte(uint64_t value, size_t byte_index); static std::map sessions_; }; } // namespace oemprofiler } // namespace wvcdm #endif