| 1 |
/* |
| 2 |
* This File is part of Davix, The IO library for HTTP based protocols |
| 3 |
* Copyright (C) CERN 2013 |
| 4 |
* Author: Adrien Devresse <[email protected]> |
| 5 |
* |
| 6 |
* This library is free software; you can redistribute it and/or |
| 7 |
* modify it under the terms of the GNU Lesser General Public |
| 8 |
* License as published by the Free Software Foundation; either |
| 9 |
* version 2.1 of the License, or (at your option) any later version. |
| 10 |
* |
| 11 |
* This library is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 |
* Lesser General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU Lesser General Public |
| 17 |
* License along with this library; if not, write to the Free Software |
| 18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 |
* |
| 20 |
*/ |
| 21 |
|
| 22 |
#include <cstdlib> |
| 23 |
#include <davix.hpp> |
| 24 |
#include <utils/davix_logger_internal.hpp> |
| 25 |
|
| 26 |
using namespace Davix; |
| 27 |
|
| 28 |
|
| 29 |
PerformanceMarker::PerformanceMarker(): |
| 30 |
index(0), count(0), begin(0), latest(0), |
| 31 |
transferred(0), |
| 32 |
transferAvg(0), transferInstant(0) |
| 33 |
{ |
| 34 |
// Nothing |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
PerformanceData::PerformanceData(): |
| 40 |
begin(0), latest(0), |
| 41 |
ipflag(IPtype::undefined), |
| 42 |
markers() |
| 43 |
{ |
| 44 |
// Nothing |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
PerformanceData::~PerformanceData() |
| 50 |
{ |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
void PerformanceData::update(const PerformanceMarker& in) |
| 55 |
{ |
| 56 |
if(in.count > 8192) { |
| 57 |
DAVIX_SLOG(DAVIX_LOG_WARNING, DAVIX_LOG_GRID, "Received unreasonably high number of stripes, something is wrong: {}", in.count); |
| 58 |
return; |
| 59 |
} |
| 60 |
|
| 61 |
if (markers.size() != in.count) |
| 62 |
markers.resize(in.count); |
| 63 |
|
| 64 |
if (in.index < 0 || in.index >= markers.size()) |
| 65 |
return; |
| 66 |
|
| 67 |
PerformanceMarker& marker = markers[in.index]; |
| 68 |
|
| 69 |
if (marker.begin == 0) |
| 70 |
marker.begin = in.latest; |
| 71 |
|
| 72 |
// Calculate differences |
| 73 |
time_t absElapsed = in.latest - marker.begin; |
| 74 |
time_t diffElapsed = in.latest - marker.latest; |
| 75 |
off_t diffSize = in.transferred - marker.transferred; |
| 76 |
|
| 77 |
// Update |
| 78 |
marker.index = in.index; |
| 79 |
marker.count = in.count; |
| 80 |
marker.latest = in.latest; |
| 81 |
marker.transferred = in.transferred; |
| 82 |
if (absElapsed) |
| 83 |
marker.transferAvg = marker.transferred / absElapsed; |
| 84 |
if (diffElapsed) |
| 85 |
marker.transferInstant = diffSize / diffElapsed; |
| 86 |
|
| 87 |
if (begin == 0 || begin < marker.begin) |
| 88 |
begin = marker.begin; |
| 89 |
if (latest < marker.latest) |
| 90 |
latest = marker.latest; |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
time_t PerformanceData::absElapsed() const |
| 96 |
{ |
| 97 |
return latest - begin; |
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
off_t PerformanceData::avgTransfer(void) const |
| 103 |
{ |
| 104 |
off_t total = 0; |
| 105 |
for (int i = 0; i < markers.size(); ++i) |
| 106 |
total += markers[i].transferAvg; |
| 107 |
return total; |
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
off_t PerformanceData::diffTransfer() const |
| 113 |
{ |
| 114 |
off_t total = 0; |
| 115 |
for (size_t i = 0; i < markers.size(); ++i) |
| 116 |
total += markers[i].transferInstant; |
| 117 |
return total; |
| 118 |
} |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
off_t PerformanceData::totalTransferred() const |
| 123 |
{ |
| 124 |
off_t total = 0; |
| 125 |
for (size_t i = 0; i < markers.size(); ++i) |
| 126 |
total += markers[i].transferred; |
| 127 |
return total; |
| 128 |
} |