diff --git a/dom/plugins/ipc/PluginModuleParent.cpp b/dom/plugins/ipc/PluginModuleParent.cpp index 646913addc1b..994602bd9cc2 100644 --- a/dom/plugins/ipc/PluginModuleParent.cpp +++ b/dom/plugins/ipc/PluginModuleParent.cpp @@ -33,7 +33,6 @@ #include "nsPrintfCString.h" #include "prsystem.h" -#include "prdtoa.h" #ifdef XP_WIN #include "mozilla/widget/AudioSession.h" @@ -111,7 +110,7 @@ PluginModuleParent::PluginModuleParent(const char* aFilePath) , mPlugin(NULL) , mTaskFactory(this) #ifdef XP_WIN - , mPluginCpuUsageOnHang() + , mPluginCpuUsageOnHang(-1) #endif #ifdef MOZ_CRASHREPORTER_INJECTOR , mFlashProcess1(0) @@ -179,18 +178,11 @@ PluginModuleParent::WriteExtraDataForMinidump(AnnotationTable& notes) if (!hangID.IsEmpty()) { notes.Put(CS("HangID"), NS_ConvertUTF16toUTF8(hangID)); #ifdef XP_WIN - if (mPluginCpuUsageOnHang.Length() > 0) { + if (mPluginCpuUsageOnHang >= 0) { + notes.Put(CS("PluginCpuUsage"), + nsPrintfCString("%.2f", mPluginCpuUsageOnHang)); notes.Put(CS("NumberOfProcessors"), nsPrintfCString("%d", PR_GetNumberOfProcessors())); - - char buf[7]; - PR_cnvtf(buf, NS_ARRAY_LENGTH(buf), 2, mPluginCpuUsageOnHang[0]); - notes.Put(CS("PluginCpuUsage"), CS(buf)); - - for (PRInt32 i=1; i& processHandles, InfallibleTArray& cpuUsage) +GetProcessCpuUsage(const base::ProcessHandle& processHandle, float& cpuUsage) { - InfallibleTArray samples(processHandles.Length()); FILETIME creationTime, exitTime, kernelTime, userTime, currentTime; BOOL res; - for (PRUint32 i = 0; i < processHandles.Length(); ++i) { - ::GetSystemTimeAsFileTime(¤tTime); - res = ::GetProcessTimes(processHandles[i], &creationTime, &exitTime, &kernelTime, &userTime); - if (!res) { - NS_WARNING("failed to get process times"); - return false; - } - - samples[i].sampleTimes[0] = FileTimeToUTC(currentTime); - samples[i].cpuTimes[0] = FileTimeToUTC(kernelTime) + FileTimeToUTC(userTime); + ::GetSystemTimeAsFileTime(¤tTime); + res = ::GetProcessTimes(processHandle, &creationTime, &exitTime, &kernelTime, &userTime); + if (!res) { + NS_WARNING("failed to get process times"); + return false; } + PRUint64 sampleTimes[2]; + PRUint64 cpuTimes[2]; + + sampleTimes[0] = FileTimeToUTC(currentTime); + cpuTimes[0] = FileTimeToUTC(kernelTime) + FileTimeToUTC(userTime); + // we already hung for a while, a little bit longer won't matter ::Sleep(50); - const PRInt32 numberOfProcessors = PR_GetNumberOfProcessors(); - - for (PRUint32 i = 0; i < processHandles.Length(); ++i) { - ::GetSystemTimeAsFileTime(¤tTime); - res = ::GetProcessTimes(processHandles[i], &creationTime, &exitTime, &kernelTime, &userTime); - if (!res) { - NS_WARNING("failed to get process times"); - return false; - } - - samples[i].sampleTimes[1] = FileTimeToUTC(currentTime); - samples[i].cpuTimes[1] = FileTimeToUTC(kernelTime) + FileTimeToUTC(userTime); - - const PRUint64 deltaSampleTime = samples[i].sampleTimes[1] - samples[i].sampleTimes[0]; - const PRUint64 deltaCpuTime = samples[i].cpuTimes[1] - samples[i].cpuTimes[0]; - const float usage = 100.f * (float(deltaCpuTime) / deltaSampleTime) / numberOfProcessors; - cpuUsage.AppendElement(usage); + ::GetSystemTimeAsFileTime(¤tTime); + res = ::GetProcessTimes(processHandle, &creationTime, &exitTime, &kernelTime, &userTime); + if (!res) { + NS_WARNING("failed to get process times"); + return false; } + sampleTimes[1] = FileTimeToUTC(currentTime); + cpuTimes[1] = FileTimeToUTC(kernelTime) + FileTimeToUTC(userTime); + + const PRUint64 deltaSampleTime = sampleTimes[1] - sampleTimes[0]; + const PRUint64 deltaCpuTime = cpuTimes[1] - cpuTimes[0]; + cpuUsage = 100.f * (float(deltaCpuTime) / deltaSampleTime) / PR_GetNumberOfProcessors(); + return true; } @@ -307,22 +288,9 @@ PluginModuleParent::ShouldContinueFromReplyTimeout() #endif #ifdef XP_WIN - // collect cpu usage for plugin processes - - InfallibleTArray processHandles; - InfallibleTArray cpuUsage; - base::ProcessHandle handle; - - processHandles.AppendElement(OtherProcess()); - if (mFlashProcess1 && base::OpenProcessHandle(mFlashProcess1, &handle)) { - processHandles.AppendElement(handle); - } - if (mFlashProcess2 && base::OpenProcessHandle(mFlashProcess2, &handle)) { - processHandles.AppendElement(handle); - } - - if (!GetProcessCpuUsage(processHandles, cpuUsage)) { - mPluginCpuUsageOnHang.Clear(); + float cpuUsage; + if (GetProcessCpuUsage(OtherProcess(), cpuUsage)) { + mPluginCpuUsageOnHang = cpuUsage; } #endif diff --git a/dom/plugins/ipc/PluginModuleParent.h b/dom/plugins/ipc/PluginModuleParent.h index e6e89b6fe745..6e97665b784b 100644 --- a/dom/plugins/ipc/PluginModuleParent.h +++ b/dom/plugins/ipc/PluginModuleParent.h @@ -302,7 +302,7 @@ private: nsString mBrowserDumpID; nsString mHangID; #ifdef XP_WIN - InfallibleTArray mPluginCpuUsageOnHang; + float mPluginCpuUsageOnHang; #endif #ifdef MOZ_X11 diff --git a/dom/plugins/test/mochitest/hang_test.js b/dom/plugins/test/mochitest/hang_test.js index 47871b5bc72a..c260023963aa 100644 --- a/dom/plugins/test/mochitest/hang_test.js +++ b/dom/plugins/test/mochitest/hang_test.js @@ -79,7 +79,7 @@ var testObserver = { // check cpu usage field let extraData = parseKeyValuePairsFromFile(pluginExtraFile); ok("PluginCpuUsage" in extraData, "got extra field for plugin cpu usage"); - let cpuUsage = parseFloat(extraData["PluginCpuUsage"]); + let cpuUsage = parseFloat(extraData["PluginCpuUsage"].replace(',', '.')); if (this.idleHang) { ok(cpuUsage == 0, "plugin cpu usage is 0%"); } else {