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 6052315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:54:54+00:00 2026-05-23T07:54:54+00:00

I want to do something like this: #import <sys/time.h> typedef long long int64; int64

  • 0

I want to do something like this:

#import <sys/time.h>

typedef long long int64;

int64 int64Micro(void)
{
    struct timeval timestruct;
    gettimeofday(&timestruct, NULL);
    return ((int64)timestruct.tv_sec)*((int64)1000000)+(int64)timestruct.tv_usec;
}

int64 lasttime = 0;

id objc_msgSend(id self, SEL op, ...)
{
    int64 starttime = int64Micro();
    va_list argptr;
    va_start(argptr, op);
    id retVal = 0;//objc_msgSendv(self, op, method_getSizeOfArguments(op), argptr);
    va_end(argptr);
    int64 cost = int64Micro()-starttime;
    if(cost > 1000)
        NSLog(@"%@() : %lld µs\n", NSStringFromSelector(op), cost);
    return retVal;
}

to be able to log for every method at a central place in code, when it is getting very expensive (the 1.000µs or 1 ms is just an example-value, can be adjusted of course, but should not be to small, as otherwise the logging will cost more time as the execution of the method, being logged, for most methods).

As on iPhone dynamic libs aren’t possible, there is no way, to replace the objc_msgSend-implementation, which is called by precompiled frameworks, without recompiling them, but in my code actually my implementation is called instead of the one from the objc-runtime.

But this line

id retVal = 0;//objc_msgSendv(self, op, method_getSizeOfArguments(op), argptr)

is commented out, as it should work in objc 1.0, but in objc 2.0 objc_msgSendv() isn’t available anymore, same as method_getSizeOfArguments().

So, is there any way to do this, without having to rebuild the objc runtime and without having to re-implement the original behavior of objc_msgSend and it’s siblings by copy-and paste those thousands of platform dependent assembly code lines from the source of the objc runtime?

I already thought about GCC’s __builtin_apply() function, to call the original objc_msgSend(), but it seems, there is no way to know the size in bytes of the variable parameters passed to objc_msgSend() for a certain call to it.

  • 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-23T07:54:54+00:00Added an answer on May 23, 2026 at 7:54 am

    Swapping out objc_msgSend to measure performance like this is a bad idea for a few reasons.

    1. There are actually a number of objc_msgSend variants depending on the parameter types and return types. You’d have to re-implement all of those.
    2. The performance of your app is likely to degrade massively. When you’re trying to measure performance, this isn’t the best way to do it.
    3. For certain selectors, the compiler actually issues a objc_msgSend_fixup function pointer, which is then dynamically optimized into a vtable lookup. This avoids the traditional objc_msgSend entirely. You’d have to catch all of those too.
    4. objc_msgSend can not be implemented in C, as it is not actually variadic function and does not have a prototype that can be represented in C. From the caller’s perspective, objc_msgSend is an opaque trampoline; it will dispatch to the method IMP, which is itself expected to implement the function ABI required by the caller.

    There are much better ways to measure performance.

    If Instruments isn’t showing your slow areas, you may be profiling only running threads instead of all threads. Using the Time Profiler instrument, click the little ‘i’ next to the track header, and then select “All Thread States”. This will make sure that time spent waiting on I/O is counted in your measurements, which by default isn’t counted.

    Profiling all thread states

    If for some reason that still isn’t working and you just want to record a hard list of all selector running times, you could add a DTrace probe using the objc DTrace provider to record the running time of every Objective-C method. This wouldn’t record statistics for C functions like Instruments will, and it won’t organize things hierarchically, but if Instruments isn’t doing it for you, this will. In Instruments, choose Instrument -> Trace Symbol. In the window that appears, type the following:

    -[* *]
    

    That is, trace all instance methods (-) called on any class (*) of any selector name (*). Then record, and you’ll get a list of the time consumed in every method. Further, this does not defeat the hand-tuned assembler in the built-in objc_msgSend, and is fully supported by Apple. It is also not limited to only your code; it will profile calls inside Apple’s frameworks as well.

    Unfortunately, DTrace probes are not currently supported on iOS devices, so you’d have to use the DTrace probe against an app running in the simulator. This is obviously not ideal. If you’ve really got a single method serving as a hot spot, though, it’s likely that it will show up in the simulator as well.

    Again, though, the Time Profile instrument is far better suited to the job, and it definitely works. Turn on All Thread States, and you’ll see your problem.

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

Sidebar

Related Questions

I want to achieve something like this in C# 3.5: public void Register<T>() :
suppose there is a script doing something like this: # module writer.py import sys
I want something like this: abcdab.search(/a/g) //return [0,4] Is it possible?
I want to do something like this within an MS Access query, but SUBSTRING
i want to do something like this: Transcript show: '\n'. how?
I want to do something like this: class Cls { function fun($php) { return
I want to do something like this: cat abcd.txt | cut -f 2,1 and
I want to do something like this create type Item as object ( id
I want to do something like this with a GridView: <asp:CommandField ShowSelectButton=True Visible='<%# return
I want to do something like this... try { # Something in this function

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.