Comments (17)
UPDATE: As of version 1.1.5, Scalene now supports @profile
decorators.
from scalene.
My bad; I used from scalene import profile
, but the trick is to, as you say, just use @profile
. I was just a bit confused because my IDE complained that in that case profile
isn't defined anywhere.
I changed it (removed my import) and it does seem to work.
PS: I loved your ACM Tech Talk. So many spot-on Simpsons references.
from scalene.
+1, I would also like this
I tried doing this when scalene was first announced
emeryberger/scalene@master...chiragjn:contextmanager_patch
Since scalene does line by line output. it would either output too much code or crash with ipython cells (because they are not files).
My fork is also out of date by now, I might sync up and give it another shot if I get some time
from scalene.
So, did this patch work? It doesn't look like it would take much effort to resolve the conflicts (I can do this, just let me know).
from scalene.
@emeryberger Since this hasn't been updated, and I would like to have a context manager for my project, I would like to pick this one up.
from scalene.
Sounds great! I look forward to a PR. Let me know if you have any questions, etc.
from scalene.
It seems to be harder than I initially thought. Would you be willing to call some time so we can discuss a good approach to solve this?
from scalene.
Sure. Drop me a line: [email protected].
I do think that it doesn't make sense to disable a lot of the functionality; in effect, it seems like the contextmanager approach should just be a way to say "just give me the results from this function"; that maybe is most expediently handled in the should_trace
method, and then with some additional logic in the profile output routine.
from scalene.
was there any progress on this? one reason for wanting it is to leave out startup overhead from the profile (ie. if I know that the startup overhead is paid only once or not in the perf-intensive part of my code)
from scalene.
It would be straightforward to have a command-line parameter for a start profile delay, but I am not clear how much it would matter for any sufficiently long running program, which would eventually amortize the startup cost. But if itβs a real need, it would be easy to add.
from scalene.
sorry I wasn't clear earlier. I meant that in my program, there is an expensive data loading step at the beginning that needs to be executed once, and then a loop over less expensive steps. I want to profile the less expensive step. I'd like to skip profiling the data loading step.
from scalene.
So would it be practical to time the expensive data loading part, and then have Scalene start its profiling after that much time has elapsed?
from scalene.
Yes, that is certainly one approach, but the approach suggested in this issue (a context manager or other way of turning profiling on and off programmatically instead of at the command line) would be my preference - seems cleaner and more flexible.
from scalene.
From an implementation perspective, it's challenging. Scalene (when it's not invoked with --cpu-only
) uses a library that replaces all memory operations (allocations, frees, and copying). It's not something you can safely turn and off. What I would actually have to do is profile all the time, but simply discard profiling information when profiling is "off". Since even this would require refactoring and special casing (what happens with multiple processes, for example?), I'd really like to see a compelling case that isn't handled by something much simpler, like delaying the start of profiling.
from scalene.
UPDATE: As of version 1.1.5, Scalene now supports
@profile
decorators.
That's a great feature but I can't seem to figure out how it's used. I have a little test script where the code to profile is in a function decorated with @profile
. But running scalene still produces the full program's profile. Is there a command line argument I need to pass? If so, it doesn't seem to be mentioned when running scalene --help
from scalene.
It should "just work"; I just tested it on a short script and it behaved as expected (no command-line parameters needed). Can you attach the script?
from scalene.
Great! I'm going to close this issue because I think it's easy enough to use @profile
instead of context managers and it satisfies the same need, AFAICT.
from scalene.
Related Issues (20)
- scalene memory profiling is slower then memray! HOT 2
- Full stack profiling/ full stack tracing a la pyinstrument
- scalene CLI changes the behavior of sys module (sys.executable) HOT 6
- Scalene compatibility with DeepSpeed Python scripts HOT 3
- AttributeError: 'staticmethod' object has no attribute '__code__' HOT 2
- Scalene v1.5.34 does not offer OpenAI suggestion option | CPU and GPU columns are also missing. HOT 1
- Build fails with a GCC error ("unused result" in the printf redefinition) HOT 2
- Web browser doesn't launch on NixOS
- Proposal: Serve results via a webserver (from PR #779 discussion) HOT 4
- Programs using Qiskit fail to run with Scalene >1.5.31.1 HOT 3
- AttributeError: 'str' object has no attribute 'suffix' HOT 5
- Per-process GPU accounting isn't working under CUDA 12
- Scalene can't open browser on MacOS HOT 4
- Is there a way to measure time spent in GC? HOT 3
- GPU and memory columns not present HOT 7
- Python 3.11 support HOT 1
- defaults to cli HOT 2
- Segmentation fault profiling project
- Getting SIGSEGV with empty program HOT 5
- Probable bug with scalene when profiling async code HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from scalene.