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

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

Issue 2393013002: reflow comments in core/{clipboard,streams,testing,timing} (Closed)
Patch Set: comments (heh!) Created 4 years, 2 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
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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 67
68 static HeapSizeCache& forCurrentThread() { 68 static HeapSizeCache& forCurrentThread() {
69 DEFINE_THREAD_SAFE_STATIC_LOCAL(ThreadSpecific<HeapSizeCache>, 69 DEFINE_THREAD_SAFE_STATIC_LOCAL(ThreadSpecific<HeapSizeCache>,
70 heapSizeCache, 70 heapSizeCache,
71 new ThreadSpecific<HeapSizeCache>); 71 new ThreadSpecific<HeapSizeCache>);
72 return *heapSizeCache; 72 return *heapSizeCache;
73 } 73 }
74 74
75 private: 75 private:
76 void maybeUpdate() { 76 void maybeUpdate() {
77 // We rate-limit queries to once every twenty minutes to make it more diffic ult 77 // We rate-limit queries to once every twenty minutes to make it more
78 // for attackers to compare memory usage before and after some event. 78 // difficult for attackers to compare memory usage before and after some
79 // event.
79 double now = monotonicallyIncreasingTime(); 80 double now = monotonicallyIncreasingTime();
80 if (now - m_lastUpdateTime >= TwentyMinutesInSeconds) { 81 if (now - m_lastUpdateTime >= TwentyMinutesInSeconds) {
81 update(); 82 update();
82 m_lastUpdateTime = now; 83 m_lastUpdateTime = now;
83 } 84 }
84 } 85 }
85 86
86 void update() { 87 void update() {
87 getHeapSize(m_info); 88 getHeapSize(m_info);
88 m_info.usedJSHeapSize = quantizeMemorySize(m_info.usedJSHeapSize); 89 m_info.usedJSHeapSize = quantizeMemorySize(m_info.usedJSHeapSize);
89 m_info.totalJSHeapSize = quantizeMemorySize(m_info.totalJSHeapSize); 90 m_info.totalJSHeapSize = quantizeMemorySize(m_info.totalJSHeapSize);
90 m_info.jsHeapSizeLimit = quantizeMemorySize(m_info.jsHeapSizeLimit); 91 m_info.jsHeapSizeLimit = quantizeMemorySize(m_info.jsHeapSizeLimit);
91 } 92 }
92 93
93 double m_lastUpdateTime; 94 double m_lastUpdateTime;
94 95
95 HeapInfo m_info; 96 HeapInfo m_info;
96 }; 97 };
97 98
98 // We quantize the sizes to make it more difficult for an attacker to see precis e 99 // We quantize the sizes to make it more difficult for an attacker to see
99 // impact of operations on memory. The values are used for performance tuning, 100 // precise impact of operations on memory. The values are used for performance
100 // and hence don't need to be as refined when the value is large, so we threshol d 101 // tuning, and hence don't need to be as refined when the value is large, so we
101 // at a list of exponentially separated buckets. 102 // threshold at a list of exponentially separated buckets.
102 size_t quantizeMemorySize(size_t size) { 103 size_t quantizeMemorySize(size_t size) {
103 const int numberOfBuckets = 100; 104 const int numberOfBuckets = 100;
104 DEFINE_STATIC_LOCAL(Vector<size_t>, bucketSizeList, ()); 105 DEFINE_STATIC_LOCAL(Vector<size_t>, bucketSizeList, ());
105 106
106 if (bucketSizeList.isEmpty()) { 107 if (bucketSizeList.isEmpty()) {
107 bucketSizeList.resize(numberOfBuckets); 108 bucketSizeList.resize(numberOfBuckets);
108 109
109 float sizeOfNextBucket = 10000000.0; // First bucket size is roughly 10M. 110 float sizeOfNextBucket = 10000000.0; // First bucket size is roughly 10M.
110 const float largestBucketSize = 4000000000.0; // Roughly 4GB. 111 const float largestBucketSize = 4000000000.0; // Roughly 4GB.
111 // We scale with the Nth root of the ratio, so that we use all the bucktes. 112 // We scale with the Nth root of the ratio, so that we use all the bucktes.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 } 146 }
146 147
147 MemoryInfo::MemoryInfo() { 148 MemoryInfo::MemoryInfo() {
148 if (RuntimeEnabledFeatures::preciseMemoryInfoEnabled()) 149 if (RuntimeEnabledFeatures::preciseMemoryInfoEnabled())
149 getHeapSize(m_info); 150 getHeapSize(m_info);
150 else 151 else
151 HeapSizeCache::forCurrentThread().getCachedHeapSize(m_info); 152 HeapSizeCache::forCurrentThread().getCachedHeapSize(m_info);
152 } 153 }
153 154
154 } // namespace blink 155 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698