尧图网站设计 尧图网站设计YAOTU DESIGN
ARTICLE DETAIL

资讯详情

深耕网站设计与一线实操的经验洞察。

MediaPipe 怎么开启 tracing 与 profiling 并在 Visualizer 中分析计算器延迟?

MediaPipe 怎么开启 tracing 与 profiling 并在 Visualizer 中分析计算器延迟? MediaPipe 怎么开启 tracing 与 profiling 并在 Visualizer 中分析计算器延迟【免费下载链接】mediapipeCross-platform, customizable ML solutions for live and streaming media.项目地址: https://gitcode.com/GitHub_Trending/med/mediapipe如果你的 MediaPipe 图整体偏慢想定位是哪个 calculator 在Process()里耗时最多、或者包到达后平均要等多久才开始处理可以用框架自带的 tracer 和 profilertracer 记录包处理相关的计时事件包括每次Calculator::Process调用的开始与结束时间并以 binary protobuf 格式写出 trace 日志文件profiler 为每个运行中的 calculator 累积一份Process调用时延直方图。整套流程是在图配置中开启 tracing/profiling → 运行图产生.binarypb文件 → 上传到 MediaPipe Visualizer按列查看各 calculator 的延迟统计。文档说明 tracing 与 profiling 可用平台为 Linux、Android、iOS。准备确保 profiling 库已链接开启一个图的 tracing 和 profiling 需要满足两个条件profiling 库已链接到框架图配置中已启用 tracing 和 profiling。Desktop 平台默认已将 profiling 库链接进框架。其他平台在构建时加上 bazel 命令行选项即可链接--define MEDIAPIPE_PROFILING1对应地Desktop 上如需把 profiling 库从框架中排除使用--define MEDIAPIPE_PROFILING0。在图配置中开启 tracing 与 profiling把profiler_config消息加到代表该图的CalculatorGraphConfig根部也就是你的.pbtxt图文件顶层。文档给出的示例profiler_config { trace_enabled: true enable_profiler: true trace_log_interval_count: 200 trace_log_path: /sdcard/Download/ }各字段的用途trace_log_path示例值/sdcard/Download/是文档中的 Android 路径示例桌面平台默认写/tmpenable_profiler为 true 时 profiler 在图初始化时开始 profiling。文档明确不设置它就不会产生任何日志是必选项。trace_enabled为 true 时 tracer 记录并上报计时事件这是离线 profiling 所需的 packet 级信息。trace_log_pathtrace 日志的输出目录与基名。日志写到StrCat(trace_log_path, index, .binarypb)。注意路径末尾的斜杠是必需的用于表示其后是目录且该目录应当已存在。trace_log_interval_count每个 trace 文件包含的 interval 数。文档把上面的示例配置描述为“保持 100 秒的 timing events”。总日志时长按trace_log_interval_usec * trace_log_count * trace_log_interval_count计算。默认情况下日志文件命名为mediapipe_trace_index.binarypbindex 默认在 0 和 1 之间轮换即保留 2 个轮换文件每个文件默认记录 5 秒的事件具体是每 0.5 秒一个 interval、共 10 个 interval可通过trace_log_interval_usec和trace_log_interval_count覆盖。完整的字段定义在 calculator.proto 的ProfilerConfig消息中图根部的profiler_config字段见 calculator.proto。按平台收集 trace 日志文档给出的默认日志输出位置Desktop/tmp目录Android外部存储目录如/storage/emulated/0/iOS通过 Xcode 获取见下文。Linux / Desktop按上一节在图配置中开启 tracing构建并运行你的 MediaPipe 图运行中的图会把 trace 事件写到默认目录或你指定的trace_log_path。Android前提是 Android 应用拥有外部存储的写权限在AndroidManifest.xml中加入uses-permission android:nameandroid.permission.MANAGE_EXTERNAL_STORAGE /授予权限可以在应用首次启动时授予或进入Settings - Apps notifications - 你的应用名 - Permissions后启用Storage。把profiler_config消息加到现有的 calculator-graph-config protobuf 中例如现有的.pbtxt文件。连接设备后运行adb devices确认设备已识别文档示例输出adb devices # should print: # List of devices attached # 805KPWQ1876505 device用bazel build编译 Android 应用再用adb install安装到设备。打开应用。运行中的 MediaPipe 图会向 trace 日志文件追加事件trace_log_path设为/sdcard/Download/时/storage/emulated/0/Download/mediapipe_trace_0.binarypb /storage/emulated/0/Download/mediapipe_trace_1.binarypb默认每 5 秒切换到下一个 trace 文件只保留最近 5 秒的事件。可以用 adb shell 确认文件已写到设备上adb shell ls -la /storage/emulated/0/Download把 trace 文件从设备拉下来adb pull /storage/emulated/0/Download/mediapipe_trace_0.binarypb文档示例输出文档示例实际数值不同/sdcard/mediapipe_trace_0.binarypb: 1 file pulled. 0.1 MB/s (6766 bytes in 0.045s)如果需要换目录用trace_log_path覆盖例如/sdcard/Download/profiles/末尾斜杠不可省略。iOS在 Xcode 中打开 Window → Devices and Simulators选择 Devices 标签找到你的应用并打开 Download Container日志位于application container/.xcappdata/AppData/Documents/。如果 Xcode 显示下载的容器内容为空在 Finder 中右键选择 Show Package Contents日志位于AppData/Documents/。在 Visualizer 中上传 trace 文件并读取延迟列打开 MediaPipe Visualizer 在线站点viz.mediapipe.dev。点击右上角的 Upload 按钮。点击 Upload trace file。在弹出的文件选择框中选择包含 trace 信息的.binarypb文件。出现 chart view所有 calculator 列在左侧profiling 指标列在顶部。点击列头可对该列交替按升序/降序排序也可以横向、纵向滚动查看更多列和更多 calculator。手头还没有真实日志时可以先用仓库里自带的示例 trace 文件 sample_trace.binarypb 走一遍上传流程熟悉界面后再替换成自己的日志。各列含义列名含义namecalculator 的名称fps该 calculator 平均每秒能产出的帧数1 / (input_latency_mean time_mean)单位 1/秒frequency该 calculator 每秒被要求处理包的速率# of calls total / (last_call_time - first_call_time)单位 1/秒counterprocess()被调用的次数等于dropped completeddroppedcalculator 被调用但没有产生输出的次数completedcalculator 被要求处理输入后实际产生输出的次数processing_rate1E6 / time_mean该 calculator 平均每秒能运行 process 的次数单位 1/秒thread_count使用了该 calculator 的线程数time_mean在 calculator 内部花费的平均时间微秒time_stddevtime_mean 的标准差微秒time_total在 calculator 内部花费的总时间微秒time_percent在 calculator 内部花费的时间占总时间的百分比input_latency_mean某次 calculator 迭代所使用的最早输入包与该 calculator 实际开始处理之间的平均延迟微秒input_latency_stddevinput_latency_mean 的标准差微秒input_latency_total累积的总 input latency微秒按列排序时time_mean、time_total、time_percent对应 calculator 自身处理耗时的占比input_latency_mean对应输入等待延迟文档只给出上述定义具体哪个 calculator 是瓶颈需要结合你上传的日志判断。限制与可调项平台范围tracing 与 profiling 只在 Linux、Android、iOS 上可用。enable_profiler必须为 true否则不产生任何日志。默认只保留 2 个轮换文件、每文件 5 秒事件窗口只覆盖最近 5 秒要采集更长的时间段增大trace_log_interval_count文档示例设为 200或调整trace_log_count/trace_log_interval_usec。文档标注ProfilerConfig中多数字段属于高级设置一般用不到。常用与高级字段可在 tracing_and_profiling.md 的 Profiler configuration 一节核对包括trace_log_capacity内存中缓冲的 trace 事件数上限默认 20000、trace_log_disabled关闭落盘默认是启用写盘、histogram_interval_size_usec/num_histogram_intervalsProcess()时延直方图的区间大小与数量默认 1 秒单区间、enable_stream_latency在enable_profiler为 false 时无效等calculator.proto 中还定义了calculator_filter用于把 calculator 时延直方图限制到一组 calculator 子集。完整操作步骤与列含义见 tracing_and_profiling.mdVisualizer 的图视图等其余功能见 visualizer.md。【免费下载链接】mediapipeCross-platform, customizable ML solutions for live and streaming media.项目地址: https://gitcode.com/GitHub_Trending/med/mediapipe创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
返回列表