본문으로 건너뛰기
cccskills
무료GitHub에 공개

flight-profiler-vmtool

Inspect live Python class instances in a running process — find all instances of a class, examine their attributes/state, or invoke methods on them. Also supports forcing GC. Use this when you need to probe object-level runtime state beyond what watch/getglobal can provide.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

설치 방법 보기

포함된 파일(1)

  • SKILL.md10.0 KB

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

flight-profiler-vmtool

Inspect live Python class instances at runtime. The primary use case is state inspection — find all instances of a given class and examine their current attributes — and method invocation — call methods on found instances via -e expressions. Also supports forcing a garbage collection cycle.

Prerequisites: Read the flight-profiler-attach skill first for platform requirements, installation, permissions, and connection details.

When to Use

  • You want to find all live instances of a specific class and inspect their current attribute values (e.g., connection status, queue size, internal flags)
  • You need to invoke a method on a live instance to trigger a diagnostic action (e.g., instances[0].get_stats(), instances[0].dump_state())
  • You want to check how many instances of a class exist (potential memory leak investigation)
  • You need to filter instances by attribute to find the ones in a specific state (e.g., all connections with status == "error")
  • You suspect objects aren't being garbage collected and want to force GC

Usage

flight_profiler <pid> --cmd "vmtool -a <action> [options]" --no-color

Options

FlagDescriptionDefault
-a, --actionAction: forceGc or getInstancesrequired
-c, --classClass locator: module classrequired for getInstances
-e, --expr <value>Expression to evaluate on found instances. Variable is instances (a list).instances
-x, --expand <value>Object tree expand level (1-6)1
-n, --limit <value>Max instances to collect (-1 for unlimited)10
-r, --rawUse __str__ (equivalent to print(obj)) instead of default JSON serializationoff
-v, --verboseDisplay all nested items in list/dict without truncationoff

Choosing the Right -e Expression

-e directly controls what you see in the output. Always match the user's intent to the right expression — the default instances dumps all found objects.

User intent-e value
See all instancesinstances (default)
Count how many instances existlen(instances)
Inspect a single instance in detailinstances[0] (combine with -x 2)
Filter instances by attribute[i for i in instances if i.attr=='val']
Extract one field from all instances[i.field for i in instances]
Check if any instance matches a conditionany(i.status=='error' for i in instances)
Invoke a diagnostic method on an instanceinstances[0].get_stats()
Invoke a method on all instances[i.get_status() for i in instances]

Output Format

forceGc

Returns a plain text message:

Gc execute successfully, totally 76 unreachable objects are freed.

getInstances

Returns an expression result block (same format as getglobal/watch):

  EXPR:       instances
  TYPE:       <class 'list'>
  VALUE:      [
                Connection({'host': 'queue', 'port': 5672, 'status': 'error'}),
                Connection({'host': 'cache', 'port': 6379, 'status': 'idle'}),
                Connection({'host': 'db-replica', 'port': 5433, 'status': 'active'}),
                Connection({'host': 'db-primary', 'port': 5432, 'status': 'active'})
              ]
FieldDescription
EXPRThe expression used (default instances)
TYPEPython type of the expression result
VALUEThe value, formatted as JSON (or __str__ if -r)

Examples

1. Force garbage collection

flight_profiler <pid> --cmd "vmtool -a forceGc" --no-color
Gc execute successfully, totally 76 unreachable objects are freed.

2. Find all instances of a class

flight_profiler <pid> --cmd "vmtool -a getInstances -c __main__ Connection" --no-color
  EXPR:       instances
  TYPE:       <class 'list'>
  VALUE:      [
                Connection({'host': 'queue', 'port': 5672, 'status': 'error'}),
                Connection({'host': 'cache', 'port': 6379, 'status': 'idle'}),
                Connection({'host': 'db-replica', 'port': 5433, 'status': 'active'}),
                Connection({'host': 'db-primary', 'port': 5432, 'status': 'active'})
              ]

3. Count instances

flight_profiler <pid> --cmd "vmtool -a getInstances -c __main__ Connection -e len(instances)" --no-color
  EXPR:       len(instances)
  TYPE:       <class 'int'>
  VALUE:      4

4. Inspect a specific instance with expanded attributes

Use -e instances[0] to pick one instance and -x 2 to expand its attributes:

flight_profiler <pid> --cmd "vmtool -a getInstances -c __main__ Connection -e instances[0] -x 2" --no-color
  EXPR:       instances[0]
  TYPE:       <class '__main__.Connection'>
  VALUE:      Connection({
                "host": "queue",
                "port": 5672,
                "status": "error"
              })

5. Filter instances by attribute

Find only instances with status == "error". Note: list comprehension expressions with quotes need careful shell escaping:

flight_profiler <pid> --cmd 'vmtool -a getInstances -c __main__ Connection -e "[i for i in instances if i.status==\"error\"]"' --no-color
  EXPR:       [i for i in instances if i.status=="error"]
  TYPE:       <class 'list'>
  VALUE:      [
                Connection({'host': 'queue', 'port': 5672, 'status': 'error'})
              ]

6. Raw mode -r (use __str__ instead of JSON)

flight_profiler <pid> --cmd "vmtool -a getInstances -c __main__ Connection -r" --no-color
  EXPR:       instances
  TYPE:       <class 'list'>
  VALUE:      [<__main__.Connection object at 0x1056debb0>, <__main__.Connection object at 0x1056dec10>, ...]

Shows Python's default __str__ representation for each object.

7. Limit collected instances with -n

-n 2 collects at most 2 instances:

flight_profiler <pid> --cmd "vmtool -a getInstances -c __main__ Connection -n 2" --no-color
  EXPR:       instances
  TYPE:       <class 'list'>
  VALUE:      [
                Connection({'host': 'queue', 'port': 5672, 'status': 'error'}),
                Connection({'host': 'cache', 'port': 6379, 'status': 'idle'})
              ]

8. Inspect instances of a different class

flight_profiler <pid> --cmd "vmtool -a getInstances -c __main__ Task -e instances[0] -x 2" --no-color
  EXPR:       instances[0]
  TYPE:       <class '__main__.Task'>
  VALUE:      Task({
                "name": "cleanup_logs",
                "priority": 1,
                "task_id": 3
              })

-e Expression Guide

The -e option accepts any valid Python expression. The variable instances is a list containing the found class instances.

Common patterns:

# Default: show all instances
-e instances

# Count instances
-e len(instances)

# Pick a specific instance
-e instances[0]

# Filter by attribute
-e "[i for i in instances if i.status=='error']"

# Get a specific attribute from all instances
-e "[i.host for i in instances]"

# Check if any instance matches a condition
-e "any(i.status=='error' for i in instances)"

# Aggregate values
-e "sum(i.priority for i in instances)"

# Invoke a method on an instance
-e instances[0].get_stats()
-e instances[0].health_check()

# Invoke a method on all instances
-e "[i.get_status() for i in instances]"

Note: When using list comprehensions or expressions with quotes in shell, use single quotes for the outer --cmd and escaped double quotes inside the expression (see example 5).

Note: -e expressions execute inside the target process. Invoking methods on instances will actually run them — use this for read-only diagnostic methods (e.g., get_stats(), dump_state()). Avoid calling methods with side effects unless you intend to.

Handling Command Output

  • Long output: if many instances are found or instance attributes are large, redirect the output to a file for the user to review later:
    flight_profiler <pid> --cmd "vmtool -a getInstances -c __main__ Connection -n -1 -v" --no-color > /tmp/vmtool_output.txt
    
  • Short output: if the result is brief (e.g., a count via -e len(instances), or a few instances), display the full result directly to the user so they can see it immediately.

Handling Large Objects

When an object is too large to serialize or the output is truncated/incomplete:

  1. Prefer minimal extraction — use -e to extract only the fields you need, instead of the entire instance:

    # Instead of serializing the entire instance:
    -e instances[0]
    # Extract only the field you care about:
    -e instances[0].status
    -e [i.host for i in instances]
    -e type(instances[0]),len(vars(instances[0]))
    
  2. Use -v (verbose) — if you do need the full object, add -v to disable truncation so all nested items in lists/dicts are shown completely.

Tips

  • Use -e expressions to filter and analyze instances without dumping everything
  • The instances variable in -e is a list — you can use any Python list operation on it
  • Use -n to limit collection when you only need a sample — collecting all instances of a very common class can be slow
  • Instance order is determined by gc.get_referrers() — it may not match creation order

Related Commands

  • getglobal — inspect a known global variable (vmtool is for finding unknown instances)
  • console — for more complex inspection logic

Source Files

  • CLI plugin: flight_profiler/plugins/vmtool/cli_plugin_vmtool.py
  • Parser: flight_profiler/plugins/vmtool/vmtool_parser.py
  • Server plugin: flight_profiler/plugins/vmtool/server_plugin_vmtool.py

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

Prerequisites and connection details for attaching to a live Python process with PyFlightProfiler. Read this skill first before using any other PyFlightProfiler command (watch, trace, stack, perf, etc.).

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

alibaba/PyFlightProfiler462026년 9월 22일 업데이트

Inspect Python module global field or class static field value in a running Python process. Use this for safe, read-only inspection of global variables, configuration objects, or class-level state.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

alibaba/PyFlightProfiler462026년 9월 22일 업데이트

Translate a file path to its Python module name in a running Python process. Use this when you know a file path but need the module name for commands like watch, trace, or reload.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

alibaba/PyFlightProfiler462026년 9월 22일 업데이트

Hot-reload a Python function implementation from the latest file content without restarting the process. Use this to apply code fixes live after identifying a bug with watch/trace.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

alibaba/PyFlightProfiler462026년 9월 22일 업데이트

Inspect stack frames of a running Python process including thread stacks, native C-level frames, and async coroutine stacks. Use this to see what each thread is currently doing and diagnose hangs, deadlocks, or stuck async tasks.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

alibaba/PyFlightProfiler462026년 9월 22일 업데이트

Trace execution time of Python method invocations in a live process with call stack visualization. Use this to see a hierarchical call tree showing which sub-calls are slow and where time is spent within a function.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

alibaba/PyFlightProfiler462026년 9월 22일 업데이트

alibaba의 스킬 모두 보기

이 스킬의 문제 신고