> For the complete documentation index, see [llms.txt](https://mariadb.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mariadb.com/docs/server/reference/system-tables/sys-schema/sys-schema-stored-procedures/ps_trace_thread.md).

# ps\_trace\_thread

## Syntax

```
ps_trace_thread(thread_id, outfile, max_runtime, interval, start_fresh, auto_setup, debug)
```

## Description

`ps_trace_thread` is a [stored procedure](/docs/server/server-usage/stored-routines/stored-procedures.md) available with the [Sys Schema](/docs/server/reference/system-tables/sys-schema.md).

Parameters:

* thread\_id `INT`: The thread to trace.
* outfile `VARCHAR(255)`: Name of the .dot file to be create.
* max\_runtime `DECIMAL(20,2)`: Maximum time in seconds to collect data. Fractional seconds can be used, and `NULL` results in data being collected for the default sixty seconds.
* interval `DECIMAL(20,2)`: Time in seconds to sleep between data collection. Fractional seconds can be used, and `NULL` results in the sleep being the default one second.
* start\_fresh `BOOLEAN`: Whether to reset all Performance Schema data before tracing.
* auto\_setup `BOOLEAN`: Whether to disable all other threads, enable all instruments and consumers, and reset the settings at the end of the run.
* debug `BOOLEAN`: Whether to include `file:lineno` information in the graph.

Dumps all Performance Schema data for an instrumented thread to a .dot formatted graph file (for use with the [DOT graph description language](https://en.wikipedia.org/wiki/DOT_\(graph_description_language\))). All returned result sets should be used for a complete graph.

Session [binary logging](/docs/server/server-management/server-monitoring-logs/binary-log.md) is disabled during execution, by adjusting the [sql\_log\_bin](/docs/server/ha-and-performance/standard-replication/replication-and-binary-log-system-variables.md#sql_log_bin) session value (note the permissions required).

## Examples

```sql
CALL sys.ps_trace_thread(25, CONCAT('/tmp/stack-', REPLACE(NOW(), ' ', '-'), '.dot'), 
  NULL, NULL, TRUE, TRUE, TRUE);

--------------------+
| summary            |
+--------------------+
| Disabled 0 threads |
+--------------------+

+---------------------------------------------+
| Info                                        |
+---------------------------------------------+
| Data collection starting for THREAD_ID = 25 |
+---------------------------------------------+

+-----------------------------------------------------------+
| Info                                                      |
+-----------------------------------------------------------+
| Stack trace written to /tmp/stack-2023-04-05-19:06:29.dot |
+-----------------------------------------------------------+

+-------------------------------------------------------------------+
| Convert to PDF                                                    |
+-------------------------------------------------------------------+
| dot -Tpdf -o /tmp/stack_25.pdf /tmp/stack-2023-04-05-19:06:29.dot |
+-------------------------------------------------------------------+

+-------------------------------------------------------------------+
| Convert to PNG                                                    |
+-------------------------------------------------------------------+
| dot -Tpng -o /tmp/stack_25.png /tmp/stack-2023-04-05-19:06:29.dot |
+-------------------------------------------------------------------+
```

<sub>*This page is licensed: CC BY-SA / Gnu FDL*</sub>

{% @marketo/form formId="4316" %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://mariadb.com/docs/server/reference/system-tables/sys-schema/sys-schema-stored-procedures/ps_trace_thread.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
