1 // Copyright (C) 2021 The Android Open Source Project 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #pragma once 16 17 #include <ctime> 18 #include <vector> 19 20 #include <ditto/timespec_utils.h> 21 22 namespace dittosuite { 23 24 template <class T> 25 class Sampler { 26 public: GetSamples()27 std::vector<T> GetSamples() const { return samples_; } 28 29 protected: 30 std::vector<T> samples_; 31 }; 32 33 class TimeSampler : public Sampler<timespec> { 34 public: 35 void MeasureStart(); 36 void MeasureEnd(); 37 38 private: 39 timespec start_; 40 timespec end_; 41 }; 42 43 class BandwidthSampler : public Sampler<double> { 44 public: 45 void Measure(size_t file_size, const timespec& duration); 46 }; 47 48 } // namespace dittosuite 49