Giter Club home page Giter Club logo

Comments (8)

Insutanto avatar Insutanto commented on May 18, 2024 2

I have a new pull request for support console_scripts. 😸

from scalene.

pohmelie avatar pohmelie commented on May 18, 2024 1
$ python -m scalene --help
scalene: could not find input file.

First of all, there are no docs. Secondly, what if I want to profile console_scripts or python modules (not files).
Even cProfile have some abilities for this:

$ python -m cProfile --help
Usage: cProfile.py [-o output_file_path] [-s sort] [-m module | scriptfile] [arg] ...

Options:
  -h, --help            show this help message and exit
  -o OUTFILE, --outfile=OUTFILE
                        Save stats to <outfile>
  -s SORT, --sort=SORT  Sort order when printing to stdout, based on
                        pstats.Stats class
  -m                    Profile a library module

from scalene.

jessemyers avatar jessemyers commented on May 18, 2024 1

@emeryberger, here's an example repo that reproduces the issues I originally reported:

https://github.com/jessemyers/scalene-repro

from scalene.

emeryberger avatar emeryberger commented on May 18, 2024 1

Updated to provide conventional command-line help and output redirection.

 % python3 -m scalene --help                                   
usage: scalene [-h] [-o OUTFILE] prog

Scalene: a high-precision CPU and memory profiler.
https://github.com/emeryberger/scalene

    for CPU profiling only:
  % python -m scalene yourprogram.py
    for CPU and memory profiling (Mac OS X):
  % DYLD_INSERT_LIBRARIES=$PWD/libscalene.dylib PYTHONMALLOC=malloc python -m scalene yourprogram.py
    for CPU and memory profiling (Linux):
  % LD_PRELOAD=$PWD/libscalene.dylib PYTHONMALLOC=malloc python -m scalene yourprogram.py

positional arguments:
  prog                  program to be profiled

optional arguments:
  -h, --help            show this help message and exit
  -o OUTFILE, --outfile OUTFILE
                        file to hold profiler output (default: stdout)

Will work on the other issue described here.

from scalene.

emeryberger avatar emeryberger commented on May 18, 2024

I'd love a repro case.

from scalene.

emeryberger avatar emeryberger commented on May 18, 2024

I'd be happy to add more descriptive text via help (I am planning to add an --outfile option, so the time is right).

Usage is currently just python -m scalene your-file-goes-here.py. It doesn't have explicit support for console_scripts or modules, but that shouldn't be hard to add. If you have some test cases you could share, that would be helpful.

from scalene.

pohmelie avatar pohmelie commented on May 18, 2024

console_scripts are just plain python files in python bin directory without extension with shebang string. This one is for alembic library:

#!/home/poh/.pyenv/versions/3.7.2/bin/python3.7
# -*- coding: utf-8 -*-
import re
import sys

from alembic.config import main

if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
    sys.exit(main())

They can be actually runned with scalene (did not test output though):

$ python -m scalene $(which alembic)

or in case of pyenv:

$ python -m scalene $(pyenv which alembic)

But, this is not very elegant.

For modules runpy should be used.

from scalene.

emeryberger avatar emeryberger commented on May 18, 2024

Merged, thanks!

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.