Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3455668
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:38:33+00:00 2026-05-18T09:38:33+00:00

The Time Profiler can measure the amount of time spent on certain methods. Is

  • 0

The Time Profiler can measure the amount of time spent on certain methods. Is there a similar method that measures the number of times a method is called?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T09:38:33+00:00Added an answer on May 18, 2026 at 9:38 am

    DTrace can do this, but only in the iPhone Simulator (it’s supported by Snow Leopard, but not yet by iOS). I have two writeups about this technology on MacResearch here and here where I walk through some case studies of using DTrace to look for specific methods and when they are called.

    For example, I created the following DTrace script to measure the number of times methods were called on classes with the CP prefix, as well as total up the time spent in those methods:

    #pragma D option quiet
    #pragma D option aggsortrev
    
    dtrace:::BEGIN
    {
        printf("Sampling Core Plot methods ... Hit Ctrl-C to end.\n");
        starttime = timestamp;      
    }
    
    objc$target:CP*::entry
    {
        starttimeformethod[probemod,probefunc] = timestamp;
        methodhasenteredatleastonce[probemod,probefunc] = 1;
    }
    
    objc$target:CP*::return
    /methodhasenteredatleastonce[probemod,probefunc] == 1/
    {
        this->executiontime = (timestamp - starttimeformethod[probemod,probefunc]) / 1000;
        @overallexecutions[probemod,probefunc] = count();
        @overallexecutiontime[probemod,probefunc] = sum(this->executiontime);
        @averageexecutiontime[probemod,probefunc] = avg(this->executiontime);
    }
    
    dtrace:::END 
    {
        milliseconds = (timestamp - starttime) / 1000000;
        normalize(@overallexecutiontime, 1000);
        printf("Ran for %u ms\n", milliseconds);
        printf("%30s %30s %20s %20s %20s\n", "Class", "Method", "Total CPU time (ms)",  "Executions", "Average CPU time (us)");
        printa("%30s %30s %20@u %20@u %20@u\n", @overallexecutiontime, @overallexecutions, @averageexecutiontime);
    }
    

    This generates the following nicely formatted output:

            Class                         Method  Total CPU time (ms)           Executions Average CPU time (us)
          CPLayer                -drawInContext:                 6995                  352                19874
           CPPlot                -drawInContext:                 5312                   88                60374
    CPScatterPlot      -renderAsVectorInContext:                 4332                   44                98455
    CPXYPlotSpace        -viewPointForPlotPoint:                 3208                 4576                  701
           CPAxis               -layoutSublayers                 2050                   44                46595
    CPXYPlotSpace -viewCoordinateForViewLength:linearPlotRange:plotCoordinateValue:                 1870                 9152
    ...
    

    While you can create and run DTrace scripts from the command line, probably your best bet would be to create a custom instrument in Instruments and fill in the appropriate D code within that instrument. You can then easily run that against your application in the Simulator.

    Again, this won’t work on the device, but if you just want statistics on the number of times something is called, and not the duration it runs for, this might do the job.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can examine the optimization using profiler, size of the executable file and time
short version: Is there a good time based sampling profiler for Linux? long version:
For time profiler for XYZ, I can just run 'time XYZ', or if I
I have stored procedure that insanely times out every single time it's called from
I ran the profiler in firebug and found that the most time costly function
It's my first time using SQL Server Profiler and I'm wondering how can i
I try to run the Time Profiler on my iPad 2(5.0.1) on Xcode 4.2
I am having a hard time tracking this down since the profiler keeps crashing
I'm looking at the timeline in the Symfony2 web profiler. The total request time
I used the timing profile tool to identify that 95% of the time is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.