監控裝置上的 FIDL 訊息

ffx debug fidl 會啟動 fidlcat (Fuchsia 程式),用於監控 Fuchsia 裝置上的 FIDL 流量。

概念

fidlcat 這項工具可讓您在 Fuchsia 裝置上監控 FIDL 訊息並進行偵錯。fidlcat 會為裝置建立連線,並列印 Fuchsia 元件即時收發的所有 FIDL 訊息。

與其他 Fuchsia 偵錯工具類似,如要讓 fidlcat 瞭解及解壓縮 Fuchsia 元件的 FIDL 訊息,您的開發環境必須能使用該元件的偵錯符號。(如要進一步瞭解偵錯符號,請參閱「註冊偵錯符號」)。

不過,除了偵錯符號外,fidlcat 還需要取得元件的 FIDL 中繼表示法 (IR) 檔案清單。這份清單通常會以標籤為 all_fidl_json.txt 的全域檔案儲存在您的 Fuchsia 專案中。如果您使用 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