A simple method to test the gprof performance of multi-threaded opening

Source: Internet
Author: User

When you use the gprof, you only know that the original gprof can only be counted on the main thread. There are no thread-related issues on the manual.

But there are ready-made solutions: http://sam.zoy.org/writings/programming/gprof.html

The scheme encapsulates the pthread_create (), allowing the thread to initialize the execution of a setitimer (Itimer_prof, ...).

An easy way to do this is to write a setitimer () directly in your code.

#include <sys/time.h>
#include <boost/thread.hpp>

struct itimerval g_itimer;

void foo ()
{
    Setitimer (itimer_prof, &g_itimer, NULL);
    for (int i = 0; i < 10000000 i++)
        (void) i;
}

int main ()
{
    Getitimer (itimer_prof, &g_itimer);
    Boost::thread T (&foo);
    T.join ();
    return 0;
}

g++ Main.cpp-pg-lboost_thread

./a.out

Gprof

This will help you to count the time consuming foo (). There will be no time-consuming statistics for foo () without Setitimer ().






Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.