cprofile

cProfile saving data to file causes jumbles of characters

可紊 提交于 2019-11-29 22:08:52
I am using cProfile on a module named bot4CA.py so in the console I type: python -m cProfile -o thing.txt bot4CA.py After the module runs and exits, it creates a file named thing.txt and when I open it, there is some information there, and the rest is a jumble of characters instead of a neatly organized file of data which is what I want. Does any one know how to use cProfile and end up with neatly organized table of data like when using it normally on command line, except in a file? Here's an example of some of the data in the .txt file: {( s) build\bdist.win32\egg\colorama\winterm.pyi' t

App Engine: Is time.sleep() counting towards my quotas?

試著忘記壹切 提交于 2019-11-29 18:18:31
问题 Hey. I'm working on an App Engine app that involves queries to the Google Maps API for geocoding. Google Maps doesn't like too much requests so I put a 1 second delay between each request with time.sleep(1) . I noticed that my quotas are running low in my GAE dashboard and decided to run a short test: import cProfile import time def foo(): time.sleep(3) cProfile.run('foo()') Which gave me the following output: 4 function calls in 3.003 CPU seconds Ordered by: standard name ncalls tottime

profiling a method of a class in Python using cProfile?

懵懂的女人 提交于 2019-11-28 22:33:29
I'd like to profile a method of a function in Python, using cProfile. I tried the following: import cProfile as profile # Inside the class method... profile.run("self.myMethod()", "output_file") But it does not work. How can I call a self.method with "run"? Use the profilehooks decorator http://pypi.python.org/pypi/profilehooks EDIT: Sorry, didn't realise that the profile call was in a class method. run just tries to exec the string you pass it. If self isn't bound to anything in the scope of the profiler you are using, you can't use it in run ! Use the runctx method to pass in the local and

cProfile saving data to file causes jumbles of characters

假如想象 提交于 2019-11-28 17:00:51
问题 I am using cProfile on a module named bot4CA.py so in the console I type: python -m cProfile -o thing.txt bot4CA.py After the module runs and exits, it creates a file named thing.txt and when I open it, there is some information there, and the rest is a jumble of characters instead of a neatly organized file of data which is what I want. Does any one know how to use cProfile and end up with neatly organized table of data like when using it normally on command line, except in a file? Here's an

Python multiprocess profiling

江枫思渺然 提交于 2019-11-28 08:53:51
I'm struggling to figure out how to profile a simple multiprocess python script import multiprocessing import cProfile import time def worker(num): time.sleep(3) print 'Worker:', num if __name__ == '__main__': for i in range(5): p = multiprocessing.Process(target=worker, args=(i,)) cProfile.run('p.start()', 'prof%d.prof' %i) I'm starting 5 processes and therefore cProfile generates 5 different files. Inside of each I want to see that my method 'worker' takes approximately 3 seconds to run but instead I'm seeing only what's going on inside the 'start'method. I would greatly appreciate if

profiling a method of a class in Python using cProfile?

拜拜、爱过 提交于 2019-11-27 21:06:28
问题 I'd like to profile a method of a function in Python, using cProfile. I tried the following: import cProfile as profile # Inside the class method... profile.run("self.myMethod()", "output_file") But it does not work. How can I call a self.method with "run"? 回答1: Use the profilehooks decorator http://pypi.python.org/pypi/profilehooks 回答2: EDIT: Sorry, didn't realise that the profile call was in a class method. run just tries to exec the string you pass it. If self isn't bound to anything in

Python getting meaningful results from cProfile

跟風遠走 提交于 2019-11-27 00:42:57
问题 I have a Python script in a file which takes just over 30 seconds to run. I am trying to profile it as I would like to cut down this time dramatically. I am trying to profile the script using cProfile , but essentially all it seems to be telling me is that yes, the main script took a long time to run, but doesn't give the kind of breakdown I was expecting. At the terminal, I type something like: cat my_script_input.txt | python -m cProfile -s time my_script.py The results I get are: <my

How can I speed up fetching pages with urllib2 in python?

爷,独闯天下 提交于 2019-11-26 21:35:48
I have a script that fetches several web pages and parses the info. (An example can be seen at http://bluedevilbooks.com/search/?DEPT=MATH&CLASS=103&SEC=01 ) I ran cProfile on it, and as I assumed, urlopen takes up a lot of time. Is there a way to fetch the pages faster? Or a way to fetch several pages at once? I'll do whatever is simplest, as I'm new to python and web developing. Thanks in advance! :) UPDATE: I have a function called fetchURLs() , which I use to make an array of the URLs I need so something like urls = fetchURLS() .The URLS are all XML files from Amazon and eBay APIs (which

Using cProfile results with KCacheGrind

有些话、适合烂在心里 提交于 2019-11-26 18:15:49
I'm using cProfile to profile my Python program. Based upon this talk I was under the impression that KCacheGrind could parse and display the output from cProfile. However, when I go to import the file, KCacheGrind just displays an 'Unknown File Format' error in the status bar and sits there displaying nothing. Is there something special I need to do before my profiling stats are compatible with KCacheGrind? ... if profile: import cProfile profileFileName = 'Profiles/pythonray_' + time.strftime('%Y%m%d_%H%M%S') + '.profile' profile = cProfile.Profile() profile.run('pilImage = camera.render

How can I speed up fetching pages with urllib2 in python?

懵懂的女人 提交于 2019-11-26 07:58:55
问题 I have a script that fetches several web pages and parses the info. (An example can be seen at http://bluedevilbooks.com/search/?DEPT=MATH&CLASS=103&SEC=01 ) I ran cProfile on it, and as I assumed, urlopen takes up a lot of time. Is there a way to fetch the pages faster? Or a way to fetch several pages at once? I\'ll do whatever is simplest, as I\'m new to python and web developing. Thanks in advance! :) UPDATE: I have a function called fetchURLs() , which I use to make an array of the URLs I