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

force_print argument for output behaves strange #657

Open
danlkv opened this issue Aug 18, 2023 · 6 comments · May be fixed by #658
Open

force_print argument for output behaves strange #657

danlkv opened this issue Aug 18, 2023 · 6 comments · May be fixed by #658

Comments

@danlkv
Copy link

danlkv commented Aug 18, 2023

https://github.com/plasma-umass/scalene/blob/6980cb0c41df6ae724a2ce8d4686398b4b058853/scalene/scalene_json.py#L109C12-L109C15

Shouldn't it be if force_print and not ...? The printing will happen if force_print=False.

@danlkv danlkv linked a pull request Aug 18, 2023 that will close this issue
@emeryberger
Copy link
Member

I agree that this looks unintuitive but that line of code has been in the codebase for 2 years. Can you point to a bug here?

@danlkv
Copy link
Author

danlkv commented Aug 18, 2023

I think the issue is that there seems to be no way to output only the functions I care about (but maybe there's another way?), only the full file. The output_profile_line never returns a False, which in turn makes output print every line.

@emeryberger
Copy link
Member

So I see that there is some code that is always executing now that output_profile_line returns a "null" entry instead of False (which led to some issues, addressed by cadb8f4). Are you using @profile to select the functions you care about? You should definitely not be using Scalene's internal functions.

@danlkv
Copy link
Author

danlkv commented Aug 19, 2023

I see. No, I use scalene_profiler.Scalene.profile to wrap the function in runtime, since adding and removing @profile everywhere is a hassle:) I was under impression that using @profile and Scalene.profile should give the same results. It seems that there is some other mechanism for filtering lines in addition to profile_this_code.

@emeryberger
Copy link
Member

It's the same mechanism, but it was never intended to be called directly. I like the idea of listing a bunch of functions to profile without selecting them one by one. Can you give me an example of how you are doing this? Might make sense to expose an API.

@danlkv
Copy link
Author

danlkv commented Aug 19, 2023

The usecase is that I have profile.py script that imports a library that I want to profile. It's simply calling Scalene.profile on whatever function I want to profile. If I run scalene profile.py it works, but requires the library files to be within working directory tree (can workaround with --profile-only).

  for func in [mylib.func1, mylib.Class1.method1]:
      scalene_profiler.Scalene.profile(func)
  logger.log(10, f"{scalene_profiler.Scalene.__dict__['_Scalene__functions_to_profile']=}")
  scalene_profiler.Scalene.start()
  func_to_run(*args, **kwargs)
  scalene_profiler.Scalene.stop()

Unrelated, but something that I found useful is to start scalene from within a python script with pre-configured parameters. This removes the need to know or remember to run the script as scalene [params] profile.py: you can run python profile.py and get the same result. Example

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 a pull request may close this issue.

2 participants