Skip to content
cccskills
FreePublished on 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.

The English summary is being prepared. Showing the original description.

See how to install

Files included (1)

  • SKILL.md10.0 KB

SKILL.md (original)

Review the instructions the agent will receive before you install.

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

Reviews

No reviews yet. Tell others what you thought.

Comments

No login needed. Share how it worked for you, ask a question, or note where it did not run.

No comments yet. Be the first to write one.

Comments are published right away. Do not include personal information such as email addresses or phone numbers. Up to 2 URLs.

0 / 1,000 characters

This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.

More skills from this repository

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.).

The English summary is being prepared. Showing the original description.

alibaba/PyFlightProfiler46Updated Sep 22, 2026

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.

The English summary is being prepared. Showing the original description.

alibaba/PyFlightProfiler46Updated Sep 22, 2026

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.

The English summary is being prepared. Showing the original description.

alibaba/PyFlightProfiler46Updated Sep 22, 2026

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.

The English summary is being prepared. Showing the original description.

alibaba/PyFlightProfiler46Updated Sep 22, 2026

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.

The English summary is being prepared. Showing the original description.

alibaba/PyFlightProfiler46Updated Sep 22, 2026

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.

The English summary is being prepared. Showing the original description.

alibaba/PyFlightProfiler46Updated Sep 22, 2026

See all skills by alibaba

Report a problem with this skill