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

news2024/10/7 8:32:21

 

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 latencies
  std::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 latencies
  std::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.coloradmin.cn/o/46888.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

原型设计模式

一、原型模式 1、定义 原型模式&#xff08;Prototype Pattern&#xff09;指原型实例指定创建对象的种类&#xff0c;并且通过复制这些原型创建新的对象&#xff0c;属于创建型设计模式。 原型模式的核心在于复制原型对象。 2、结构 &#xff08;1&#xff09;模式的结构 …

doris 动态分区

添加分区 ALTER TABLE v2x_olap_database.government_car ADD PARTITION p20221203 VALUES LESS THAN ("2022-12-04");动态分区表不能添加分区&#xff0c;需要转为手动分区表 查看分区 show paritions from <表名>删除分区 alter table <表名> dro…

[附源码]Python计算机毕业设计SSM隆庆祥企业服装销售管理系统(程序+LW)

项目运行 环境配置&#xff1a; Jdk1.8 Tomcat7.0 Mysql HBuilderX&#xff08;Webstorm也行&#xff09; Eclispe&#xff08;IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持&#xff09;。 项目技术&#xff1a; SSM mybatis Maven Vue 等等组成&#xff0c;B/S模式 M…

短信的信令过程

目录 1 短消息的信息流程&#xff1a; 1.1消息一次成功发送时的情况MO上行-MT下行 方式&#xff1a;1&#xff0e; MO&#xff08;主叫移动用户发给sp短消息中心&#xff09;编辑好短消息&#xff0c;键入发送号码&#xff08;被叫移动用户号码&#xff09;&#xff0c;按发送…

Java基于springboot+vue的摄影作品展示交流系统 计算机毕业设计

随着时代的发展&#xff0c;人们的精神世界也在不断的丰富&#xff0c;尤其是在当下电子设备发展迅速的背景下&#xff0c;人们通过数码相机或者手机随后就可以拍下每一个美丽的瞬间&#xff0c;但是人们更希望将这些摄影作品传到网上和更多的人进行分享&#xff0c;同时也希望…

决策树算法、随机森林算法

一、决策树 1、什么是决策树&#xff1f;如何进行高效的决策&#xff1f; 最早的决策树就是利用程序设计中的if-else结构分割数据的一种分类学习法。决策树的思想就是&#xff1a;如何高效的进行决策。而我们决策是有顺序的&#xff0c;即&#xff1a;我们在看不同的特征的时…

SSE AVX 发展简单介绍

SIMD全称是"Single Instruction, Multiple Data". SSE1是Pentium III引入的&#xff0c;它操作于16 bytes寄存器。在C和C中&#xff0c;这些寄存器以__m128的形式作为数据类型(128 bits16 bytes)。每个寄存器包含4个单精度浮点数float&#xff0c;指令集一共有8个这…

virtualbox下ubuntu虚拟机配置网络

一、目标&#xff1a; 1.在ubuntu虚拟机内可以联通外网 2.可以通过本机ssh连接上ubuntu虚拟机 二、Virtualbox配置 1.勾选 “系统->网络” 2.配置双网卡 网卡1配置为Nat&#xff0c;网卡2配置为Host-Only 三、ubuntu虚拟机内部设置 vi /etc/netplan/00-installer-confi…

OS_内存管理@非连续方式@段式和段页式

文章目录OS_内存管理非连续方式段式和段页式内存管理方式的发展基本分段存储逻辑结构图逻辑地址结构划分段表地址变换机构段表寄存器内容结构段和段表项的记号地址变换机构变换过程段的共享与保护段页式存储逻辑地址结构实现思路:段表和页表的变体&#x1f388;逻辑结构图sp-段…

HLS + ffmpeg 实现动态码流视频服务

一、简介 如下图&#xff0c;包含三部分&#xff0c;右边一列为边缘节点&#xff1b;中间一列代表数据中心&#xff1b;左边一列是项目为客户提供的一系列web管理工具&#xff1a; 具体来说在我们项目中有一堆边缘节点&#xff0c;每个节点上部署一台强大的GPU服务器及N个网络…

猴子也能学会的jQuery第十二期——jQuery遍历(下)

&#x1f4da;系列文章—目录&#x1f525; 猴子也能学会的jQuery第一期——什么是jQuery 猴子也能学会的jQuery第二期——引用jQuery 猴子也能学会的jQuery第三期——使用jQuery 猴子也能学会的jQuery第四期——jQuery选择器大全 猴子也能学会的jQuery第五期——jQuery样式操作…

0201导数的概念-导数与微分-高等数学

文章目录1 导数的定义2 常见函数的导数(导函数)3 单侧导数4 导数的几何意义5 可导和连续的关系6 后记1 导数的定义 设函数yf(x)yf(x)yf(x)在点x0x_0x0​的某个邻域内有定义&#xff0c;当自变量x在x0取得增量△xx在x_0取得增量\triangle xx在x0​取得增量△x(点x△xx\triangle …

品优购项目案例制作需要注意的内容笔记

个人在做的时候遇到的&#xff0c;自己觉得需要注意的内容 模块化 1.有些样式和结构在很多页面会出现&#xff0c;比如页面的头部和底部&#xff0c;大部分页面都有。此时可以把这些结构和样式单独作为一个模块&#xff0c;然后重复使用 2.这里最典型的应用就是common.css公…

虚拟内存系统【多级页表】

多级页表&#x1f3dd;️1. 考虑使用更大的页&#x1f3d6;️2. 使用段页式管理&#x1f4d6;2.1 为什么采用段页式管理&#xff1f;&#x1f4d6;2.2 段页式管理的缺点&#x1f3de;️3. 多级页表&#x1f4d6;3.1 多级页表的优点&#x1f4d6;3.2 多级页表的缺点&#x1f4d6…

文本匹配实战:基于Glove+RNN实现文本匹配 详细教程

任务描述: 文本匹配是自然语言处理中一个非常核心的任务,主要目的是研究两段文本之间的关系。许多自然语言处理任务在很大程度上都可以抽象成文本匹配问题,比如信息检索可以归结为搜索词和文档资源的匹配,问答系统可以归结为问题和候选答案的匹配,复述问题可以归结为两个同…

数商云SRM系统招标流程分享,助力建筑材料企业降低采购成本,提高采购效率

近年来&#xff0c;随着主管部门对房地产市场的监管非常严格&#xff0c;房地产业的发展已进入瓶颈期&#xff0c;这对与房地产业密切相关的建材行业产生了很大的影响。同时&#xff0c;我国城市化进入成熟期&#xff0c;行业规模发展动力减弱&#xff0c;建材行业增长压力明显…

谷粒商城1.项目简介和项目环境预搭建(项目概述和环境搭建代码)

一.商城项目总体架构 从讲课篇看 从分块来看 项目知识概述 二.环境搭建代码 1.项目架构 建立父工程 pom文件 <description>聚合服务</description><packaging>pom</packaging><modules><module>gulimall-coupon</module><mo…

H2数据库端口占用

因为服务已经起来了&#xff0c;然后自己再想测试的时候&#xff0c;发现端口已经占用&#xff0c;找了好久在官网文档找到了对应的解决方案 意思是在服务端上&#xff08;就是我们的配置文件application.yml&#xff09;我们得加上tcp://localhost/也就是你的主机地址tcp://12…

Lambert (兰伯特)光照模型

漫反射的定义 漫反射是投射在粗糙表面上的光向各个方向反射的现象。当一束平行的入射光线射到粗糙的表面时&#xff0c;表面会把光线向着四面八方反射&#xff0c;所以入射线虽然互相平行&#xff0c;由于各点的法线方向不一致&#xff0c;造成反射光线向不同的方向无规则地反…

小程序赋能生鲜食品进销存,线上+物流系统两手抓

互联网、物联网和消费升级的多重影响下&#xff0c;生鲜食品市场的流通更加便捷。在国内外的生鲜产品的可用性不再受季节和地区的限制&#xff0c;需求也逐渐增加。 那么随着生鲜食品商城小程序和网上商城购物系统平台的数量逐渐增加&#xff0c;如何体现其价值在企业进销存系统…