Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

Very high CPU usage - status display

Help
Matt N
2007-06-06
2013-05-13
  • Matt N
    Matt N
    2007-06-06

    I typically use mplayerplug-in with noembed=1. The only window that initially pops up when I click a video link on a webpage is a status window that shows how many KB have been downloaded along with a progress bar. For some reason, this status window is using huge amounts of CPU (sometimes over 50% on a 2.4 GHz machine). If I add the hidestatus=1 option, the CPU usage problem is gone, but I get no status information about the progress of the file download.

    I'm guessing this status window is being updated too frequently, causing high CPU usage. Can this be fixed so that the updates are more infrequent (i.e. update at most 2 times/second)? Thanks!

     
    • Matt N
      Matt N
      2007-06-07

      So, I downloaded the 3.40 source and made some small changed to plugin.cpp that solved the high CPU usage problem. Basically, I modified the code so the UI is only updated once per second when downloading a file. This should really help out anyone who watched a file while it's downloading. Probably a large part of their CPU is being hogged by the download-status display.

      I'm sure my modification can be done in a more elegant way, but here's a diff of the changes I made so you get the basic idea. Hopefully someone involved with the project can do a better job. I don't imagine it should take more than 15 min.

      diff (original)plugin.cpp (modified)plugin.cpp
      42a43
      > #include <time.h>
      62a64
      > time_t lastOutput;
      1971a1974,1978
      >               if (difftime(time(NULL),lastOutput) < 1) {
      >                    goto skipOutput;
      >               } else {
      >                    time(&lastOutput);
      >                 }
      2063c2070
      <
      ---
      > skipOutput:

       
      • Kevin DeKorte
        Kevin DeKorte
        2007-06-07

        A modified version of this patch has been applied to CVS. Please give it a try.

        Comment: gotos are generally not good, so I made it an if statement.

         
    • Matt N
      Matt N
      2007-06-08

      Thanks a lot for incorporating the fix and cleaning it up--I compiled CVS and all seems good.

      One minor thing I should mention is that I noticed you changed it to update every 0.5 seconds. Unfortunately that won't work with the time() function since it only returns a value in seconds (it's only precise to 1 second). So, the effect is, that "< 0.5" is the same as "< 1", since the difftime function (although it returns a double), will always return either 0 or 1 or some higher integer. If you want greater precision, you'll need to use the gettimeofday() function.