Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(95)

Side by Side Diff: Source/core/timing/MemoryInfo.cpp

Issue 893803003: Ensure that performance.memory is updated on first access. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 24 matching lines...) Expand all
35 #include "core/frame/Settings.h" 35 #include "core/frame/Settings.h"
36 #include "platform/RuntimeEnabledFeatures.h" 36 #include "platform/RuntimeEnabledFeatures.h"
37 #include "wtf/CurrentTime.h" 37 #include "wtf/CurrentTime.h"
38 #include "wtf/MainThread.h" 38 #include "wtf/MainThread.h"
39 #include "wtf/MathExtras.h" 39 #include "wtf/MathExtras.h"
40 #include "wtf/ThreadSpecific.h" 40 #include "wtf/ThreadSpecific.h"
41 #include <limits> 41 #include <limits>
42 42
43 namespace blink { 43 namespace blink {
44 44
45 static const double TwentyMinutesInSeconds = 20 * 60;
46
45 class HeapSizeCache { 47 class HeapSizeCache {
46 WTF_MAKE_NONCOPYABLE(HeapSizeCache); WTF_MAKE_FAST_ALLOCATED; 48 WTF_MAKE_NONCOPYABLE(HeapSizeCache); WTF_MAKE_FAST_ALLOCATED;
47 public: 49 public:
48 HeapSizeCache() 50 HeapSizeCache()
49 : m_lastUpdateTime(0) 51 : m_lastUpdateTime(monotonicallyIncreasingTime() - TwentyMinutesInSecond s)
50 { 52 {
51 } 53 }
52 54
53 void getCachedHeapSize(HeapInfo& info) 55 void getCachedHeapSize(HeapInfo& info)
54 { 56 {
55 maybeUpdate(); 57 maybeUpdate();
56 info = m_info; 58 info = m_info;
57 } 59 }
58 60
59 static HeapSizeCache& forCurrentThread() 61 static HeapSizeCache& forCurrentThread()
60 { 62 {
61 AtomicallyInitializedStaticReference(ThreadSpecific<HeapSizeCache>, heap SizeCache, new ThreadSpecific<HeapSizeCache>); 63 AtomicallyInitializedStaticReference(ThreadSpecific<HeapSizeCache>, heap SizeCache, new ThreadSpecific<HeapSizeCache>);
62 return *heapSizeCache; 64 return *heapSizeCache;
63 } 65 }
64 66
65 private: 67 private:
66 void maybeUpdate() 68 void maybeUpdate()
67 { 69 {
68 // We rate-limit queries to once every twenty minutes to make it more di fficult 70 // We rate-limit queries to once every twenty minutes to make it more di fficult
69 // for attackers to compare memory usage before and after some event. 71 // for attackers to compare memory usage before and after some event.
70 const double TwentyMinutesInSeconds = 20 * 60;
71
72 double now = monotonicallyIncreasingTime(); 72 double now = monotonicallyIncreasingTime();
73 if (now - m_lastUpdateTime >= TwentyMinutesInSeconds) { 73 if (now - m_lastUpdateTime >= TwentyMinutesInSeconds) {
74 update(); 74 update();
75 m_lastUpdateTime = now; 75 m_lastUpdateTime = now;
76 } 76 }
77 } 77 }
78 78
79 void update() 79 void update()
80 { 80 {
81 ScriptGCEvent::getHeapSize(m_info); 81 ScriptGCEvent::getHeapSize(m_info);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 139
140 MemoryInfo::MemoryInfo() 140 MemoryInfo::MemoryInfo()
141 { 141 {
142 if (RuntimeEnabledFeatures::preciseMemoryInfoEnabled()) 142 if (RuntimeEnabledFeatures::preciseMemoryInfoEnabled())
143 ScriptGCEvent::getHeapSize(m_info); 143 ScriptGCEvent::getHeapSize(m_info);
144 else 144 else
145 HeapSizeCache::forCurrentThread().getCachedHeapSize(m_info); 145 HeapSizeCache::forCurrentThread().getCachedHeapSize(m_info);
146 } 146 }
147 147
148 } // namespace blink 148 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698