代码拉取完成,页面将自动刷新
同步操作将从 src-openEuler/iSulad 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
From 3dc12d7806fda8d5ceee183595e993079bee4056 Mon Sep 17 00:00:00 2001
From: jikai <jikai11@huawei.com>
Date: Fri, 12 Jan 2024 17:38:09 +0800
Subject: [PATCH 11/26] add cpu usage nano cores for sandbox
Signed-off-by: jikai <jikai11@huawei.com>
---
.../v1/v1_cri_pod_sandbox_manager_service.cc | 17 ++++++++++++++---
.../cri/v1/v1_cri_pod_sandbox_manager_service.h | 1 +
2 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/src/daemon/entry/cri/v1/v1_cri_pod_sandbox_manager_service.cc b/src/daemon/entry/cri/v1/v1_cri_pod_sandbox_manager_service.cc
index a0c45111..76fa17bc 100644
--- a/src/daemon/entry/cri/v1/v1_cri_pod_sandbox_manager_service.cc
+++ b/src/daemon/entry/cri/v1/v1_cri_pod_sandbox_manager_service.cc
@@ -1024,6 +1024,7 @@ void PodSandboxManagerService::PodSandboxStatsToGRPC(const std::string &id, cons
const std::vector<Network::NetworkInterfaceStats> &netMetrics,
const std::unique_ptr<ContainerManagerService> &containerManager,
std::unique_ptr<runtime::v1::PodSandboxStats> &podStats,
+ sandbox::StatsInfo &oldStatsRec,
Errors &error)
{
std::unique_ptr<runtime::v1::PodSandboxStats> podStatsPtr(
@@ -1044,8 +1045,13 @@ void PodSandboxManagerService::PodSandboxStatsToGRPC(const std::string &id, cons
auto cpu = podStatsPtr->mutable_linux()->mutable_cpu();
cpu->set_timestamp(timestamp);
cpu->mutable_usage_core_nano_seconds()->set_value(cgroupMetrics.cgcpu_metrics.cpu_use_nanos);
- // todo
- // cpu->mutable_usage_nano_cores()->set_value(getNanoCores());
+ if (oldStatsRec.cpuUseNanos != 0 && timestamp > oldStatsRec.timestamp &&
+ cgroupMetrics.cgcpu_metrics.cpu_use_nanos > oldStatsRec.cpuUseNanos) {
+ uint64_t usage = cgroupMetrics.cgcpu_metrics.cpu_use_nanos - oldStatsRec.cpuUseNanos;
+ uint64_t nanoSeconds = timestamp - oldStatsRec.timestamp;
+ uint64_t usage_nano_cores = (uint64_t)(((double)usage / (double)nanoSeconds) * (double)Time_Second);
+ cpu->mutable_usage_nano_cores()->set_value(usage_nano_cores);
+ }
// Memory
auto memory = podStatsPtr->mutable_linux()->mutable_memory();
@@ -1114,6 +1120,7 @@ auto PodSandboxManagerService::PodSandboxStats(const std::string &podSandboxID,
return nullptr;
}
auto &config = sandbox->GetSandboxConfig();
+ auto oldStatsRec = sandbox->GetStatsInfo();
auto status = PodSandboxStatus(sandbox->GetId(), tmpErr);
if (error.NotEmpty()) {
@@ -1136,13 +1143,17 @@ auto PodSandboxManagerService::PodSandboxStats(const std::string &podSandboxID,
tmpErr.Clear();
}
- PodSandboxStatsToGRPC(sandbox->GetId(), cgroupMetrics, netMetrics, containerManager, podStats, tmpErr);
+ PodSandboxStatsToGRPC(sandbox->GetId(), cgroupMetrics, netMetrics, containerManager, podStats, oldStatsRec, tmpErr);
if (tmpErr.NotEmpty()) {
ERROR("Failed to set PodSandboxStats: %s", tmpErr.GetCMessage());
error.Errorf("Failed to set PodSandboxStats");
return nullptr;
}
+ // update stats info that sandbox recorded
+ sandbox::StatsInfo newStatsRec { podStats->linux().cpu().timestamp(), podStats->linux().cpu().usage_core_nano_seconds().value() };
+ sandbox->UpdateStatsInfo(newStatsRec);
+
return podStats;
}
diff --git a/src/daemon/entry/cri/v1/v1_cri_pod_sandbox_manager_service.h b/src/daemon/entry/cri/v1/v1_cri_pod_sandbox_manager_service.h
index 2bd28007..c3d98b8c 100644
--- a/src/daemon/entry/cri/v1/v1_cri_pod_sandbox_manager_service.h
+++ b/src/daemon/entry/cri/v1/v1_cri_pod_sandbox_manager_service.h
@@ -123,6 +123,7 @@ private:
const std::vector<Network::NetworkInterfaceStats> &netMetrics,
const std::unique_ptr<ContainerManagerService> &containerManager,
std::unique_ptr<runtime::v1::PodSandboxStats> &podStats,
+ sandbox::StatsInfo &statsInfo,
Errors &error);
void GetFilterPodSandbox(const runtime::v1::PodSandboxStatsFilter *filter,
std::vector<std::string> &podSandboxIDs, Errors &error);
--
2.25.1
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。