GET_PYTHON_PROFILER_OUTPUT (SNOWFLAKE.CORE) | Snowflake Documentation (original) (raw)

Returns output containing a report generated by the Python code profiler.

Syntax

SNOWFLAKE.CORE.GET_PYTHON_PROFILER_OUTPUT()

Arguments

_queryid_

Query ID of the stored procedure query for which profiling was enabled.

Returns

A string of type VARCHAR with the report generated by the code profiler.

Access control requirements

You must use the ACCOUNTADMIN role to call this function.

Examples

When the profiler is set to profile memory, rather than time, the setting looks something like the following.

Handler Name: main Python Runtime Version: 3.8 Modules Profiled: ['main_module'] File: _udf_code.py Function: main at line 4

Line # Mem usage Increment Occurrences Line Contents

4    245.3 MiB    245.3 MiB           1   def main(session, last_n, total):
5                                             # create sample dataset to emulate id + elapsed time
6    245.8 MiB      0.5 MiB           1       session.sql('''
7                                                 CREATE OR REPLACE TABLE sample_query_history (query_id INT, elapsed_time FLOAT)''').collect()
8    245.8 MiB      0.0 MiB           2       session.sql('''
9                                             INSERT INTO sample_query_history
10                                             SELECT
11                                             seq8() AS query_id,
12                                             uniform(0::float, 100::float, random()) as elapsed_time
13    245.8 MiB      0.0 MiB           1       FROM table(generator(rowCount => {0}));'''.format(total)).collect()
14
15                                             # get the mean of the last n query elapsed time
16    245.8 MiB      0.0 MiB           3       df = session.table('sample_query_history').select(
17    245.8 MiB      0.0 MiB           1           funcs.col('query_id'),
18    245.8 MiB      0.0 MiB           2           funcs.col('elapsed_time')).limit(last_n)
19
20    327.9 MiB     82.1 MiB           1       pandas_df = df.to_pandas()
21    328.9 MiB      1.0 MiB           1       mean_time = pandas_df.loc[:, 'ELAPSED_TIME'].mean()
22    320.9 MiB     -8.0 MiB           1       del pandas_df
23    320.9 MiB      0.0 MiB           1       return mean_time