Apollo 应用与源码分析:Monitor监控-软件监控-时间延迟监控

news/2024/4/24 0:02:47/文章来源:https://blog.csdn.net/qq_32378713/article/details/128095329

 

9bb78baf2ed9aa03ea73a8439259f5d2.png

 

目录

 

代码

分析

RunOnce 函数分析

UpdateState函数分析

发送时间延迟报告函数分析

备注


 

代码

class LatencyMonitor : public RecurrentRunner {public:LatencyMonitor();void RunOnce(const double current_time) override;bool GetFrequency(const std::string& channel_name, double* freq);private:void UpdateStat(const std::shared_ptr<apollo::common::LatencyRecordMap>& records);void PublishLatencyReport();void AggregateLatency();apollo::common::LatencyReport latency_report_;std::unordered_map<uint64_t,std::set<std::tuple<uint64_t, uint64_t, std::string>>>track_map_;std::unordered_map<std::string, double> freq_map_;double flush_time_ = 0.0;
};void LatencyMonitor::RunOnce(const double current_time) {static auto reader =MonitorManager::Instance()->CreateReader<LatencyRecordMap>(FLAGS_latency_recording_topic);reader->SetHistoryDepth(FLAGS_latency_reader_capacity);reader->Observe();static std::string last_processed_key;std::string first_key_of_current_round;for (auto it = reader->Begin(); it != reader->End(); ++it) {const std::string current_key =absl::StrCat((*it)->module_name(), (*it)->header().sequence_num());if (it == reader->Begin()) {first_key_of_current_round = current_key;}if (current_key == last_processed_key) {break;}UpdateStat(*it);}last_processed_key = first_key_of_current_round;if (current_time - flush_time_ > FLAGS_latency_report_interval) {flush_time_ = current_time;if (!track_map_.empty()) {PublishLatencyReport();}}
}

分析

分析之前先回忆一下,之前模块channel 的之间的时间延迟就是通过LatencyMonitor 实现的,所以LatencyMonitor的工作就是收集各种时间延迟,并且汇总形成一个报告。

RunOnce 函数分析

订阅latency_recording_topic,消息体是LatencyRecordMap

message LatencyRecord {optional uint64 begin_time = 1;optional uint64 end_time = 2;optional uint64 message_id = 3;
};message LatencyRecordMap {optional apollo.common.Header header = 1;optional string module_name = 2;repeated LatencyRecord latency_records = 3;
};

遍历订阅到的所有的信息,然后使用UpdateStat 进行状态更新

UpdateState函数分析

void LatencyMonitor::UpdateStat(const std::shared_ptr<LatencyRecordMap>& records) {const auto module_name = records->module_name();for (const auto& record : records->latency_records()) {track_map_[record.message_id()].emplace(record.begin_time(),record.end_time(), module_name);}if (!records->latency_records().empty()) {const auto begin_time = records->latency_records().begin()->begin_time();const auto end_time = records->latency_records().rbegin()->end_time();if (end_time > begin_time) {freq_map_[module_name] =records->latency_records().size() /apollo::cyber::Time(end_time - begin_time).ToSecond();}}
}
  1. 保存每个 msg 的耗时信息到 track_map_
  2. 更新 freq_map 中模块的频率信息

发送时间延迟报告函数分析

void LatencyMonitor::PublishLatencyReport() {static auto writer = MonitorManager::Instance()->CreateWriter<LatencyReport>(FLAGS_latency_reporting_topic);apollo::common::util::FillHeader("LatencyReport", &latency_report_);AggregateLatency();writer->Write(latency_report_);latency_report_.clear_header();track_map_.clear();latency_report_.clear_modules_latency();latency_report_.clear_e2es_latency();
}
void LatencyMonitor::AggregateLatency() {static const std::string kE2EStartPoint = FLAGS_pointcloud_topic;std::unordered_map<std::string, std::vector<uint64_t>> modules_track;std::unordered_map<std::string, std::vector<uint64_t>> e2es_track;std::unordered_set<std::string> all_modules;// Aggregate modules latenciesstd::string module_name;uint64_t begin_time = 0, end_time = 0;for (const auto& message : track_map_) {auto iter = message.second.begin();while (iter != message.second.end()) {std::tie(begin_time, end_time, module_name) = *iter;modules_track[module_name].push_back(end_time - begin_time);all_modules.emplace(module_name);++iter;}}// Aggregate E2E latenciesstd::unordered_map<std::string, uint64_t> e2e_latencies;for (const auto& message : track_map_) {uint64_t e2e_begin_time = 0;auto iter = message.second.begin();e2e_latencies.clear();while (iter != message.second.end()) {std::tie(begin_time, std::ignore, module_name) = *iter;if (e2e_begin_time == 0 && module_name == kE2EStartPoint) {e2e_begin_time = begin_time;} else if (module_name != kE2EStartPoint && e2e_begin_time != 0 &&e2e_latencies.find(module_name) == e2e_latencies.end()) {const auto duration = begin_time - e2e_begin_time;e2e_latencies[module_name] = duration;e2es_track[module_name].push_back(duration);}++iter;}}// The results could be in the following fromat:// e2e latency:// pointcloud -> perception: min(500), max(600), average(550),// sample_size(1500) pointcloud -> planning: min(800), max(1000),// average(900), sample_size(1500) pointcloud -> control: min(1200),// max(1300), average(1250), sample_size(1500)// ...// modules latency:// perception: min(5), max(50), average(30), sample_size(1000)// prediction: min(500), max(5000), average(2000), sample_size(800)// control: min(500), max(800), average(600), sample_size(800)// ...auto* modules_latency = latency_report_.mutable_modules_latency();for (const auto& module : modules_track) {SetLatency(module.first, module.second, modules_latency);}auto* e2es_latency = latency_report_.mutable_e2es_latency();for (const auto& e2e : e2es_track) {SetLatency(absl::StrCat(kE2EStartPoint, " -> ", e2e.first), e2e.second,e2es_latency);}
}

可以看出主要是两个部分的时间延迟:

  1. 所有模块的时间延迟
  2. E2E 的时间延迟

这里的E2E就是端到端的时间延迟,在apollo 中指的是电晕信息到各个模块输出的时间。

E2E Latency 的逻辑:

  1. 记录第一条点云数据的开始时间
  2. 依次记录那些不是点云数据的记录的开始时间,计算它们之间的差值,就成了这一个测试周期的 E2E 时延。

备注

Latency 的运行基于依靠于 CyberRT 的通信,所以,也必须保证 CyberRT 的 Channel 通信机制足够可靠,不然会产生误差。

 

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.luyixian.cn/news_show_38605.aspx

如若内容造成侵权/违法违规/事实不符,请联系dt猫网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Git---idea中git的基本操作

idea中使用git仓库 idea中配置git仓库&#xff1a; 首先idea配置git仓库的位置 配置完成之后&#xff0c;有两种创建仓库的方式 从本地配置git仓库&#xff1a; idea本身设置好的&#xff0c;直接下一步就好 从远程克隆仓库&#xff1a; 如果远程仓库没有的话可以绑定完…

CDMP考试时间与报名方式

CDMP“数据管理专业人士认证”证书国际通用&#xff0c;行业认可度极高&#xff0c;是一项涵盖学历教育、工作经验和专业知识考试在内的综合资格认证&#xff0c;也是 目前全球唯一数据管理方面权威性认证 。CDMP考试时间是什么时候&#xff1f;怎样报名&#xff1f;今天小编来…

从ChargePoint到能链智电,充电服务商的价值创新

近日&#xff0c;吉林长春出租车雨雪之中排队换电艰难的视频引起热议。 新能源汽车充换电困难&#xff0c;一方面说明电池在寒冷天气下的性能有优化空间&#xff0c;另一方面也反映出国内新能源汽车配套基础设施仍然存在较大需求缺口。 充电基础设施建设对新能源汽车推广意义…

使用Spark的foreach算子及UDTF函数实现MySQL数据的一对多【Java】

使用Spark的foreach算子及UDTF函数实现MySQL数据的一对多【Java】 背景 我们的数仓项目中遇到了这样一种场景&#xff0c;脱敏后内容大致如下&#xff1a; col1col2time1time2a1b12022-01-01 00:00:002022-01-05 00:00:00a2b22022-01-28 00:00:002022-02-03 00:00:00a3b3202…

设计模式——模板方法模式

模板方法模式 一、基本思想 定义一个操作中的算法骨架&#xff0c;而将算法的一些步骤延迟到子类中&#xff0c;使得子类可以不改变该算法结构的情况下重定义该算法的某些特定步骤。 二、应用场景 算法的整体步骤很固定&#xff0c;但其中个别部分易变时&#xff0c;这时候…

数据结构学习:Trie树

Trie一、概念二、代码实现三、Tire树的时间复杂度和空间复杂度四、Tire树的优势一、概念 Trie树,也叫"字典树",顾名思义,是一种专门处理字符串匹配的树形结构,用来解决在一组字符串集合中快速找到某个字符串类似于这种字符串匹配问题,可以使用RF暴力匹配、RK哈希匹配…

数字孪生技术栈的应用场景的优点

技术栈是一个IT术语&#xff0c;本意是指某项工作需要掌握的一系列技能组合的统称。那么对于如今炙手可热的数字孪生技术而言&#xff0c;数字孪生技术栈都会包括哪些底层技能&#xff1f;它又是如何构成和运行的呢&#xff1f; 北京智汇云舟科技有限公司成立于2012年&#xff…

【Rust日报】2022-11-28 使用 Rust 编写解释型语言

使用 Rust 编写解释型语言这是一本关于使用 Rust 来编写解释型语言的指导书.从理论基础, 内存分配, 真实实践, GC 等方面循序渐进的指导如何使用 Rust 来编写解释型语言.原文链接: https://rust-hosted-langs.github.io/book/introduction.htmlRust的所有权和生命周期这是一篇从…

黄佳《零基础学机器学习》chap2笔记

黄佳 《零基础学机器学习》 chap2笔记 第2课 数学和Python基础知识 文章目录黄佳 《零基础学机器学习》 chap2笔记第2课 数学和Python基础知识2.1 函数描述了事物间的关系机器学习中常用的一些函数2.2 捕捉函数的变化趋势2.3 梯度下降2.4 机器学习的数据结构--张量2.4.1 张量的…

面板模型进行熵值法分析

背景说明 熵值法&#xff08;熵权法&#xff09;是一种研究指标权重的研究方法&#xff0c;比如有5个指标&#xff0c;分别为指标1到指标5&#xff0c;并且有很多样本&#xff08;比如100个样本&#xff09;&#xff0c;即100行*5列数据&#xff0c;此时研究该5个指标的权重分…

WSL2 请启用虚拟机平台 Windows 功能并确保在 BIOS 中启用虚拟化

bcdedit /set hypervisorlaunchtype autoC:\WINDOWS\system32>bcdedit /set hypervisorlaunchtype auto 操作成功完成。

使用nohup命令 或者 代码创建守护进程

目录 一、什么是守护进程&#xff1f; 1、守护进程的概念 2、为什么需要守护进程 二、理解进程组、会话、终端 三、创建守护进程的两种方式 1、nohup命令创建守护进程 2、代码创建守护进程 (1) 创建子进程&#xff0c;父进程退出 (2) 子进程创建新的会话 (3) 更改守护…

车载电子专用DC-DC方案PL5501

PL5501是一个同步4开关Buck-Boost能够调节输出电压的控制器高于或低于输入电压。PL5501运作输入电压范围从3.6 V到32 V (36 V Maximum)以支持各种应用程序。PL5501 buck采用恒ON时间控制&#xff0c;上位机采用升压和升压两种操作方式负荷和线路调节。开关频率可以设置为150kHz…

链式二叉树

链式二叉树一&#xff0c;相关函数接口实现1&#xff0c;前序遍历2&#xff0c;中序遍历3&#xff0c;后序遍历4&#xff0c;节点个数5&#xff0c;叶子结点个数6&#xff0c;树的高度7&#xff0c;第K层结点个数8&#xff0c;查找值为X的结点9&#xff0c;通过前序遍历数组构建…

关于虚拟机中IPI中断的思考

前言 感谢intel的vt-x技术&#xff0c;让虚拟机大部分指令可以直接运行在CPU中&#xff0c;只有少部分敏感指令需要有VMM来模拟执行。其中&#xff0c;每个CPU的LAPIC接收到的中断是虚拟化的开销一个大头。 LAPIC接收到的中断分为外部中断&#xff0c;内部中断&#xff0c;IP…

【SQL Server + MySQL三】数据库设计【ER模型+UML模型+范式】 + 数据库安全性

极其感动&#xff01;&#xff01;&#xff01;当时学数据库的时候&#xff0c;没白学&#xff01;&#xff01; 时隔很长时间回去看数据库的笔记都能看懂&#xff0c;每次都靠这份笔记巩固真的是语雀分享要花钱&#xff0c;要不一定把笔记给贴出来(;༎ຶД༎ຶ) &#xff0c;除…

第2-4-8章 规则引擎Drools实战(1)-个人所得税计算器

文章目录9. Drools实战9.1 个人所得税计算器9.1.1 名词解释9.1.2 计算规则9.1.2.1 新税制主要有哪些变化&#xff1f;9.1.2.2 资较高人员本次个税较少&#xff0c;可能到年底扣税增加&#xff1f;9.1.2.3 关于年度汇算清缴9.1.2.4 个人所得税预扣率表&#xff08;居民个人工资、…

LeetCode - 76 最小覆盖子串

目录 题目来源 题目描述 示例 提示 题目解析 算法源码 题目来源 76. 最小覆盖子串 - 力扣&#xff08;LeetCode&#xff09; 题目描述 给你一个字符串 s 、一个字符串 t 。返回 s 中涵盖 t 所有字符的最小子串。如果 s 中不存在涵盖 t 所有字符的子串&#xff0c;则返回…

iClient for Leaflet设置地图掩膜

作者&#xff1a;lly 文章目录背景一、实现思路二、步骤代码三、完整代码背景 最近很多小伙伴需要只展示地图的某个行政区域&#xff0c;由于地图存在多个图层&#xff0c;所以图层过滤的方式并不能很好的适用&#xff0c;这个时候&#xff0c;我们可以考虑给地图覆盖一层掩膜…

界面控件DevExpress WPF的主题设计器,可轻松完成应用主题研发

DevExpress WPF拥有120个控件和库&#xff0c;将帮助您交付满足甚至超出企业需求的高性能业务应用程序。通过DevExpress WPF能创建有着强大互动功能的XAML基础应用程序&#xff0c;这些应用程序专注于当代客户的需求和构建未来新一代支持触摸的解决方案。 DevExpress WPF的The…