监控设备上的 FIDL 消息

ffx debug fidl 会启动 fidlcat(Fuchsia 程序),以监控 Fuchsia 设备上的 FIDL 流量。

概念

fidlcat 是一个工具,可让您在 Fuchsia 设备上监控和调试 FIDL 消息。fidlcat 会与设备建立连接,并输出 Fuchsia 组件正在发送和接收的所有 FIDL 消息。

与其他 Fuchsia 调试工具类似,为了让 fidlcat 理解和解压缩 Fuchsia 组件的 FIDL 消息,您的开发环境中必须提供该组件的调试符号。(如需详细了解调试符号,请参阅注册调试符号。)

不过,除了调试符号之外,fidlcat 还需要获取组件的 FIDL 中间表示 (IR) 文件列表。此列表通常存储为 Fuchsia 项目中标记为 all_fidl_json.txt 的全局文件。如果您使用的是 Fuchsia 的 Bazel 规则,系统会在构建过程中自动生成此列表文件。

启动 fidlcat

如需监控设备上 Fuchsia 组件的 FIDL 流量,请运行以下命令:

ffx debug fidl -f <COMPONENT> --fidl-ir-path <LIST_OF_IR_FILES>

替换以下内容:

  • COMPONENT - 您要监控的 Fuchsia 组件的名称。
  • LIST_OF_IR_FILES - 包含 IR 文件列表的文件的路径,以 @ 为前缀(例如 @/usr/home/alice/my-fuchsia-project/all_fidl_json.txt)。

以下示例命令会启动用于监控 memory_monitor 组件的 fidlcat

$ ffx debug fidl -f memory_monitor.cm --fidl-ir-path @/usr/home/alice/my-fuchsia-project/all_fidl_json.txt

成功连接到设备后,此命令会输出类似于以下内容的输出:

$ ffx debug fidl -f memory_monitor.cm --fidl-ir-path @/usr/home/alice/my-fuchsia-project/all_fidl_json.txt
INFO: [main.cc(242)] Connected to symbol server gs://our-fuchsia-artifacts/debug
INFO: [main.cc(125)] Connecting to /tmp/debug_agent_lpaMdL.socket...
INFO: [main.cc(92)] Connected!

从此时开始,该命令会实时输出目标组件的 FIDL 消息,例如:

2701.44 Monitoring memory_monitor.cm koid=47467

2703.286866 memory_monitor.cm 47467:47469 zx_channel_call_etc(handle: handle = 7dd2c40b, options: uint32 = ZX_CHANNEL_WRITE_USE_IOVEC, deadline: zx.time = ZX_TIME_INFINITE, rd_num_bytes: uint32 = 65536, rd_num_handles: uint32 = 64)
  sent request fuchsia.kernel/Stats.GetMemoryStats = {}
2703.286866   -> ZX_OK
    received response fuchsia.kernel/Stats.GetMemoryStats = {
      stats: fuchsia.kernel/MemoryStats = {
        total_bytes: uint64 = 8455393280
        free_bytes: uint64 = 6727020544
        wired_bytes: uint64 = 102539264
        total_heap_bytes: uint64 = 32464896
        free_heap_bytes: uint64 = 1672120
        vmo_bytes: uint64 = 1540259840
        mmu_overhead_bytes: uint64 = 50339840
        ipc_bytes: uint64 = 278528
        other_bytes: uint64 = 0
      }
    }

2703.815113 memory_monitor.cm 47467:47469 zx_channel_write_etc(handle: handle = 7df30f83, options: uint32 = 0)
  sent request fuchsia.memory/Watcher.OnChange = {
    stats: fuchsia.memory/Stats = {
      total_bytes: uint64 = 8455393280
      free_bytes: uint64 = 6727020544
      wired_bytes: uint64 = 102539264
      total_heap_bytes: uint64 = 32464896
      free_heap_bytes: uint64 = 1672120
      vmo_bytes: uint64 = 1540259840
      mmu_overhead_bytes: uint64 = 50339840
      ipc_bytes: uint64 = 278528
      other_bytes: uint64 = 0
    }
  }
2703.815113   -> ZX_OK

...

如需退出 fidlcat,请按 Ctrl-C