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

Side by Side Diff: base/debug/crash_logging.cc

Issue 12211080: Change crash keys to be registered with a maximum length instead of number of chunks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Win fix Created 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/debug/crash_logging.h" 5 #include "base/debug/crash_logging.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/debug/stack_trace.h" 9 #include "base/debug/stack_trace.h"
10 #include "base/format_macros.h" 10 #include "base/format_macros.h"
(...skipping 23 matching lines...) Expand all
34 if (!g_set_key_func_) 34 if (!g_set_key_func_)
35 return; 35 return;
36 36
37 const CrashKey* crash_key = LookupCrashKey(key); 37 const CrashKey* crash_key = LookupCrashKey(key);
38 38
39 // TODO(rsesek): Do this: 39 // TODO(rsesek): Do this:
40 //DCHECK(crash_key) << "All crash keys must be registered before use " 40 //DCHECK(crash_key) << "All crash keys must be registered before use "
41 // << "(key = " << key << ")"; 41 // << "(key = " << key << ")";
42 42
43 // Handle the un-chunked case. 43 // Handle the un-chunked case.
44 if (!crash_key || crash_key->num_chunks == 1) { 44 if (!crash_key || crash_key->max_length <= g_chunk_max_length_) {
45 g_set_key_func_(key, value); 45 g_set_key_func_(key, value);
46 return; 46 return;
47 } 47 }
48 48
49 // Unset the unused chunks. 49 // Unset the unused chunks.
50 std::vector<std::string> chunks = 50 std::vector<std::string> chunks =
51 ChunkCrashKeyValue(*crash_key, value, g_chunk_max_length_); 51 ChunkCrashKeyValue(*crash_key, value, g_chunk_max_length_);
52 for (size_t i = chunks.size(); i < crash_key->num_chunks; ++i) { 52 for (size_t i = chunks.size();
53 i < crash_key->max_length / g_chunk_max_length_;
54 ++i) {
53 g_clear_key_func_(base::StringPrintf(kChunkFormatString, key.data(), i+1)); 55 g_clear_key_func_(base::StringPrintf(kChunkFormatString, key.data(), i+1));
54 } 56 }
55 57
56 // Set the chunked keys. 58 // Set the chunked keys.
57 for (size_t i = 0; i < chunks.size(); ++i) { 59 for (size_t i = 0; i < chunks.size(); ++i) {
58 g_set_key_func_(base::StringPrintf(kChunkFormatString, key.data(), i+1), 60 g_set_key_func_(base::StringPrintf(kChunkFormatString, key.data(), i+1),
59 chunks[i]); 61 chunks[i]);
60 } 62 }
61 } 63 }
62 64
63 void ClearCrashKey(const base::StringPiece& key) { 65 void ClearCrashKey(const base::StringPiece& key) {
64 if (!g_clear_key_func_) 66 if (!g_clear_key_func_)
65 return; 67 return;
66 68
67 const CrashKey* crash_key = LookupCrashKey(key); 69 const CrashKey* crash_key = LookupCrashKey(key);
68 70
69 // Handle the un-chunked case. 71 // Handle the un-chunked case.
70 if (!crash_key || crash_key->num_chunks == 1) { 72 if (!crash_key || crash_key->max_length <= g_chunk_max_length_) {
71 g_clear_key_func_(key); 73 g_clear_key_func_(key);
72 return; 74 return;
73 } 75 }
74 76
75 for (size_t i = 0; i < crash_key->num_chunks; ++i) { 77 for (size_t i = 0; i < crash_key->max_length / g_chunk_max_length_; ++i) {
76 g_clear_key_func_(base::StringPrintf(kChunkFormatString, key.data(), i+1)); 78 g_clear_key_func_(base::StringPrintf(kChunkFormatString, key.data(), i+1));
77 } 79 }
78 } 80 }
79 81
80 void SetCrashKeyToStackTrace(const base::StringPiece& key, 82 void SetCrashKeyToStackTrace(const base::StringPiece& key,
81 const StackTrace& trace) { 83 const StackTrace& trace) {
82 size_t count = 0; 84 size_t count = 0;
83 const void* const* addresses = trace.Addresses(&count); 85 const void* const* addresses = trace.Addresses(&count);
84 SetCrashKeyFromAddresses(key, addresses, count); 86 SetCrashKeyFromAddresses(key, addresses, count);
85 } 87 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 g_crash_keys_ = NULL; 131 g_crash_keys_ = NULL;
130 return 0; 132 return 0;
131 } 133 }
132 134
133 g_crash_keys_ = new CrashKeyMap; 135 g_crash_keys_ = new CrashKeyMap;
134 g_chunk_max_length_ = chunk_max_length; 136 g_chunk_max_length_ = chunk_max_length;
135 137
136 size_t total_keys = 0; 138 size_t total_keys = 0;
137 for (size_t i = 0; i < count; ++i) { 139 for (size_t i = 0; i < count; ++i) {
138 g_crash_keys_->insert(std::make_pair(keys[i].key_name, keys[i])); 140 g_crash_keys_->insert(std::make_pair(keys[i].key_name, keys[i]));
139 total_keys += keys[i].num_chunks; 141 total_keys += keys[i].max_length / chunk_max_length;
140 } 142 }
141 DCHECK_EQ(count, g_crash_keys_->size()) 143 DCHECK_EQ(count, g_crash_keys_->size())
142 << "Duplicate crash keys were registered"; 144 << "Duplicate crash keys were registered";
143 145
144 return total_keys; 146 return total_keys;
145 } 147 }
146 148
147 const CrashKey* LookupCrashKey(const base::StringPiece& key) { 149 const CrashKey* LookupCrashKey(const base::StringPiece& key) {
148 CrashKeyMap::const_iterator it = g_crash_keys_->find(key.as_string()); 150 CrashKeyMap::const_iterator it = g_crash_keys_->find(key.as_string());
149 if (it == g_crash_keys_->end()) 151 if (it == g_crash_keys_->end())
150 return NULL; 152 return NULL;
151 return &(it->second); 153 return &(it->second);
152 } 154 }
153 155
154 void SetCrashKeyReportingFunctions( 156 void SetCrashKeyReportingFunctions(
155 SetCrashKeyValueFuncT set_key_func, 157 SetCrashKeyValueFuncT set_key_func,
156 ClearCrashKeyValueFuncT clear_key_func) { 158 ClearCrashKeyValueFuncT clear_key_func) {
157 g_set_key_func_ = set_key_func; 159 g_set_key_func_ = set_key_func;
158 g_clear_key_func_ = clear_key_func; 160 g_clear_key_func_ = clear_key_func;
159 } 161 }
160 162
161 std::vector<std::string> ChunkCrashKeyValue(const CrashKey& crash_key, 163 std::vector<std::string> ChunkCrashKeyValue(const CrashKey& crash_key,
162 const base::StringPiece& value, 164 const base::StringPiece& value,
163 size_t chunk_max_length) { 165 size_t chunk_max_length) {
164 std::string value_string = value.as_string(); 166 std::string value_string = value.substr(0, crash_key.max_length).as_string();
eroman 2013/02/20 00:08:43 Is this restriction necessary? Assuming implementa
Robert Sesek 2013/02/27 18:52:49 At this layer, I think it makes more sense to deal
165 std::vector<std::string> chunks; 167 std::vector<std::string> chunks;
166 for (size_t i = 0, offset = 0; 168 for (size_t offset = 0; offset < value_string.length(); ) {
167 i < crash_key.num_chunks && offset < value_string.length();
168 ++i) {
169 std::string chunk = value_string.substr(offset, chunk_max_length); 169 std::string chunk = value_string.substr(offset, chunk_max_length);
170 chunks.push_back(chunk); 170 chunks.push_back(chunk);
171 offset += chunk.length(); 171 offset += chunk.length();
172 } 172 }
173 return chunks; 173 return chunks;
174 } 174 }
175 175
176 void ResetCrashLoggingForTesting() { 176 void ResetCrashLoggingForTesting() {
177 delete g_crash_keys_; 177 delete g_crash_keys_;
178 g_crash_keys_ = NULL; 178 g_crash_keys_ = NULL;
179 g_chunk_max_length_ = 0; 179 g_chunk_max_length_ = 0;
180 g_set_key_func_ = NULL; 180 g_set_key_func_ = NULL;
181 g_clear_key_func_ = NULL; 181 g_clear_key_func_ = NULL;
182 } 182 }
183 183
184 } // namespace debug 184 } // namespace debug
185 } // namespace base 185 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698