mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-25 17:43:44 +00:00
Bug 962044 - Forward event loop lag messages via an observer. r=ted
This commit is contained in:
parent
2d9332319c
commit
cd0cf4ebe2
@ -64,6 +64,12 @@
|
||||
#include <prthread.h>
|
||||
#include <prtime.h>
|
||||
|
||||
#ifdef MOZ_WIDGET_GONK
|
||||
#include "nsThreadUtils.h"
|
||||
#include "nsIObserverService.h"
|
||||
#include "mozilla/Services.h"
|
||||
#endif
|
||||
|
||||
using mozilla::TimeDuration;
|
||||
using mozilla::TimeStamp;
|
||||
using mozilla::FireAndWaitForTracerEvent;
|
||||
@ -77,6 +83,31 @@ struct TracerStartClosure {
|
||||
bool mLogTracing;
|
||||
};
|
||||
|
||||
#ifdef MOZ_WIDGET_GONK
|
||||
class EventLoopLagDispatcher : public nsRunnable
|
||||
{
|
||||
public:
|
||||
explicit EventLoopLagDispatcher(int aLag)
|
||||
: mLag(aLag) {}
|
||||
|
||||
NS_IMETHODIMP Run()
|
||||
{
|
||||
nsCOMPtr<nsIObserverService> obsService =
|
||||
mozilla::services::GetObserverService();
|
||||
if (!obsService) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsAutoString value;
|
||||
value.AppendInt(mLag);
|
||||
return obsService->NotifyObservers(nullptr, "event-loop-lag", value.get());
|
||||
}
|
||||
|
||||
private:
|
||||
int mLag;
|
||||
};
|
||||
#endif
|
||||
|
||||
/*
|
||||
* The tracer thread fires events at the native event loop roughly
|
||||
* every kMeasureInterval. It will sleep to attempt not to send them
|
||||
@ -146,6 +177,10 @@ void TracerThread(void *arg)
|
||||
fprintf(log, "MOZ_EVENT_TRACE sample %llu %lf\n",
|
||||
now,
|
||||
duration.ToMilliseconds());
|
||||
#ifdef MOZ_WIDGET_GONK
|
||||
NS_DispatchToMainThread(
|
||||
new EventLoopLagDispatcher(int(duration.ToSecondsSigDigits() * 1000)));
|
||||
#endif
|
||||
}
|
||||
|
||||
if (next_sleep > duration.ToMilliseconds()) {
|
||||
|
Loading…
Reference in New Issue
Block a user