* Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved.
* MindIE is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
#include "batch_latency_tracker.h"
namespace mindie_llm {
void BatchLatencyTracker::AddDataPoint(uint64_t value) {
if (queue_.size() == windowSize_) {
queue_.pop_front();
}
queue_.push_back(value);
}
double BatchLatencyTracker::GetRecentAvgLatency(size_t forwardNum) {
float minScale = 0.1;
if (queue_.size() < (forwardNum * minScale)) {
return 0;
}
size_t sumVal = 0;
size_t count = (queue_.size() < forwardNum) ? queue_.size() : forwardNum;
auto rit = queue_.rbegin();
for (size_t i = 0; i < count; ++i) {
sumVal += *rit;
++rit;
}
return static_cast<double>(sumVal) / count;
}
}