Slashdot Mirror


Is Profiling Useless in Today's World?

rngadam writes "gprof doesn't work in Linux multithreaded programs without a workaround that doesn't work that well. It seems that if you want to use profiling, you have to look for alternatives or agree with RedHat's Ulrich Drepper that "gprof is useless in today's world"... Is profiling useless? How do you profile your programs? Is the lack of good profiling tools under Linux leading us in a world of bloated applications and killing Linux adoption by the embedded developers? Or will the adoption of a LinuxThreads replacement solve our problems?"

8 of 221 comments (clear)

  1. VTune by Anonymous Coward · · Score: 1, Interesting

    Use VTune (http://www.intel.com/software/products/vtune/vtun e60/), Intel's profiler.

    It does a pretty good job, and it uses performance counters.

  2. working code, not pipe dreams by Splork · · Score: 3, Interesting

    i'll always choose a program that exists and works with a good user interface over one that is never released because the author(s) thought it could be faster.

    listen to your profiler. everything else lies.

  3. Re:HW Profiling is the best way to go... by Anonymous Coward · · Score: 1, Interesting

    The Intel tool probably is very decent if it's using performance counters. That's one part of a microprocessor design that turns out to be very useful for programmers, but many people don't even know they exist because they're buried in some special purpose register access somewhere. High end POWER boxes have had such things for years.

  4. Re:There is no question that profiling is necessar by pthisis · · Score: 3, Interesting

    However, "fast enough" is a really bad metric to use. Yes, utility "X" is fast enough. But oh, I didn't realize it was going to be used in conjunction with utility "Y" and "Z". Now, everything is really slow. Hey, can you say Microsoft?

    Hey, I need this report on my desk every morning. It takes 3 hours to run. Let's kick it off every night at midnight.

    Fast enough, even though a well-coded, well-designed implementation might take seconds to run. And mission critical. No point wasting programmer time speeding it up when we can do another project with big upside instead.

    This sort of thing is not uncommon at all.

    Sumner

    --
    rage, rage against the dying of the light
  5. Re:So threads are evil -- now what? by pthisis · · Score: 3, Interesting

    That said, thanks for the information, it has certainly helped to clear some things up.
    No problem.

    I guess the key point I want people to remember (if I only clear one thing up...) is that a decision about whether to use threads or processes should be based on whether they want all (or mostly) shared memory, in which case threads are in order, or some protected memory (and possibly some shared) in which case processes are the way to go.

    Windows has hoodwinked people into thinking threads are fast and processes are slow (and that processes have to start new executables), when that's really not the interesting detail and isn't really very true under well-designed operating systems. And you lose a lot by giving up protected memory (even only giving it up wrt other threads in your memory space).

    Sumner

    --
    rage, rage against the dying of the light
  6. what's the problem? by g4dget · · Score: 4, Interesting
    You say that there is a problem with profiling multithreaded code with gprof. But the issue you point to seems to apply to both single and multithreaded code: Linux gprof doesn't seem to count time spent in system code.

    Now, compute intensive code tends not to spend a lot of time in system calls, so it isn't clear that it matters whether a profiler counts time spent in system calls. I kind of prefer if it doesn't because it doesn't clutter up the profile with I/O delays (which are usually unavoidable).

    If you want to find out where your code is spending time in system calls, you can use "strace -c".

    There are also gcov-like tools that can be used for profiling via code insertion (as opposed to statistical profiling like gprof), although I'm not sure whether PC hardware has the necessary timer support.

    Overall, the answer is: yes, profiling still matters for programs that push the limits of the machine. But fewer programs do. I think most people would be a lot better off not programming in C or C++ at all and not worrying about performance. Too much worry about "efficiency" often results in code that is not only buggy but also quite inefficient: tricks that are fine for optimizing a few inner loops wreak havoc with performance when applied throughout a program. Too much tuning of low-level stuff also causes people to miss opportunities for better data structure and program logic. This is actually an endemic problem in the industry that affects almost all big C/C++ software systems. Desktop software, major servers, and even major parts of the kernel should simply not be written in C/C++ anymore.

    The thing with profiling and optimization is to know when to stop, and few people know that. So, maybe the best thing to say is: "no, profiling doesn't matter anymore". That will keep most people out of trouble, and the few that still need to profile will figure it out themselves.

  7. Re:There is no question that profiling is necessar by pthisis · · Score: 3, Interesting

    If you don't take a cursory run with a profiler on it, you'll never know the real cost of speeding it up.

    Right. It's obviously a cost/benefit tradeoff. If you start the report at midnight and need it at 8:00 in the morning, then if it takes 15 minutes to run you probably don't even want to think about profiling. If it takes 7 hours, it's still fast enough for now but you may want to concern yourself with whether it'll always be fast enough. What's the cutoff? 1 hour? 4 hours? Depends on how crucial the report is and what other projects are on your plate at the moment.

    Obviously "performance problem" is tough to quantify in general, but I still contend that you should normally only profile if there is a potential performance problem (or if you have idle resources, etc). Otherwise, go do some QA. Work on a new project. Clean up the nasty hack you wrote late at night to get it going. Write some documentation. Whatever.

    Sumner

    --
    rage, rage against the dying of the light
  8. Re:Not useless by pthisis · · Score: 3, Interesting

    I'd think you appreciate the quote on threads attributed to Alan Cox on Larry McVoy's page.

    (The quote in question is:
    "A computer is a state machine. Threads are for people who can't program state machines." Alan Cox)

    Except I'd assert that threads are far harder to program correctly than state machines. Easier concept at first, and easy to come up with a design for the 90% solution, but the devil's in the details and threads have a ton of details. Not to say that state machines don't, but they seem to cause less problems in practice.

    Sumner

    --
    rage, rage against the dying of the light