Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are |
| 6 | * met: |
| 7 | * |
| 8 | * * Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * * Redistributions in binary form must reproduce the above |
| 11 | * copyright notice, this list of conditions and the following disclaimer |
| 12 | * in the documentation and/or other materials provided with the |
| 13 | * distribution. |
| 14 | * * Neither the name of Google Inc. nor the names of its |
| 15 | * contributors may be used to endorse or promote products derived from |
| 16 | * this software without specific prior written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 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. |
| 29 | */ |
| 30 | |
| 31 | #include "config.h" |
| 32 | #include "core/css/resolver/StyleResolverStats.h" |
| 33 | |
| 34 | #include "wtf/text/CString.h" |
| 35 | #include "wtf/text/StringBuilder.h" |
| 36 | |
| 37 | #define PERCENT(x, y) ((!y) ? 0 : (((x) * 100.0) / (y))) |
| 38 | |
| 39 | namespace WebCore { |
| 40 | |
| 41 | void StyleResolverStats::reset() |
| 42 | { |
| 43 | sharedStyleLookups = 0; |
| 44 | sharedStyleCandidates = 0; |
| 45 | sharedStyleFound = 0; |
| 46 | sharedStyleMissed = 0; |
| 47 | sharedStyleRejectedByUncommonAttributeRules = 0; |
| 48 | sharedStyleRejectedBySiblingRules = 0; |
| 49 | sharedStyleRejectedByParent = 0; |
| 50 | matchedPropertyApply = 0; |
| 51 | matchedPropertyCacheHit = 0; |
| 52 | matchedPropertyCacheInheritedHit = 0; |
| 53 | matchedPropertyCacheAdded = 0; |
| 54 | } |
| 55 | |
| 56 | String StyleResolverStats::report() const |
| 57 | { |
| 58 | StringBuilder output; |
| 59 | |
| 60 | unsigned sharedStylesRejected = sharedStyleRejectedByUncommonAttributeRules + sharedStyleRejectedBySiblingRules + sharedStyleRejectedByParent; |
| 61 | unsigned sharedStylesUsed = sharedStyleFound - sharedStylesRejected; |
| 62 | |
| 63 | output.append("Style sharing:\n"); |
| 64 | output.append(String::format(" %u elements were added to the sharing candidate list.\n", sharedStyleCandidates)); |
| 65 | output.append(String::format(" %u calls were made to findSharedStyle, %u found a candidate to share with (%.2f%%).\n", sharedStyleLookups, sharedStyleFound, PERCENT(sharedStyleFound, sharedStyleLookups))); |
| 66 | if (printMissedCandidateCount) |
| 67 | output.append(String::format(" %u candidates could have matched but were not in the list when searching (%.2f%%).\n", sharedStyleMissed, PERCENT(sharedStyleMissed, sharedStyleLookups))); |
| 68 | output.append(String::format(" %u of found styles were rejected (%.2f%%), %.2f%% by uncommon attribute rules, %.2f%% by sibling rules and %.2f%% by parents disabling sharing.\n", |
| 69 | sharedStylesRejected, |
| 70 | PERCENT(sharedStylesRejected, sharedStyleFound), |
| 71 | PERCENT(sharedStyleRejectedByUncommonAttributeRules, sharedStylesRejected), |
| 72 | PERCENT(sharedStyleRejectedBySiblingRules, sharedStylesRejected), |
| 73 | PERCENT(sharedStyleRejectedByParent, sharedStylesRejected))); |
| 74 | output.append(String::format(" %u of found styles were used for sharing (%.2f%%).\n", sharedStylesUsed, PERCENT(sharedStylesUsed, sharedStyleFound))); |
| 75 | output.append(String::format(" %.2f%% of calls to findSharedStyle returned a shared style.\n", PERCENT(sharedStylesUsed, sharedStyleLookups))); |
| 76 | |
| 77 | output.append("\n"); |
| 78 | |
| 79 | output.append("Matched property cache:\n"); |
| 80 | output.append(String::format(" %u calls to applyMatchedProperties, %u hit the cache (%.2f%%).\n", matchedPropertyApply, matchedPropertyCacheHit, PERCENT(matchedPropertyCacheHit, matchedPropertyApply))); |
| 81 | output.append(String::format(" %u cache hits also shared the inherited style (%.2f%%).\n", matchedPropertyCacheInheritedHit, PERCENT(matchedPropertyCacheInheritedHit, matchedPropertyCacheHit))); |
| 82 | output.append(String::format(" %u styles created in applyMatchedProperties were added to the cache (%.2f%%).\n", matchedPropertyCacheAdded, PERCENT(matchedPropertyCacheAdded, matchedPropertyApply))); |
| 83 | |
| 84 | return output.toString(); |
| 85 | } |
| 86 | |
| 87 | } // namespace WebCore |