GET_PYTHON_PROFILER_OUTPUT
GET_PYTHON_PROFILER_OUTPUT (SNOWFLAKE.CORE)
Python 코드 프로파일러가 생성한 보고서가 담긴 출력을 반환해요.
출처: Snowflake SQL Reference - GET_PYTHON_PROFILER_OUTPUT (SNOWFLAKE.CORE)
본문
구문
SNOWFLAKE.CORE.GET_PYTHON_PROFILER_OUTPUT(<query_id>)
인자
query_id
- 프로파일링이 활성화된 저장 프로시저 쿼리의 쿼리 ID예요.
반환 값
코드 프로파일러가 생성한 보고서가 담긴 VARCHAR 타입의 문자열이에요.
접근 제어 요구 사항
이 함수를 호출하려면 ACCOUNTADMIN 역할을 사용해야 해요.
예시
프로파일러가 시간이 아니라 메모리를 프로파일하도록 설정되어 있으면 설정값이 대략 다음과 같이 보여요.
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
더 알아보기
- System functions — 시스템 함수 모음