Very high CPU usage - status display

Matt N
  • Matt N
    Matt N

    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

      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
      > #include <time.h>
      > time_t lastOutput;
      >               if (difftime(time(NULL),lastOutput) < 1) {
      >                    goto skipOutput;
      >               } else {
      >                    time(&lastOutput);
      >                 }
      > skipOutput:

      • Kevin DeKorte
        Kevin DeKorte

        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

      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.