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 #include <ditto/sampler.h> 16 17 #include <cmath> 18 #include <ctime> 19 20 #include <ditto/logger.h> 21 22 namespace dittosuite { 23 MeasureStart()24void TimeSampler::MeasureStart() { 25 clock_gettime(CLOCK_MONOTONIC, &start_); 26 } 27 MeasureEnd()28void TimeSampler::MeasureEnd() { 29 clock_gettime(CLOCK_MONOTONIC, &end_); 30 samples_.push_back(end_ - start_); 31 } 32 Measure(const size_t file_size,const timespec & duration)33void BandwidthSampler::Measure(const size_t file_size, const timespec& duration) { 34 double bandwidth = file_size * 1e6 / TimespecToNanos(duration); // currently bytes/milliseconds 35 bandwidth = bandwidth * 1e3 / (1 << 10); // Kb / s 36 samples_.push_back(bandwidth); 37 } 38 39 } // namespace dittosuite 40