Skip to content

Instantly share code, notes, and snippets.

@gregtatum
Created February 8, 2019 21:38
Show Gist options
  • Save gregtatum/7b997816f7efcc7aefaf201d80d8f25a to your computer and use it in GitHub Desktop.
Save gregtatum/7b997816f7efcc7aefaf201d80d8f25a to your computer and use it in GitHub Desktop.
diff --git a/dom/performance/Performance.cpp b/dom/performance/Performance.cpp
--- a/dom/performance/Performance.cpp
+++ b/dom/performance/Performance.cpp
@@ -215,20 +215,68 @@ void Performance::Mark(const nsAString&
}
RefPtr<PerformanceMark> performanceMark =
new PerformanceMark(GetParentObject(), aName, Now());
InsertUserEntry(performanceMark);
#ifdef MOZ_GECKO_PROFILER
if (profiler_is_active()) {
+
nsCOMPtr<EventTarget> et = do_QueryInterface(GetOwner());
nsCOMPtr<nsIDocShell> docShell =
nsContentUtils::GetDocShellForEventTarget(et);
DECLARE_DOCSHELL_AND_HISTORY_ID(docShell);
+
+ {
+ auto timerA = TimeStamp::Now();
+ size_t iterations = 1000;
+
+ for(size_t i = 0; i < iterations; i++) {
+ profiler_add_marker(
+ "UserTiming",
+ js::ProfilingStackFrame::Category::DOM,
+ MakeUnique<UserTimingMarkerPayload>(
+ aName,
+ TimeStamp::Now(),
+ docShellId,
+ docShellHistoryId,
+ profiler_get_backtrace()
+ )
+ );
+ }
+
+ auto timerB = TimeStamp::Now();
+
+ for(size_t i = 0; i < iterations; i++) {
+ profiler_add_marker(
+ "UserTiming",
+ js::ProfilingStackFrame::Category::DOM,
+ MakeUnique<UserTimingMarkerPayload>(
+ aName,
+ TimeStamp::Now(),
+ docShellId,
+ docShellHistoryId
+ )
+ );
+ }
+
+ auto timerC = TimeStamp::Now();
+
+ auto timingWith = (timerB - timerA).ToMicroseconds();
+ auto timingWithout = (timerC - timerB).ToMicroseconds();
+ auto timePer = (timingWith - timingWithout) / iterations;
+ auto percentage = 100.0 * timingWith / timingWithout;
+
+ printf("!!! Generate %zu markers with stack %ldμs\n", iterations, (long) timingWith);
+ printf("!!! Generate %zu markers without stack %ldμs\n", iterations, (long) timingWithout);
+ printf("!!! Time per stack %fμs\n", timePer);
+ printf("!!! Percentage difference %ld%%\n\n", (long) percentage);
+ }
+
profiler_add_marker(
"UserTiming", js::ProfilingStackFrame::Category::DOM,
MakeUnique<UserTimingMarkerPayload>(aName, TimeStamp::Now(), docShellId,
docShellHistoryId));
}
#endif
}
diff --git a/tools/profiler/public/ProfilerMarkerPayload.h b/tools/profiler/public/ProfilerMarkerPayload.h
--- a/tools/profiler/public/ProfilerMarkerPayload.h
+++ b/tools/profiler/public/ProfilerMarkerPayload.h
@@ -157,19 +157,20 @@ class DOMEventMarkerPayload : public Tra
nsString mEventType;
};
class UserTimingMarkerPayload : public ProfilerMarkerPayload {
public:
UserTimingMarkerPayload(const nsAString& aName,
const mozilla::TimeStamp& aStartTime,
const mozilla::Maybe<nsID>& aDocShellId,
- const mozilla::Maybe<uint32_t>& aDocShellHistoryId)
+ const mozilla::Maybe<uint32_t>& aDocShellHistoryId,
+ UniqueProfilerBacktrace aStack = nullptr)
: ProfilerMarkerPayload(aStartTime, aStartTime, aDocShellId,
- aDocShellHistoryId),
+ aDocShellHistoryId, std::move(aStack)),
mEntryType("mark"),
mName(aName) {}
UserTimingMarkerPayload(const nsAString& aName,
const mozilla::Maybe<nsString>& aStartMark,
const mozilla::Maybe<nsString>& aEndMark,
const mozilla::TimeStamp& aStartTime,
const mozilla::TimeStamp& aEndTime,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment