PerformanceLogging.cpp [plain text]
#include "config.h"
#include "PerformanceLogging.h"
#include "CommonVM.h"
#include "DOMWindow.h"
#include "Document.h"
#include "FrameLoaderClient.h"
#include "JSDOMWindow.h"
#include "Logging.h"
#include "MainFrame.h"
#include "PageCache.h"
namespace WebCore {
#if !RELEASE_LOG_DISABLED
static const char* toString(PerformanceLogging::PointOfInterest poi)
{
switch (poi) {
case PerformanceLogging::MainFrameLoadStarted:
return "MainFrameLoadStarted";
case PerformanceLogging::MainFrameLoadCompleted:
return "MainFrameLoadCompleted";
}
}
#endif
HashMap<const char*, size_t> PerformanceLogging::memoryUsageStatistics(ShouldIncludeExpensiveComputations includeExpensive)
{
HashMap<const char*, size_t> stats;
auto& vm = commonVM();
stats.add("javascript_gc_heap_capacity", vm.heap.capacity());
stats.add("javascript_gc_heap_extra_memory_size", vm.heap.extraMemorySize());
auto& pageCache = PageCache::singleton();
stats.add("pagecache_page_count", pageCache.pageCount());
stats.add("document_count", Document::allDocuments().size());
if (includeExpensive == ShouldIncludeExpensiveComputations::Yes) {
stats.add("javascript_gc_heap_size", vm.heap.size());
stats.add("javascript_gc_object_count", vm.heap.objectCount());
stats.add("javascript_gc_protected_object_count", vm.heap.protectedObjectCount());
stats.add("javascript_gc_global_object_count", vm.heap.globalObjectCount());
stats.add("javascript_gc_protected_global_object_count", vm.heap.protectedGlobalObjectCount());
}
return stats;
}
HashCountedSet<const char*> PerformanceLogging::javaScriptObjectCounts()
{
return WTFMove(*commonVM().heap.objectTypeCounts());
}
PerformanceLogging::PerformanceLogging(MainFrame& mainFrame)
: m_mainFrame(mainFrame)
{
}
void PerformanceLogging::didReachPointOfInterest(PointOfInterest poi)
{
#if RELEASE_LOG_DISABLED
UNUSED_PARAM(poi);
#else
if (m_mainFrame.loader().client().isEmptyFrameLoaderClient())
return;
auto stats = memoryUsageStatistics(ShouldIncludeExpensiveComputations::No);
getPlatformMemoryUsageStatistics(stats);
RELEASE_LOG(PerformanceLogging, "Memory usage info dump at %s:", toString(poi));
for (auto& it : stats)
RELEASE_LOG(PerformanceLogging, " %s: %zu", it.key, it.value);
#endif
}
#if !PLATFORM(COCOA)
void PerformanceLogging::getPlatformMemoryUsageStatistics(HashMap<const char*, size_t>&) { }
std::optional<uint64_t> PerformanceLogging::physicalFootprint() { return std::nullopt; }
#endif
}