Bug 853358 - Add plugin profiling support. r=ehsan,bsmedberg

This commit is contained in:
Benoit Girard
2013-03-21 10:17:23 +01:00
parent 14516ad542
commit fb221d781b
14 changed files with 260 additions and 84 deletions

View File

@@ -38,7 +38,9 @@
#include "PluginHangUIParent.h"
#include "mozilla/widget/AudioSession.h"
#endif
#include "GeckoProfiler.h"
#include "nsIProfileSaveEvent.h"
#include "mozilla/Services.h"
#include "nsIObserverService.h"
using base::KillProcess;
@@ -138,12 +140,16 @@ PluginModuleParent::PluginModuleParent(const char* aFilePath)
Preferences::RegisterCallback(TimeoutChanged, kHangUITimeoutPref, this);
Preferences::RegisterCallback(TimeoutChanged, kHangUIMinDisplayPref, this);
#endif
InitPluginProfiling();
}
PluginModuleParent::~PluginModuleParent()
{
NS_ASSERTION(OkToCleanup(), "unsafe destruction");
ShutdownPluginProfiling();
if (!mShutdown) {
NS_WARNING("Plugin host deleted the module without shutting down.");
NPError err;
@@ -1710,3 +1716,56 @@ PluginModuleParent::OnCrash(DWORD processID)
}
#endif // MOZ_CRASHREPORTER_INJECTOR
class PluginProfilerObserver MOZ_FINAL : public nsIObserver,
public nsSupportsWeakReference
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER
explicit PluginProfilerObserver(PluginModuleParent* pmp)
: mPmp(pmp)
{}
private:
PluginModuleParent* mPmp;
};
NS_IMPL_ISUPPORTS2(PluginProfilerObserver, nsIObserver, nsISupportsWeakReference)
NS_IMETHODIMP
PluginProfilerObserver::Observe(nsISupports *aSubject,
const char *aTopic,
const PRUnichar *aData)
{
nsCOMPtr<nsIProfileSaveEvent> pse = do_QueryInterface(aSubject);
if (pse) {
nsCString result;
bool success = mPmp->CallGeckoGetProfile(&result);
if (success && !result.IsEmpty()) {
pse->AddSubProfile(result.get());
}
}
return NS_OK;
}
void
PluginModuleParent::InitPluginProfiling()
{
nsCOMPtr<nsIObserverService> observerService = mozilla::services::GetObserverService();
if (observerService) {
mProfilerObserver = new PluginProfilerObserver(this);
observerService->AddObserver(mProfilerObserver, "profiler-subprocess", false);
}
}
void
PluginModuleParent::ShutdownPluginProfiling()
{
nsCOMPtr<nsIObserverService> observerService = mozilla::services::GetObserverService();
if (observerService) {
observerService->RemoveObserver(mProfilerObserver, "profiler-subprocess");
}
}