Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNOW-1527717: Add profiler snowpark API #2252

Open
wants to merge 35 commits into
base: main
Choose a base branch
from
Open

Conversation

sfc-gh-yuwang
Copy link
Collaborator

  1. Which Jira issue is this PR addressing? Make sure that there is an accompanying issue to your PR.

    Fixes SNOW-NNNNNNN

  2. Fill out the following pre-review checklist:

    • I am adding a new automated test(s) to verify correctness of my new code
      • If this test skips Local Testing mode, I'm requesting review from @snowflakedb/local-testing
    • I am adding new logging messages
    • I am adding a new telemetry message
    • I am adding new credentials
    • I am adding a new dependency
    • If this is a new feature/behavior, I'm adding the Local Testing parity changes.
  3. Please describe how your code solves the related issue.

    Please write a short description of how your code change solves the related issue.

Copy link

Seems like your changes contain some Local Testing changes, please request review from @snowflakedb/local-testing

Copy link

Seems like your changes contain some Local Testing changes, please request review from @snowflakedb/local-testing

src/snowflake/snowpark/profiler.py Outdated Show resolved Hide resolved
src/snowflake/snowpark/profiler.py Outdated Show resolved Hide resolved
src/snowflake/snowpark/profiler.py Outdated Show resolved Hide resolved
src/snowflake/snowpark/session.py Outdated Show resolved Hide resolved
src/snowflake/snowpark/profiler.py Outdated Show resolved Hide resolved
src/snowflake/snowpark/profiler.py Outdated Show resolved Hide resolved
Copy link

Seems like your changes contain some Local Testing changes, please request review from @snowflakedb/local-testing

Copy link

Seems like your changes contain some Local Testing changes, please request review from @snowflakedb/local-testing

Copy link

Seems like your changes contain some Local Testing changes, please request review from @snowflakedb/local-testing

Copy link

Seems like your changes contain some Local Testing changes, please request review from @snowflakedb/local-testing

Copy link

Seems like your changes contain some Local Testing changes, please request review from @snowflakedb/local-testing

Copy link

Seems like your changes contain some Local Testing changes, please request review from @snowflakedb/local-testing

Copy link

Seems like your changes contain some Local Testing changes, please request review from @snowflakedb/local-testing

Copy link

Seems like your changes contain some Local Testing changes, please request review from @snowflakedb/local-testing

Copy link

Seems like your changes contain some Local Testing changes, please request review from @snowflakedb/local-testing

src/snowflake/snowpark/profiler.py Outdated Show resolved Hide resolved
src/snowflake/snowpark/profiler.py Outdated Show resolved Hide resolved
src/snowflake/snowpark/profiler.py Show resolved Hide resolved
Copy link

Seems like your changes contain some Local Testing changes, please request review from @snowflakedb/local-testing

Copy link

Seems like your changes contain some Local Testing changes, please request review from @snowflakedb/local-testing

Copy link

Seems like your changes contain some Local Testing changes, please request review from @snowflakedb/local-testing

Copy link

Seems like your changes contain some Local Testing changes, please request review from @snowflakedb/local-testing

Copy link

Seems like your changes contain some Local Testing changes, please request review from @snowflakedb/local-testing

Copy link

Seems like your changes contain some Local Testing changes, please request review from @snowflakedb/local-testing

Copy link

Seems like your changes contain some Local Testing changes, please request review from @snowflakedb/local-testing

Comment on lines 26 to 37
self.stage = stage
self.active_profiler = active_profiler
self.modules_to_register = []
self.register_modules_sql = ""
self.set_targeted_stage_sql = ""
self.enable_profiler_sql = ""
self.disable_profiler_sql = ""
self.set_active_profiler_sql = ""
self.pattern = r"WITH\s+.*?\s+AS\s+PROCEDURE\s+.*?\s+CALL\s+.*"
self.session = session
self._prepare_sql()
self.query_history = None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want those member variable to be public? if not we can add "_" (self._stage) in front of them to make them private

Registered nodules will be overwritten by this function,
use this function with an empty string will remove registered modules.
Args:
modules: List of names of stored procedures.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is modules a specific term used in profiler? I find it conceptually hard to link this to the name of stored procedures..

self,
stage: Optional[str] = "",
active_profiler: Optional[str] = "LINE",
session: Optional["snowflake.snowpark.Session"] = None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what should customer expect to happen if session is None?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

session is required for profiler to work.
There is two way to use profiler as described in the design doc.
In context manager, session needed to be provided when create the context manager.
In profiler class, session is set when registering profiler.
This is why I make it optional here.

== 0
):
self.session.sql(
f"create temp stage if not exists {self.stage} FILE_FORMAT = (RECORD_DELIMITER = NONE FIELD_DELIMITER = NONE )"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

temp stage gets dropped at the end of the session which means we might lose all the profiler data.
when are users going to access the file, after the session or during the session?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If user want to access it after the session, user would want to use a permanent stage they created.
when user give a stage name that does not exist, we expect user want to create a temp stage.

Comment on lines 120 to 126
def enable_profiler(self):
"""
Enable profiler. Profiles will be generated until profiler is disabled.
"""
self.session.sql(self.enable_profiler_sql).collect()

def disable_profiler(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I think the names of these two could be simplified as disable and enable:

Suggested change
def enable_profiler(self):
"""
Enable profiler. Profiles will be generated until profiler is disabled.
"""
self.session.sql(self.enable_profiler_sql).collect()
def disable_profiler(self):
def enable(self):
"""
Enable profiler. Profiles will be generated until profiler is disabled.
"""
self.session.sql(self.enable_profiler_sql).collect()
def disable(self):

src/snowflake/snowpark/session.py Outdated Show resolved Hide resolved
def register_profiler(self, profiler: Profiler):
"""Register a profiler to current session, all action are actually executed during this function"""
self.profiler = profiler
self.profiler.session = self
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we pass a profiler which is created a different session, is the overwriting here on purpose?
or another way to ask the question is should one profiler only be linked with one session?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good question, I think one profiler link to only one session is a good idea since the new session could have different setting.

@sfc-gh-yuwang
Copy link
Collaborator Author

Copy link

Seems like your changes contain some Local Testing changes, please request review from @snowflakedb/local-testing

Copy link

Seems like your changes contain some Local Testing changes, please request review from @snowflakedb/local-testing

Copy link

Seems like your changes contain some Local Testing changes, please request review from @snowflakedb/local-testing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants