Changeset 219220 in webkit
- Timestamp:
- Jul 6, 2017 2:59:33 PM (7 years ago)
- Location:
- trunk/Source/WebKit2
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit2/ChangeLog
r219219 r219220 1 2017-07-06 Brent Fulgham <bfulgham@apple.com> 2 3 [WK2] ResourceLoadStatistics should batch its writes 4 https://bugs.webkit.org/show_bug.cgi?id=174111 5 <rdar://problem/33115894> 6 7 Reviewed by Chris Dumez. 8 9 Revise the data writing operation to only write on a specific interval (currently 10 set to 5 minutes). 11 12 Also make 'writeStoreToDisk' simpler to use by moving the deleting (before write) and 13 creating (after write) of the FileMonitor into the method, rather than requiring this 14 knowledge in multiple places. 15 16 Make sure that we write our statistics file out before exiting so that we do not 17 lose any data if we exit before the five-minute window has elapsed. 18 19 * UIProcess/Storage/ResourceLoadStatisticsStore.cpp: 20 (WebKit::ResourceLoadStatisticsStore::setWritePersistentStoreCallback): Deleted. 21 * UIProcess/WebResourceLoadStatisticsStore.cpp: 22 (WebKit::WebResourceLoadStatisticsStore::processStatisticsAndDataRecords): Remove the stop 23 and start monitoring into 'writeStoreToDisk'. Also check if enough time has elapsed since 24 the last write to commit to disk. 25 (WebKit::WebResourceLoadStatisticsStore::registerSharedResourceLoadObserver): Remove the 26 stop and start monitoring into 'writeStoreToDisk'. 27 (WebKit::WebResourceLoadStatisticsStore::writeStoreToDisk): Add the stop and start monitoring 28 commands here, so callers don't have to know to do so. 29 1 30 2017-07-06 Chris Dumez <cdumez@apple.com> 2 31 -
trunk/Source/WebKit2/UIProcess/Storage/ResourceLoadStatisticsStore.cpp
r219071 r219220 177 177 } 178 178 179 void ResourceLoadStatisticsStore::setWritePersistentStoreCallback(WTF::Function<void()>&& handler)180 {181 m_writePersistentStoreHandler = WTFMove(handler);182 }183 184 179 void ResourceLoadStatisticsStore::setGrandfatherExistingWebsiteDataCallback(WTF::Function<void()>&& handler) 185 180 { -
trunk/Source/WebKit2/UIProcess/Storage/ResourceLoadStatisticsStore.h
r219071 r219220 75 75 void setNotificationCallback(WTF::Function<void()>&&); 76 76 void setShouldPartitionCookiesCallback(WTF::Function<void(const Vector<String>& domainsToRemove, const Vector<String>& domainsToAdd, bool clearFirst)>&&); 77 void setWritePersistentStoreCallback(WTF::Function<void()>&&);78 77 void setDeletePersistentStoreCallback(WTF::Function<void()>&&); 79 78 void setGrandfatherExistingWebsiteDataCallback(WTF::Function<void()>&&); … … 108 107 WTF::Function<void()> m_dataAddedHandler; 109 108 WTF::Function<void(const Vector<String>&, const Vector<String>&, bool clearFirst)> m_shouldPartitionCookiesForDomainsHandler; 110 WTF::Function<void()> m_writePersistentStoreHandler;111 109 WTF::Function<void()> m_grandfatherExistingWebsiteDataHandler; 112 110 WTF::Function<void()> m_deletePersistentStoreHandler; -
trunk/Source/WebKit2/UIProcess/WebResourceLoadStatisticsStore.cpp
r219219 r219220 41 41 #include <wtf/MainThread.h> 42 42 #include <wtf/MathExtras.h> 43 #include <wtf/MonotonicTime.h> 43 44 #include <wtf/NeverDestroyed.h> 44 45 #include <wtf/RunLoop.h> … … 59 60 return ResourceLoadStatistics::primaryDomain(value); 60 61 } 62 63 constexpr Seconds minimumStatisticsFileWriteInterval { 5_min }; 61 64 62 65 static bool notifyPagesWhenDataRecordsWereScanned = false; … … 106 109 processStatisticsAndDataRecords(); 107 110 }); 108 m_resourceLoadStatisticsStore->setWritePersistentStoreCallback([this, protectedThis = makeRef(*this)] {109 m_statisticsQueue->dispatch([this, protectedThis = protectedThis.copyRef()] {110 stopMonitoringStatisticsStorage();111 writeStoreToDisk();112 startMonitoringStatisticsStorage();113 });114 });115 111 m_resourceLoadStatisticsStore->setGrandfatherExistingWebsiteDataCallback([this, protectedThis = makeRef(*this)] { 116 112 grandfatherExistingWebsiteData(); … … 206 202 } 207 203 208 stopMonitoringStatisticsStorage(); 209 210 writeStoreToDisk(); 211 212 startMonitoringStatisticsStorage(); 204 scheduleOrWriteStoreToDisk(); 213 205 }); 214 206 } … … 320 312 { 321 313 BinarySemaphore semaphore; 322 m_statisticsQueue->dispatch([&semaphore] { 314 m_statisticsQueue->dispatch([&semaphore, this, protectedThis = makeRef(*this)] { 315 // Write final file state to disk. 316 if (m_didScheduleWrite) 317 writeStoreToDisk(); 318 323 319 // Make sure any ongoing work in our queue is finished before we terminate. 324 320 semaphore.signal(); … … 346 342 ASSERT(!RunLoop::isMain()); 347 343 344 stopMonitoringStatisticsStorage(); 345 348 346 syncWithExistingStatisticsStorageIfNeeded(); 349 347 … … 354 352 355 353 m_lastStatisticsFileSyncTime = WallTime::now(); 354 m_lastStatisticsWriteTime = MonotonicTime::now(); 355 356 startMonitoringStatisticsStorage(); 357 m_didScheduleWrite = false; 358 } 359 360 void WebResourceLoadStatisticsStore::scheduleOrWriteStoreToDisk() 361 { 362 ASSERT(!RunLoop::isMain()); 363 364 auto timeSinceLastWrite = MonotonicTime::now() - m_lastStatisticsWriteTime; 365 if (timeSinceLastWrite < minimumStatisticsFileWriteInterval) { 366 if (!m_didScheduleWrite) { 367 m_didScheduleWrite = true; 368 Seconds delayUntil = minimumStatisticsFileWriteInterval - timeSinceLastWrite + 1_s; 369 m_statisticsQueue->dispatchAfter(delayUntil, [this, protectedThis = makeRef(*this)] { 370 writeStoreToDisk(); 371 }); 372 } 373 return; 374 } 375 376 writeStoreToDisk(); 356 377 } 357 378 -
trunk/Source/WebKit2/UIProcess/WebResourceLoadStatisticsStore.h
r219219 r219220 41 41 42 42 namespace WTF { 43 class MonotonicTime; 43 44 class WallTime; 44 45 class WorkQueue; … … 46 47 47 48 namespace WebCore { 49 class FileMonitor; 48 50 class KeyedDecoder; 49 51 class KeyedEncoder; 50 class FileMonitor;51 52 struct ResourceLoadStatistics; 52 53 } … … 123 124 124 125 void writeStoreToDisk(); 126 void scheduleOrWriteStoreToDisk(); 125 127 void writeEncoderToDisk(WebCore::KeyedEncoder&, const String& path) const; 126 128 std::unique_ptr<WebCore::KeyedDecoder> createDecoderFromDisk(const String& path) const; … … 149 151 const String m_statisticsStoragePath; 150 152 WTF::WallTime m_lastStatisticsFileSyncTime; 153 WTF::MonotonicTime m_lastStatisticsWriteTime; 151 154 RunLoop::Timer<WebResourceLoadStatisticsStore> m_telemetryOneShotTimer; 152 155 RunLoop::Timer<WebResourceLoadStatisticsStore> m_telemetryRepeatedTimer; 156 bool m_didScheduleWrite { false }; 153 157 }; 154 158
Note: See TracChangeset
for help on using the changeset viewer.