| OLD | NEW |
| 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 11 matching lines...) Expand all Loading... |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "core/page/MemoryInfo.h" | 32 #include "core/timing/MemoryInfo.h" |
| 33 | 33 |
| 34 #include <limits> | 34 #include <limits> |
| 35 #include "bindings/v8/ScriptGCEvent.h" | 35 #include "bindings/v8/ScriptGCEvent.h" |
| 36 #include "core/page/Frame.h" | 36 #include "core/page/Frame.h" |
| 37 #include "core/page/Settings.h" | 37 #include "core/page/Settings.h" |
| 38 #include "wtf/CurrentTime.h" | 38 #include "wtf/CurrentTime.h" |
| 39 #include "wtf/MainThread.h" | 39 #include "wtf/MainThread.h" |
| 40 #include "wtf/MathExtras.h" | 40 #include "wtf/MathExtras.h" |
| 41 | 41 |
| 42 namespace WebCore { | 42 namespace WebCore { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 | 103 |
| 104 size_t nextPowerOfTen = static_cast<size_t>(pow(10, floor(log10(sizeOfNe
xtBucket)) + 1) + 0.5); | 104 size_t nextPowerOfTen = static_cast<size_t>(pow(10, floor(log10(sizeOfNe
xtBucket)) + 1) + 0.5); |
| 105 size_t granularity = nextPowerOfTen / 1000; // We want 3 signficant digi
ts. | 105 size_t granularity = nextPowerOfTen / 1000; // We want 3 signficant digi
ts. |
| 106 | 106 |
| 107 for (int i = 0; i < numberOfBuckets; ++i) { | 107 for (int i = 0; i < numberOfBuckets; ++i) { |
| 108 size_t currentBucketSize = static_cast<size_t>(sizeOfNextBucket); | 108 size_t currentBucketSize = static_cast<size_t>(sizeOfNextBucket); |
| 109 bucketSizeList[i] = currentBucketSize - (currentBucketSize % granula
rity); | 109 bucketSizeList[i] = currentBucketSize - (currentBucketSize % granula
rity); |
| 110 | 110 |
| 111 sizeOfNextBucket *= scalingFactor; | 111 sizeOfNextBucket *= scalingFactor; |
| 112 if (sizeOfNextBucket >= nextPowerOfTen) { | 112 if (sizeOfNextBucket >= nextPowerOfTen) { |
| 113 if (std::numeric_limits<size_t>::max() / 10 <= nextPowerOfTen) | 113 if (std::numeric_limits<size_t>::max() / 10 <= nextPowerOfTen) { |
| 114 nextPowerOfTen = std::numeric_limits<size_t>::max(); | 114 nextPowerOfTen = std::numeric_limits<size_t>::max(); |
| 115 else { | 115 } else { |
| 116 nextPowerOfTen *= 10; | 116 nextPowerOfTen *= 10; |
| 117 granularity *= 10; | 117 granularity *= 10; |
| 118 } | 118 } |
| 119 } | 119 } |
| 120 | 120 |
| 121 // Watch out for overflow, if the range is too large for size_t. | 121 // Watch out for overflow, if the range is too large for size_t. |
| 122 if (i > 0 && bucketSizeList[i] < bucketSizeList[i - 1]) | 122 if (i > 0 && bucketSizeList[i] < bucketSizeList[i - 1]) |
| 123 bucketSizeList[i] = std::numeric_limits<size_t>::max(); | 123 bucketSizeList[i] = std::numeric_limits<size_t>::max(); |
| 124 } | 124 } |
| 125 } | 125 } |
| 126 | 126 |
| 127 for (int i = 0; i < numberOfBuckets; ++i) { | 127 for (int i = 0; i < numberOfBuckets; ++i) { |
| 128 if (size <= bucketSizeList[i]) | 128 if (size <= bucketSizeList[i]) |
| 129 return bucketSizeList[i]; | 129 return bucketSizeList[i]; |
| 130 } | 130 } |
| 131 | 131 |
| 132 return bucketSizeList[numberOfBuckets - 1]; | 132 return bucketSizeList[numberOfBuckets - 1]; |
| 133 } | 133 } |
| 134 | 134 |
| 135 | 135 |
| 136 MemoryInfo::MemoryInfo(Frame* frame) | 136 MemoryInfo::MemoryInfo(Frame* frame) |
| 137 { | 137 { |
| 138 ScriptWrappable::init(this); | 138 ScriptWrappable::init(this); |
| 139 if (!frame || !frame->settings()) | 139 if (!frame || !frame->settings()) |
| 140 return; | 140 return; |
| 141 | 141 |
| 142 if (frame->settings()->memoryInfoEnabled()) | 142 if (frame->settings()->memoryInfoEnabled()) { |
| 143 ScriptGCEvent::getHeapSize(m_info); | 143 ScriptGCEvent::getHeapSize(m_info); |
| 144 else { | 144 } else { |
| 145 DEFINE_STATIC_LOCAL(HeapSizeCache, heapSizeCache, ()); | 145 DEFINE_STATIC_LOCAL(HeapSizeCache, heapSizeCache, ()); |
| 146 heapSizeCache.getCachedHeapSize(m_info); | 146 heapSizeCache.getCachedHeapSize(m_info); |
| 147 } | 147 } |
| 148 } | 148 } |
| 149 | 149 |
| 150 } // namespace WebCore | 150 } // namespace WebCore |
| OLD | NEW |