fidlcat:指南

啟動 fidlcat並附加至執行中的程序後,這項工具就會開始記錄透過 FIDL 傳送及接收的系統呼叫。

請參閱以下 fidlcat 的基本範例輸出內容:

Monitoring echo_client.cm koid=193974

echo_client.cm 193974:193976 zx_channel_create(options: uint32 = 0)
  -> ZX_OK (out0: handle = d7e9f83b(channel:0), out1: handle = d6c9fd5f(channel:1))

範例輸出內容包含下列資訊:

  • echo_client.cm:產生這個畫面的程序名稱。

  • 193974:程序 koid。

  • 193976:執行緒 koid。

  • zx_channel_create:攔截/顯示的系統呼叫名稱。

  • 系統呼叫輸入參數 (例如 handleoptions),並依名稱、類型和值列出。

  • 系統呼叫傳回值 (ZX_OK) 和輸出參數。

如果是代表 FIDL 交易的系統呼叫,fidlcat 會顯示額外的輸入和輸出參數。以下是同步 fuchsia.examples/Echo.EchoString 要求範例:

echo_client.cm 193974:193976 zx_channel_call_etc(handle: handle = Channel:d089f8fb(dir:/svc/fuchsia.examples.Echo), options: uint32 = ZX_CHANNEL_WRITE_USE_IOVEC, deadline: zx.time = ZX_TIME_INFINITE, rd_num_bytes: uint32 = 64, rd_num_handles: uint32 = 64)
  sent request fuchsia.examples/Echo.EchoString = { value: string = "hello" }
  -> ZX_OK
    received response fuchsia.examples/Echo.EchoString = { response: string = "hello" }

請注意顯示輸出內容中的 FIDL 要求和回應訊息,包括方法名稱和參數。

修改顯示畫面

根據預設,fidlcat 只會在每則訊息的第一行顯示程序資訊。使用 --with-process-info 旗標,在每一行中加入這些詳細資料:

echo_client.cm 60014:60016 zx_channel_call_etc(handle: handle = Channel:35272afb(dir:/svc/fuchsia.examples.Echo), options: uint32 = ZX_CHANNEL_WRITE_USE_IOVEC, deadline: zx.time = ZX_TIME_INFINITE, rd_num_bytes: uint32 = 64, rd_num_handles: uint32 = 64)
echo_client.cm 60014:60016   sent request fuchsia.examples/Echo.EchoString = { value: string = "hello" }
echo_client.cm 60014:60016   -> ZX_OK
echo_client.cm 60014:60016     received response fuchsia.examples/Echo.EchoString = { response: string = "hello" }

堆疊框架

使用 --stack 旗標,即可顯示每個系統呼叫的堆疊框架。根據預設 (--stack=0),系統不會顯示堆疊框架。

使用 --stack=1 時,只會顯示呼叫網站 (1 到 4 個影格):

echo_client.cm 675407:675409 at zircon/system/ulib/fidl/llcpp_message.cc:243:12 fidl::OutgoingMessage::CallImpl
echo_client.cm 675407:675409 zx_channel_call_etc(handle: handle = Channel:8b745347(dir:/svc/fuchsia.examples.Echo), options: uint32 = ZX_CHANNEL_WRITE_USE_IOVEC, deadline: zx.time = ZX_TIME_INFINITE, rd_num_bytes: uint32 = 64, rd_num_handles: uint32 = 64)
  sent request fuchsia.examples/Echo.EchoString = { value: string = "hello" }
  -> ZX_OK
    received response fuchsia.examples/Echo.EchoString = { response: string = "hello" }

這個選項不會增加任何負擔 (顯示器除外)。

--stack=2 顯示所有影格:

echo_client.cm 717533:717535 at 3ac285b4811 _start
echo_client.cm 717533:717535 at zircon/third_party/ulib/musl/src/env/__libc_start_main.c:215:5 __libc_start_main
echo_client.cm 717533:717535 at zircon/third_party/ulib/musl/src/env/__libc_start_main.c:140:3 start_main
echo_client.cm 717533:717535 at examples/fidl/llcpp/client_sync/main.cc:30:27 main
echo_client.cm 717533:717535 at fidling/gen/examples/fidl/fuchsia.examples/fuchsia.examples/llcpp/fidl/fuchsia.examples/cpp/wire_messaging.h:2711:12 fidl::internal::WireSyncClientImpl<fuchsia_examples::Echo>::EchoString
echo_client.cm 717533:717535 at fidling/gen/examples/fidl/fuchsia.examples/fuchsia.examples/llcpp/fidl/fuchsia.examples/cpp/wire_messaging.cc:1051:12 fidl::WireResult<fuchsia_examples::Echo::EchoString>::WireResult
echo_client.cm 717533:717535 at zircon/system/ulib/fidl/include/lib/fidl/llcpp/message.h:205:3 fidl::OutgoingMessage::Call<fidl::WireResponse<fuchsia_examples::Echo::EchoString>, zx::unowned<zx::channel> >
echo_client.cm 717533:717535 at zircon/system/ulib/fidl/include/lib/fidl/llcpp/message.h:196:5 fidl::OutgoingMessage::Call<fidl::WireResponse<fuchsia_examples::Echo::EchoString> >
echo_client.cm 717533:717535 at zircon/system/ulib/fidl/llcpp_message.cc:243:12 fidl::OutgoingMessage::CallImpl
echo_client.cm 717533:717535 zx_channel_call_etc(handle: handle = Channel:f751d2fb(dir:/svc/fuchsia.examples.Echo), options: uint32 = ZX_CHANNEL_WRITE_USE_IOVEC, deadline: zx.time = ZX_TIME_INFINITE, rd_num_bytes: uint32 = 64, rd_num_handles: uint32 = 64)
  sent request fuchsia.examples/Echo.EchoString = { value: string = "hello" }
  -> ZX_OK
    received response fuchsia.examples/Echo.EchoString = { response: string = "hello" }

這個選項會增加一些額外負擔,因為我們需要為每個系統呼叫向 zxdb 要求完整堆疊 (而 fidlcat 會變得更加詳細)。只有在需要瞭解程式碼的哪個部分呼叫系統呼叫時,才應使用這項功能。

篩選輸出內容

系統呼叫

根據預設,fidlcat 只會顯示 zx_channel 系統呼叫。--syscalls 選項可讓您定義規則運算式,選取要解碼及顯示的系統呼叫。

如要顯示所有系統呼叫,請使用:--syscalls=".\*"

--exclude-syscalls 旗標會定義排除系統呼叫的規則運算式,這些系統呼叫來自 --syscalls 選取的集合。

如要顯示系統呼叫,必須符合 --syscalls 模式,且不得符合 --exclude-syscalls 模式。

以下範例會顯示所有系統呼叫, zx_handle 除外:

--syscalls ".\*" --exclude-syscalls "zx_handle_.\*"

訊息

根據預設,fidlcat 會顯示所有郵件。 你可以使用下列方式指定要顯示的訊息:

  • --messages 可讓您指定一或多個規則運算式,訊息必須符合這些運算式才會顯示。

  • --exclude-messages 可讓您指定一或多個規則運算式,郵件不得符合這些運算式,才能顯示。

如果同時使用這兩個選項,訊息必須符合以 --messages 指定的其中一個規則運算式,且不符合以 --exclude-messages 指定的任何規則運算式,才會顯示。

訊息篩選功能會根據方法的完整名稱運作。舉例來說,以下旗標:

--messages=".*Open"

符合的方法如下:

fuchsia.io/Directory.Open
fuchsia.io/Node.OnOpen

執行緒

使用 --thread=<thread koid> 選項時,系統只會顯示指定執行緒的事件。這個選項可多次使用,顯示多個執行緒。

分組輸出

通訊協定

使用 --with=top--with=top=<path> 選項產生檢視畫面,依程序、通訊協定和方法將輸出內容分組。群組會依事件數量排序,因此關聯事件較多的群組會列在較前面。

執行緒

使用 --with=group-by-thread--with=group-by-thread=<path> 選項,產生顯示每個執行緒所有事件簡短版本的檢視畫面。

延後顯示訊息

根據預設,fidlcat 會在附加至程序後立即開始顯示訊息。

您可以使用 --trigger 選項延後顯示,直到提供的規則運算式與傳入訊息相符為止。

當您收到或發出特定訊息後,需要瞭解後續情況時,這項功能就非常實用。

摘要檢視

如要設定 fidlcat 顯示工作階段的摘要,而非列出個別訊息,請使用 --with=summary--with=summary=<path> 選項。

echo_client.cm 1505832: 16 handles

  Process:ac4ce043(proc-self)

  startup Vmar:a43cfe53(vmar-root)

  startup Thread:d5dce00f(thread-self)

  startup Channel:91cce2f3(dir:/svc)
      write request  fuchsia.io/Directory.Open(".")
        -> Channel:c65ce1c3(dir:/svc)

  startup Channel:daece3fb(dir:/pkg)

  startup Socket:cb8ce31f(fd:1)
    closed by zx_handle_close

  startup Socket:df8ce687(fd:2)
    closed by zx_handle_close

  startup Channel:93ccfcf7(directory-request:/)

  startup Clock:b7ecfe9b()

  startup Job:674ce17f(job-default)

  startup Vmo:adbcfc9f(vdso-vmo)

  startup Vmo:ef2ce06f(stack-vmo)

  Channel:c65ce1c3(dir:/svc)
    linked to Channel:da9cebcb(channel:1)
    created by zx_channel_create
      write request  fuchsia.io/Directory.Open("fuchsia.examples.Echo")
        -> Channel:767ce3f3(dir:/svc/fuchsia.examples.Echo)
    closed by zx_handle_close

  Channel:da9cebcb(channel:1)
    linked to Channel:c65ce1c3(dir:/svc)
    created by zx_channel_create
    closed by Channel:91cce2f3(dir:/svc) sending fuchsia.io/Directory.Open

  Channel:767ce3f3(dir:/svc/fuchsia.examples.Echo)
    linked to Channel:f4bce307(channel:3)
    created by zx_channel_create
      call  request  fuchsia.examples/Echo.EchoString
      write request  fuchsia.examples/Echo.SendString
      read  event    fuchsia.examples/Echo.OnString
    closed by zx_handle_close

  Channel:f4bce307(channel:3)
    linked to Channel:767ce3f3(dir:/svc/fuchsia.examples.Echo)
    created by zx_channel_create
    closed by Channel:c65ce1c3(dir:/svc) sending fuchsia.io/Directory.Open

這會顯示工作階段中所有受監控的程序、控制代碼和管道清單,以及其他摘要詳細資料:

  • 控制代碼:控制代碼是啟動控制代碼 (在程序建立期間繼承),還是在程序生命週期中建立。如果是非啟動控制代碼,fidlcat 也會顯示用於建立及關閉每個控制代碼的系統呼叫相關資訊。

  • 通道:顯示負責管道另一端的控制代碼,以及傳送和接收的 FIDL 訊息清單。

持續監控

根據預設,所有附加程序結束時,fidlcat 工作階段就會終止。

使用 --stay-alive 選項可讓工作階段持續執行,直到您手動結束 fidlcat 為止 (例如使用 Ctrl-C)。

這樣一來,您就能在同一個監控工作階段中多次重新啟動程式。每次重新啟動時,fidlcat 工作階段都會自動附加至新程序。