Giter Club home page Giter Club logo

Comments (17)

emeryberger avatar emeryberger commented on May 18, 2024 1

UPDATE: As of version 1.1.5, Scalene now supports @profile decorators.

from scalene.

ClemensA4t1qbit avatar ClemensA4t1qbit commented on May 18, 2024 1

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.

chiragjn avatar chiragjn commented on May 18, 2024

+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.

emeryberger avatar emeryberger commented on May 18, 2024

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.

johanvergeer avatar johanvergeer commented on May 18, 2024

@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.

emeryberger avatar emeryberger commented on May 18, 2024

Sounds great! I look forward to a PR. Let me know if you have any questions, etc.

from scalene.

johanvergeer avatar johanvergeer commented on May 18, 2024

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.

emeryberger avatar emeryberger commented on May 18, 2024

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.

indigoviolet avatar indigoviolet commented on May 18, 2024

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.

emeryberger avatar emeryberger commented on May 18, 2024

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.

indigoviolet avatar indigoviolet commented on May 18, 2024

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.

emeryberger avatar emeryberger commented on May 18, 2024

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.

indigoviolet avatar indigoviolet commented on May 18, 2024

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.

emeryberger avatar emeryberger commented on May 18, 2024

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.

ClemensA4t1qbit avatar ClemensA4t1qbit commented on May 18, 2024

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.

emeryberger avatar emeryberger commented on May 18, 2024

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.

emeryberger avatar emeryberger commented on May 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.