diff --git a/libwvdrmengine/cdm/Android.mk b/libwvdrmengine/cdm/Android.mk index 809c94cb..5645d69e 100644 --- a/libwvdrmengine/cdm/Android.mk +++ b/libwvdrmengine/cdm/Android.mk @@ -38,7 +38,6 @@ LOCAL_SRC_FILES := \ $(PROFILER_SRC_DIR)/circular_buffer.cpp \ $(PROFILER_SRC_DIR)/entry_writer.cpp \ $(PROFILER_SRC_DIR)/profiled_scope.cpp \ - $(PROFILER_SRC_DIR)/stats.cpp \ $(PROFILER_SRC_DIR)/profiler.cpp \ $(PROFILER_SRC_DIR)/call_table.cpp \ $(PROFILER_SRC_DIR)/call_history.cpp diff --git a/libwvdrmengine/cdm/profiler/include/profiler_session.h b/libwvdrmengine/cdm/profiler/include/profiler_session.h deleted file mode 100644 index a362ae17..00000000 --- a/libwvdrmengine/cdm/profiler/include/profiler_session.h +++ /dev/null @@ -1,73 +0,0 @@ -// 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 diff --git a/libwvdrmengine/cdm/profiler/include/stats.h b/libwvdrmengine/cdm/profiler/include/stats.h deleted file mode 100644 index 831359fe..00000000 --- a/libwvdrmengine/cdm/profiler/include/stats.h +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2016 Google Inc. All Rights Reserved. - -#ifndef WVCDM_PROFILER_STATS_H_ -#define WVCDM_PROFILER_STATS_H_ - -#include - -namespace wvcdm { -namespace oemprofiler { - -class Stat { - public: - Stat(); - - void Update(uint64_t sample); - void Reset(); - - uint64_t GetMin() const; - uint64_t GetMax() const; - uint64_t GetSampleSize() const; - double GetMean() const; - double GetVariance() const; - - private: - uint64_t min_; - uint64_t max_; - double mean_; - uint64_t count_; - - double sdev_m_; - double sdev_s_; - - Stat(const Stat&); - void operator=(const Stat&); -}; - -} // namespace oemprofiler -} // namespace wvcdm - -#endif diff --git a/libwvdrmengine/cdm/profiler/src/profiler_session.cpp b/libwvdrmengine/cdm/profiler/src/profiler_session.cpp deleted file mode 100644 index 254ad59d..00000000 --- a/libwvdrmengine/cdm/profiler/src/profiler_session.cpp +++ /dev/null @@ -1,229 +0,0 @@ -// Copyright 2016 Google Inc. All Rights Reserved. - -#include "profiler_session.h" - -#include - -namespace wvcdm { -namespace oemprofiler { - -namespace { - const size_t kProfilingMemoryBudget = 1024; // 1 KB -} - -std::map ProfilerSession::sessions_; - -ProfilerSession::ProfilerSession() : - buffer_(kProfilingMemoryBudget), - time_at_head_(0), - time_at_tail_(0) { - - Clear(); -} - -void ProfilerSession::Submit( - OEM_FUNCTION fid, - uint64_t start_time, - uint64_t end_time, - const uint8_t* meta_data, - size_t meta_data_length) { - - EntryWriter header; - header.WriteU8(fid); - header.WriteVLV(start_time - time_at_tail_); - header.WriteVLV(end_time - start_time); - - const size_t total_packet_size = header.GetSize() + meta_data_length; - - // The max size for a VLV is 8 bytes and the max size for a entry - // writer is 32 bytes. Normally the meta data will be packed using - // an entry writer so the max packet size will be 64 bytes. Since the - // packet size is encoded with a single byte, the packet must first - // be checked to ensure it is not too large for the cast. - if (total_packet_size <= 255 && RequestSpace(total_packet_size + 1)) { - buffer_.AddU8(static_cast(total_packet_size)); - buffer_.AddU8s(header.GetData(), header.GetSize()); - buffer_.AddU8s(meta_data, meta_data_length); - - time_at_tail_ = end_time; - } - - stats_[fid].Update(end_time - start_time); -} - -void ProfilerSession::Clear(){ - buffer_.Remove(buffer_.GetUsedSpace()); - - // the buffer is cleared so we reseting these values is clean and safe - time_at_tail_ = time_at_head_ = 0; - - for (size_t i = 0; i < OEM_FUNCTION_COUNT; i++) { - stats_[i].Reset(); - } -} - -void ProfilerSession::ReadHistory(std::vector& output) const { - // write the tail time - for (size_t i = 1; i <= sizeof(time_at_head_); i++) { - output.push_back(GetByte(time_at_head_, sizeof(time_at_head_) - i)); - } - - // write the whole circular buffer into the output buffer - const size_t num_bytes = buffer_.GetUsedSpace(); - for (size_t i = 0; i < num_bytes; i++) { - uint8_t b; - if (buffer_.PeekU8(i, &b)) { - output.push_back(b); - } - } -} - -void ProfilerSession::ReadAllStats(std::vector& output) const { - - uint64_t values_to_write[7]; - EntryWriter writer; - - const size_t num_values_to_write = - sizeof(values_to_write) / sizeof(values_to_write[0]); - - // make sure there is enough room - output.reserve( - output.size() + OEM_FUNCTION_COUNT * sizeof(values_to_write)); - - for(size_t fid = 0; fid < OEM_FUNCTION_COUNT; fid++) { - const Stat& stat = stats_[fid]; - - values_to_write[0] = stat.GetSampleSize(); - values_to_write[1] = stat.GetMin(); - values_to_write[2] = stat.GetMax(); - values_to_write[3] = static_cast(stat.GetMean()); - values_to_write[4] = static_cast(stat.GetMean() * 100) % 100; - values_to_write[5] = static_cast(stat.GetVariance()); - values_to_write[6] = static_cast(stat.GetVariance() * 100) % 100; - - for (size_t i = 0; i < num_values_to_write; i++) { - writer.Clear(); - writer.WriteU64(values_to_write[i]); - - for (size_t w_index = 0; w_index < writer.GetSize(); w_index++) { - output.push_back(writer.GetData()[w_index]); - } - } - } -} - -const Stat& ProfilerSession::ReadStat(OEM_FUNCTION fid) const { - return stats_[fid]; -} - -bool ProfilerSession::RequestSpace(uint8_t num_bytes) { - // check if it is possible to make enough room - const size_t buffer_size = buffer_.GetFreeSpace() + - buffer_.GetUsedSpace(); - - if (num_bytes > buffer_size) { - LOGE("Requesting more space than possible (requested = %u, max = %zu)", - num_bytes, buffer_size); - return false; - } - - // drop entries until we have enough space - while (num_bytes > buffer_.GetFreeSpace() && DropLastEntry()); - - return num_bytes <= buffer_.GetFreeSpace(); -} - -bool ProfilerSession::ReadNextEntryRealEndTime(uint64_t* output) { - if (output == NULL) { - LOGE("Cannout output to null pointer"); - return false; - } - - size_t initial_time_start_index = 2; - - uint64_t initial_time; - const int initial_time_length = - ReadVLV(initial_time_start_index, &initial_time); - - if (initial_time_length == -1) { - LOGE("Failed to read the start time for head entry"); - return false; - } - - uint64_t delta_time; - const int delta_time_length = ReadVLV( - initial_time_start_index + initial_time_length, &delta_time); - - if (delta_time_length == -1) { - LOGE("Failed to read the delta time for head entry"); - return false; - } - - *output = time_at_head_ + initial_time + delta_time; - return true; -} - -bool ProfilerSession::DropLastEntry() { - uint8_t entry_size; - uint64_t end_time; - - if(buffer_.PeekU8(0, &entry_size) && ReadNextEntryRealEndTime(&end_time)) { - // + 1 because the entry size byte needs to be removed too - if (buffer_.Remove(entry_size + 1)) { - time_at_head_ = end_time; - return true; - } - } - - return false; -} - -int ProfilerSession::ReadVLV(size_t offset, uint64_t* output) const { - uint8_t first_byte; - if (buffer_.PeekU8(offset, &first_byte)) { - const size_t num_bytes = (first_byte >> 5) + 1; - - uint64_t value = first_byte & 0x1F; - for (size_t i = 1; i < num_bytes; i++) { - uint8_t next_byte; - if (buffer_.PeekU8(offset + i, &next_byte)) { - value = value << 8 | next_byte; - } else { - return -1; - } - } - - *output = value; - return num_bytes; - } - - return -1; -} - -uint8_t ProfilerSession::GetByte(uint64_t value, size_t byte_index) { - return (uint8_t)(0xFF & (value >> (byte_index * 8))); -} - -void ProfilerSession::Open(int64_t sid) { - if (sessions_.count(sid) == 0) { - sessions_.insert( - std::pair(sid, new ProfilerSession())); - } -} - -void ProfilerSession::Close(int64_t sid) { - if(sessions_.count(sid) > 0) { - ProfilerSession* session = sessions_.at(sid); - sessions_.erase(sid); - - delete session; - } -} - -ProfilerSession* ProfilerSession::Find(int64_t sid) { - return sessions_.count(sid) > 0 ? sessions_.at(sid) : NULL; -} - -} // namespace wvcdm -} // namespace oemprofiler - diff --git a/libwvdrmengine/cdm/profiler/src/stats.cpp b/libwvdrmengine/cdm/profiler/src/stats.cpp deleted file mode 100644 index 01b1383d..00000000 --- a/libwvdrmengine/cdm/profiler/src/stats.cpp +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright 2016 Google Inc. All Rights Reserved. - -#include "stats.h" - -#include -#include - -namespace wvcdm { -namespace oemprofiler { - -Stat::Stat() { - Reset(); -} - -void Stat::Update(uint64_t sample) { - min_ = std::min(min_, sample); - max_ = std::max(max_, sample); - - mean_ = ((mean_ * count_) + sample) / (count_ + 1.0); - count_ += 1; - - // Welford's method for standard deviation / variance - const double old_sdev_m = sdev_m_; - const double old_sdev_s = sdev_s_; - - sdev_m_ = old_sdev_m + (sample - old_sdev_m) / count_; - sdev_s_ = old_sdev_s + (sample - sdev_m_) * (sample - old_sdev_m); -} - -void Stat::Reset() { - min_ = std::numeric_limits::max(); - max_ = count_ = 0; - - mean_ = sdev_m_ = sdev_s_ = 0.0; -} - -uint64_t Stat::GetMin() const { return min_; } - -uint64_t Stat::GetMax() const { return max_; } - -uint64_t Stat::GetSampleSize() const { return count_; } - -double Stat::GetMean() const { return mean_; } - -double Stat::GetVariance() const { - return count_ > 1 ? sdev_s_ / (count_ - 1) : 0; -} - -} // namespace oemprofiler -} // namespace wvcdm