code: def test_collect():
      options = _ProfilingOptions(
          {
              "slow_calls_duration_threshold": 0,
              "slow_subtasks_duration_threshold": 0,
          }
      )
  
      # Test collect message with incomparable arguments.
      from ..core import ActorRef
  
      fake_actor_ref = ActorRef("def", b"uid")
      fake_message1 = SendMessage(b"abc", fake_actor_ref, ["name", {}])
      fake_message2 = SendMessage(b"abc", fake_actor_ref, ["name", 1])
  
      cs = _CallStats(options)
      cs.collect(fake_message1, 1.0)
      cs.collect(fake_message2, 1.0)
  
      @dataclasses.dataclass
      class _FakeSubtask:
          extra_config: dict
  
      # Test collect subtask with incomparable arguments.
      band = ("1.2.3.4", "numa-0")
      subtask1 = _FakeSubtask({})
      subtask2 = _FakeSubtask(None)
      ss = _SubtaskStats(options)
      ss.collect(subtask1, band, 1.0)
      ss.collect(subtask2, band, 1.0)
  
      # Test call stats order.
      cs = _CallStats(options)
      for i in range(20):
          fake_message = SendMessage(
              f"{i}".encode(), fake_actor_ref, ["name", True, (i,), {}]
          )
          cs.collect(fake_message, i)
      d = cs.to_dict()
      assert list(d["most_calls"].values())[0] == 20
      assert list(d["slow_calls"].values()) == list(
          reversed(range(10, 20))
      )
  
      # Test subtask stats order.
      ss = _SubtaskStats(options)
      counter = 0
      for i in range(20):
          for j in range(i):
              fake_message = _FakeSubtask(counter)
              ss.collect(fake_message, (str(j), "numa-0"), counter)
              counter += 1
      d = ss.to_dict()
      assert list(d["band_subtasks"].values()) == [
          19,
          18,
          17,
          16,
          15,
          5,
          4,
          3,
          2,
          1,
      ]
      assert list(d["slow_subtasks"].values()) == list(
          reversed(range(counter - 10, counter))
      )
  
file_path: mars/mars/oscar/tests/test_profiling.py
imports: import asyncio
  import dataclasses
  import os
  import pytest
  from ..profiling import ProfilingData, ProfilingDataOperator, DummyOperator, _ProfilingOptions, _CallStats, _SubtaskStats
  from ..backends.message import SendMessage
  from ...tests.core import check_dict_structure_same, mock
label_desc: Use image node_id 2 for calling a global function with example usage: test_collect() without return types