[email protected] | 88269e47 | 2011-06-24 06:32:59 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 8ec7126 | 2011-07-28 08:12:46 | [diff] [blame] | 5 | #include "chrome/browser/spellchecker/spellcheck_host_metrics.h" |
[email protected] | 88269e47 | 2011-06-24 06:32:59 | [diff] [blame] | 6 | |
| 7 | #include "base/md5.h" |
| 8 | #include "base/metrics/histogram.h" |
| 9 | |
| 10 | SpellCheckHostMetrics::SpellCheckHostMetrics() |
[email protected] | 7e1f665 | 2011-06-27 07:10:43 | [diff] [blame] | 11 | : misspelled_word_count_(0), |
| 12 | spellchecked_word_count_(0), |
| 13 | suggestion_show_count_(0), |
| 14 | replaced_word_count_(0), |
| 15 | start_time_(base::Time::Now()) { |
[email protected] | 88269e47 | 2011-06-24 06:32:59 | [diff] [blame] | 16 | const uint64 kHistogramTimerDurationInMinutes = 30; |
[email protected] | d323a17 | 2011-09-02 18:23:02 | [diff] [blame^] | 17 | recording_timer_.Start(FROM_HERE, |
[email protected] | 88269e47 | 2011-06-24 06:32:59 | [diff] [blame] | 18 | base::TimeDelta::FromMinutes(kHistogramTimerDurationInMinutes), |
| 19 | this, &SpellCheckHostMetrics::OnHistogramTimerExpired); |
[email protected] | 7e1f665 | 2011-06-27 07:10:43 | [diff] [blame] | 20 | RecordWordCounts(); |
[email protected] | 88269e47 | 2011-06-24 06:32:59 | [diff] [blame] | 21 | } |
| 22 | |
| 23 | SpellCheckHostMetrics::~SpellCheckHostMetrics() { |
| 24 | } |
| 25 | |
| 26 | void SpellCheckHostMetrics::RecordCustomWordCountStats(size_t count) { |
| 27 | UMA_HISTOGRAM_COUNTS("SpellCheck.CustomWords", count); |
| 28 | } |
| 29 | |
| 30 | void SpellCheckHostMetrics::RecordEnabledStats(bool enabled) { |
| 31 | UMA_HISTOGRAM_BOOLEAN("SpellCheck.Enabled", enabled); |
| 32 | // Because SpellCheckHost is instantiated lazily, the size of |
| 33 | // custom dictionary is unknown at this time. We mark it as -1 and |
| 34 | // record actual value later. See SpellCheckHost for more detail. |
| 35 | if (enabled) |
| 36 | RecordCustomWordCountStats(-1); |
| 37 | } |
| 38 | |
| 39 | void SpellCheckHostMetrics::RecordCheckedWordStats(const string16& word, |
| 40 | bool misspell) { |
| 41 | spellchecked_word_count_++; |
| 42 | if (misspell) { |
| 43 | misspelled_word_count_++; |
| 44 | // If an user misspelled, that user should be counted as a part of |
| 45 | // the population. So we ensure to instantiate the histogram |
| 46 | // entries here at the first time. |
| 47 | if (misspelled_word_count_ == 1) |
| 48 | RecordReplacedWordStats(0); |
| 49 | } |
| 50 | |
| 51 | int percentage = (100 * misspelled_word_count_) / spellchecked_word_count_; |
| 52 | UMA_HISTOGRAM_PERCENTAGE("SpellCheck.MisspellRatio", percentage); |
| 53 | |
| 54 | // Collects actual number of checked words, excluding duplication. |
[email protected] | 0ad1d2d6 | 2011-07-18 16:54:58 | [diff] [blame] | 55 | base::MD5Digest digest; |
| 56 | base::MD5Sum(reinterpret_cast<const unsigned char*>(word.c_str()), |
[email protected] | 88269e47 | 2011-06-24 06:32:59 | [diff] [blame] | 57 | word.size() * sizeof(char16), &digest); |
[email protected] | 0ad1d2d6 | 2011-07-18 16:54:58 | [diff] [blame] | 58 | checked_word_hashes_.insert(base::MD5DigestToBase16(digest)); |
[email protected] | 7e1f665 | 2011-06-27 07:10:43 | [diff] [blame] | 59 | |
| 60 | RecordWordCounts(); |
[email protected] | 88269e47 | 2011-06-24 06:32:59 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | void SpellCheckHostMetrics::OnHistogramTimerExpired() { |
| 64 | if (0 < spellchecked_word_count_) { |
| 65 | // Collects word checking rate, which is represented |
| 66 | // as a word count per hour. |
| 67 | base::TimeDelta since_start = base::Time::Now() - start_time_; |
| 68 | size_t checked_words_per_hour = spellchecked_word_count_ * |
| 69 | base::TimeDelta::FromHours(1).InSeconds() / since_start.InSeconds(); |
| 70 | UMA_HISTOGRAM_COUNTS("SpellCheck.CheckedWordsPerHour", |
| 71 | checked_words_per_hour); |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | void SpellCheckHostMetrics::RecordDictionaryCorruptionStats(bool corrupted) { |
| 76 | UMA_HISTOGRAM_BOOLEAN("SpellCheck.DictionaryCorrupted", corrupted); |
| 77 | } |
| 78 | |
| 79 | void SpellCheckHostMetrics::RecordSuggestionStats(int delta) { |
| 80 | suggestion_show_count_ += delta; |
[email protected] | 7e1f665 | 2011-06-27 07:10:43 | [diff] [blame] | 81 | // RecordReplacedWordStats() Calls RecordWordCounts() eventually. |
[email protected] | 88269e47 | 2011-06-24 06:32:59 | [diff] [blame] | 82 | RecordReplacedWordStats(0); |
| 83 | } |
| 84 | |
| 85 | void SpellCheckHostMetrics::RecordReplacedWordStats(int delta) { |
| 86 | replaced_word_count_ += delta; |
[email protected] | 88269e47 | 2011-06-24 06:32:59 | [diff] [blame] | 87 | |
| 88 | if (misspelled_word_count_) { |
| 89 | // zero |misspelled_word_count_| is possible when an extension |
| 90 | // gives the misspelling, which is not recorded as a part of this |
| 91 | // metrics. |
| 92 | int percentage = (100 * replaced_word_count_) / misspelled_word_count_; |
| 93 | UMA_HISTOGRAM_PERCENTAGE("SpellCheck.ReplaceRatio", percentage); |
| 94 | } |
| 95 | |
| 96 | if (suggestion_show_count_) { |
| 97 | int percentage = (100 * replaced_word_count_) / suggestion_show_count_; |
| 98 | UMA_HISTOGRAM_PERCENTAGE("SpellCheck.SuggestionHitRatio", percentage); |
| 99 | } |
[email protected] | 7e1f665 | 2011-06-27 07:10:43 | [diff] [blame] | 100 | |
| 101 | RecordWordCounts(); |
| 102 | } |
| 103 | |
| 104 | void SpellCheckHostMetrics::RecordWordCounts() { |
| 105 | UMA_HISTOGRAM_COUNTS("SpellCheck.CheckedWords", spellchecked_word_count_); |
| 106 | UMA_HISTOGRAM_COUNTS("SpellCheck.MisspelledWords", misspelled_word_count_); |
| 107 | UMA_HISTOGRAM_COUNTS("SpellCheck.ReplacedWords", replaced_word_count_); |
| 108 | UMA_HISTOGRAM_COUNTS("SpellCheck.UniqueWords", checked_word_hashes_.size()); |
| 109 | UMA_HISTOGRAM_COUNTS("SpellCheck.ShownSuggestions", suggestion_show_count_); |
[email protected] | 88269e47 | 2011-06-24 06:32:59 | [diff] [blame] | 110 | } |