Seiden Group
Modern Development & Open Source for IBM i
  • Link to LinkedIn
  • Link to Mail
  • Home
  • Seiden PHP+
    • Seiden PHP+
    • Install & Learn
    • SmartSupport
    • PHP Migrations & Upgrades
    • Success Stories
    • Free PHP Assessment
    • Documentation
    • What’s New (Changelog)
  • IBM i Services
    • Development
    • Training & Mentoring
    • Open Source Setup & Upgrades
    • SSL/TLS Install & Learn
    • Performance
  • Support
    • Open Source & PHP
    • VS Code for i
    • Developer Support
    • Support Success Stories
  • VS Code for i
    • Support
    • Training
    • Code for i Resource Guide
    • Getting Started Videos
    • Code for IBM i Fridays
  • Free Stuff
    • IBM i Strategy & Tips
    • PHP Upgrade Assessment
    • CNX Valence Assessment
    • VS Code for IBM i Resources
    • Code for IBM i Fridays
    • QCachegrind Download
    • PHP Toolkit for IBM i Resources
    • Qshell on i Library
  • Blog
  • About
    • About Our Team
    • About Alan Seiden
    • Speakers & Sessions
    • In the News
  • Contact
  • 201.447.2437
  • Search
  • Menu Menu

Seiden Group Blog

How to Measure Python Speed with QCachegrind

March 17, 2021/1 Comment/in Python /by Calvin Buckley

Python on IBM iWant to know which parts of your Python program take how much time? Which parts are slow, and how often they are called? Python includes tools to measure speed, but it’s not easy to visualize their meaning.

To make it easier, the QCachegrind tool graphically displays profiler output from a variety of languages. We first introduced our build of QCachegrind as a PHP tool, but you can put your Python programs under the QCachegrind microscope as well.

Generating Profiles with cProfile

The cProfile module is built into Python. To profile pieces of your code, you can include cProfile and invoke it with a fragment of code to run:

PHP
1
2
3
import cProfile
# [...]
cProfile.run("my_function()")

This will get you output like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
         8294 function calls (8087 primitive calls) in 0.596 seconds
 
   Ordered by: standard name
 
   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
       31    0.000    0.000    0.000    0.000 :103(release)
       31    0.000    0.000    0.000    0.000 :143(__init__)
       31    0.000    0.000    0.000    0.000 :147(__enter__)
       31    0.000    0.000    0.000    0.000 :151(__exit__)
       31    0.000    0.000    0.000    0.000 :157(_get_module_lock)
       31    0.000    0.000    0.000    0.000 :176(cb)
     45/4    0.000    0.000    0.058    0.015 :211(_call_with_frames_removed)
 
[...]

This is already useful, but we want to save it to a file instead, for a better visualization. To write the data to a file, you can provide a filename as the second argument:

1
cProfile.run("my_function(2)", "with_two")

Viewing Profiles in QCachegrind

First, you’ll need to convert your profiling data from Python’s native profile format to the one QCachegrind uses. The pyprof2calltree utility can do this for us. You’ll need to run this conversion on the same system you captured the data from, because of how Python stores the data.

Install it from pip:

1
pip3 install pyprof2calltree

Then use it on the profiler output that cProfile generated:

1
pyprof2calltree -i cprofile -o cachegrind.output

Once you copy over the output file to your computer, you can then open the generated file in QCachegrind.

Viewing a Python profile output

Viewing Python profile output

Try QCachegrind with Your Python Applications

QCachegrind is free, open source, and can be downloaded for multiple platforms in a version we built for the community. It works with output from PHP, Python, Node.js, and more.

If you try QCachegrind with your applications, let us know what you discover.

Tags: application profiling, IBM i, Python, QCachegrind
Share this entry
  • Share on Facebook
  • Share on X
  • Share on Pinterest
  • Share on LinkedIn
  • Share on Tumblr
  • Share on Reddit
  • Share by Mail
https://www.seidengroup.com/wp-content/uploads/2017/03/SeidenLogo-180.png 0 0 Calvin Buckley https://www.seidengroup.com/wp-content/uploads/2017/03/SeidenLogo-180.png Calvin Buckley2021-03-17 10:42:192022-06-16 23:20:34How to Measure Python Speed with QCachegrind
Calvin Buckley

About Calvin Buckley

Recognized as an IBM Champion and a 2020 Fresh Face of IBM i, Calvin exhibits remarkable talent for expanding the use of IBM i through open ...Read More

1 reply
  1. Brij Bhushan
    Brij Bhushan says:
    April 2, 2021 at 9:40 am

    Hello Calvin,
    It is a great sharing…I am very much pleased with the contents you have mentioned. I wanted to thank you for this great article.

    Reply

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

SUBSCRIBE
Open Thinking
Monthly IBM i Strategy & Tips
  • This field is for validation purposes and should be left unchanged.

IBM i Development

  • RPG, COBOL, SQL, Node,
    PHP, Python, Valance, etc.
  • Modernization. Integration.
  • Web and API Solutions
  • Legacy Maintenance
    ...
LET'S GET IT DONE!

Recent Posts

  • Do You Need IBM i Observability?
  • PHP 8.6 is Coming Soon to IBM i
  • Safer npm installation is on the way for Node.js (and all JavaScript)
  • Access Modern Security for IBM i and Connected Web Environments
  • IBM i: A Natural Platform for Agentic AI
  • PHP on IBM i in 2026: The Modernization Engine
  • Your “AS/400” Is a Modern IBM i Platform
  • MCP + AI for IBM i Teams (with a MongoDB example)
  • GnuPG PHP Extension for IBM i: Now Included with Seiden Support
  • Getting Started with Code for IBM i: A Lunch & Learn Video

SEIDEN GROUP: Modern Development & Open Source for IBM i

Home   |   Seiden PHP+   |   IBM i Services  |   Support   |   VS Code for i   |   Free Stuff   |   Blog  |   Privacy Policy  |   Contact         201.447.2437

© 2026 Seiden Group, LLC
  • Link to LinkedIn
  • Link to Mail
Link to: Reading and Writing Physical Files in a Shell using Rfile Link to: Reading and Writing Physical Files in a Shell using Rfile Reading and Writing Physical Files in a Shell using Rfile Link to: Set Up PHP Servers in Seconds with Siteadd Link to: Set Up PHP Servers in Seconds with Siteadd Set Up PHP Servers in Seconds with Siteadd
Scroll to top Scroll to top Scroll to top