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

Side by Side Diff: test/cctest/test-log-utils.cc

Issue 125114: Involve more log compression techniques. (Closed)
Patch Set: Created 11 years, 6 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
« no previous file with comments | « src/log-utils.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. 1 // Copyright 2006-2009 the V8 project authors. All rights reserved.
2 // 2 //
3 // Tests of logging utilities from log-utils.h 3 // Tests of logging utilities from log-utils.h
4 4
5 #ifdef ENABLE_LOGGING_AND_PROFILING 5 #ifdef ENABLE_LOGGING_AND_PROFILING
6 6
7 #include "v8.h" 7 #include "v8.h"
8 8
9 #include "log-utils.h" 9 #include "log-utils.h"
10 #include "cctest.h" 10 #include "cctest.h"
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 // Check the seal. 132 // Check the seal.
133 EmbeddedVector<char, 50> seal_buf; 133 EmbeddedVector<char, 50> seal_buf;
134 CHECK_EQ(seal_size, ReadData(&dynabuf, 100, &seal_buf)); 134 CHECK_EQ(seal_size, ReadData(&dynabuf, 100, &seal_buf));
135 CHECK_EQ(CStrVector(seal), seal_buf.SubVector(0, seal_size)); 135 CHECK_EQ(CStrVector(seal), seal_buf.SubVector(0, seal_size));
136 // Verify that there's no data beyond the seal. 136 // Verify that there's no data beyond the seal.
137 CHECK_EQ(0, ReadData(&dynabuf, 100 + seal_size, &buf)); 137 CHECK_EQ(0, ReadData(&dynabuf, 100 + seal_size, &buf));
138 } 138 }
139 139
140 140
141 TEST(CompressorStore) { 141 TEST(CompressorStore) {
142 LogRecordCompressor comp(2, 0); 142 LogRecordCompressor comp(2);
143 const Vector<const char> empty = CStrVector(""); 143 const Vector<const char> empty = CStrVector("");
144 CHECK(comp.Store(empty)); 144 CHECK(comp.Store(empty));
145 CHECK(!comp.Store(empty)); 145 CHECK(!comp.Store(empty));
146 CHECK(!comp.Store(empty)); 146 CHECK(!comp.Store(empty));
147 const Vector<const char> aaa = CStrVector("aaa"); 147 const Vector<const char> aaa = CStrVector("aaa");
148 CHECK(comp.Store(aaa)); 148 CHECK(comp.Store(aaa));
149 CHECK(!comp.Store(aaa)); 149 CHECK(!comp.Store(aaa));
150 CHECK(!comp.Store(aaa)); 150 CHECK(!comp.Store(aaa));
151 CHECK(comp.Store(empty)); 151 CHECK(comp.Store(empty));
152 CHECK(!comp.Store(empty)); 152 CHECK(!comp.Store(empty));
153 CHECK(!comp.Store(empty)); 153 CHECK(!comp.Store(empty));
154 } 154 }
155 155
156 156
157 void CheckCompression(LogRecordCompressor* comp, 157 void CheckCompression(LogRecordCompressor* comp,
158 const Vector<const char>& after) { 158 const Vector<const char>& after) {
159 EmbeddedVector<char, 100> result; 159 EmbeddedVector<char, 100> result;
160 CHECK(comp->RetrievePreviousCompressed(&result)); 160 CHECK(comp->RetrievePreviousCompressed(&result));
161 CHECK_EQ(after, result); 161 CHECK_EQ(after, result);
162 } 162 }
163 163
164 164
165 void CheckCompression(LogRecordCompressor* comp, 165 void CheckCompression(LogRecordCompressor* comp,
166 const char* after) { 166 const char* after) {
167 CheckCompression(comp, CStrVector(after)); 167 CheckCompression(comp, CStrVector(after));
168 } 168 }
169 169
170 170
171 TEST(CompressorNonCompressed) { 171 TEST(CompressorNonCompressed) {
172 LogRecordCompressor comp(2, 0); 172 LogRecordCompressor comp(0);
173 CHECK(!comp.RetrievePreviousCompressed(NULL)); 173 CHECK(!comp.RetrievePreviousCompressed(NULL));
174 const Vector<const char> empty = CStrVector(""); 174 const Vector<const char> empty = CStrVector("");
175 CHECK(comp.Store(empty)); 175 CHECK(comp.Store(empty));
176 CHECK(!comp.RetrievePreviousCompressed(NULL)); 176 CHECK(!comp.RetrievePreviousCompressed(NULL));
177 const Vector<const char> a_x_20 = CStrVector("aaaaaaaaaaaaaaaaaaaa"); 177 const Vector<const char> a_x_20 = CStrVector("aaaaaaaaaaaaaaaaaaaa");
178 CHECK(comp.Store(a_x_20)); 178 CHECK(comp.Store(a_x_20));
179 CheckCompression(&comp, empty); 179 CheckCompression(&comp, empty);
180 CheckCompression(&comp, empty); 180 CheckCompression(&comp, empty);
181 CHECK(comp.Store(empty)); 181 CHECK(comp.Store(empty));
182 CheckCompression(&comp, a_x_20); 182 CheckCompression(&comp, a_x_20);
183 CheckCompression(&comp, a_x_20); 183 CheckCompression(&comp, a_x_20);
184 } 184 }
185 185
186 186
187 TEST(CompressorSingleLine) { 187 TEST(CompressorSingleLine) {
188 LogRecordCompressor comp(3, strlen("xxx,")); 188 LogRecordCompressor comp(1);
189 const Vector<const char> string_1 = CStrVector("eee,ddd,ccc,bbb,aaa"); 189 const Vector<const char> string_1 = CStrVector("eee,ddd,ccc,bbb,aaa");
190 CHECK(comp.Store(string_1)); 190 CHECK(comp.Store(string_1));
191 const Vector<const char> string_2 = CStrVector("fff,ddd,ccc,bbb,aaa"); 191 const Vector<const char> string_2 = CStrVector("fff,ddd,ccc,bbb,aaa");
192 CHECK(comp.Store(string_2)); 192 CHECK(comp.Store(string_2));
193 // string_1 hasn't been compressed. 193 // string_1 hasn't been compressed.
194 CheckCompression(&comp, string_1); 194 CheckCompression(&comp, string_1);
195 CheckCompression(&comp, string_1); 195 CheckCompression(&comp, string_1);
196 const Vector<const char> string_3 = CStrVector("hhh,ggg,ccc,bbb,aaa"); 196 const Vector<const char> string_3 = CStrVector("hhh,ggg,ccc,bbb,aaa");
197 CHECK(comp.Store(string_3)); 197 CHECK(comp.Store(string_3));
198 // string_2 compressed using string_1. 198 // string_2 compressed using string_1.
199 CheckCompression(&comp, "fff,#1:4"); 199 CheckCompression(&comp, "fff#1:3");
200 CheckCompression(&comp, "fff,#1:4"); 200 CheckCompression(&comp, "fff#1:3");
201 CHECK(!comp.Store(string_3)); 201 CHECK(!comp.Store(string_3));
202 // Expecting no changes. 202 // Expecting no changes.
203 CheckCompression(&comp, "fff,#1:4"); 203 CheckCompression(&comp, "fff#1:3");
204 CHECK(!comp.Store(string_3)); 204 CHECK(!comp.Store(string_3));
205 // Expecting no changes. 205 // Expecting no changes.
206 CheckCompression(&comp, "fff,#1:4"); 206 CheckCompression(&comp, "fff#1:3");
207 const Vector<const char> string_4 = CStrVector("iii,hhh,ggg,ccc,bbb,aaa"); 207 const Vector<const char> string_4 = CStrVector("iii,hhh,ggg,ccc,bbb,aaa");
208 CHECK(comp.Store(string_4)); 208 CHECK(comp.Store(string_4));
209 // string_3 compressed using string_2. 209 // string_3 compressed using string_2.
210 CheckCompression(&comp, "hhh,ggg#1:7"); 210 CheckCompression(&comp, "hhh,ggg#1:7");
211 const Vector<const char> string_5 = CStrVector("nnn,mmm,lll,kkk,jjj"); 211 const Vector<const char> string_5 = CStrVector("nnn,mmm,lll,kkk,jjj");
212 CHECK(comp.Store(string_5)); 212 CHECK(comp.Store(string_5));
213 // string_4 compressed using string_3. 213 // string_4 compressed using string_3.
214 CheckCompression(&comp, "iii,#1:0"); 214 CheckCompression(&comp, "iii,#1");
215 const Vector<const char> string_6 = CStrVector("nnn,mmmmmm,lll,kkk,jjj"); 215 const Vector<const char> string_6 = CStrVector("nnn,mmmmmm,lll,kkk,jjj");
216 CHECK(comp.Store(string_6)); 216 CHECK(comp.Store(string_6));
217 // string_5 hasn't been compressed. 217 // string_5 hasn't been compressed.
218 CheckCompression(&comp, string_5); 218 CheckCompression(&comp, string_5);
219 CHECK(comp.Store(string_5)); 219 CHECK(comp.Store(string_5));
220 // string_6 compressed using string_5. 220 // string_6 compressed using string_5.
221 CheckCompression(&comp, "nnn,mmm#1:4"); 221 CheckCompression(&comp, "nnn,mmm#1:4");
222 const Vector<const char> string_7 = CStrVector("nnnnnn,mmm,lll,kkk,jjj"); 222 const Vector<const char> string_7 = CStrVector("nnnnnn,mmm,lll,kkk,jjj");
223 CHECK(comp.Store(string_7)); 223 CHECK(comp.Store(string_7));
224 // string_5 compressed using string_6. 224 // string_5 compressed using string_6.
225 CheckCompression(&comp, "nnn,#1:7"); 225 CheckCompression(&comp, "nnn,#1:7");
226 const Vector<const char> string_8 = CStrVector("xxn,mmm,lll,kkk,jjj"); 226 const Vector<const char> string_8 = CStrVector("xxn,mmm,lll,kkk,jjj");
227 CHECK(comp.Store(string_8)); 227 CHECK(comp.Store(string_8));
228 // string_7 compressed using string_5. 228 // string_7 compressed using string_5.
229 CheckCompression(&comp, "nnnn#1:1"); 229 CheckCompression(&comp, "nnn#1");
230 const Vector<const char> string_9 = 230 const Vector<const char> string_9 =
231 CStrVector("aaaaaaaaaaaaa,bbbbbbbbbbbbbbbbb"); 231 CStrVector("aaaaaaaaaaaaa,bbbbbbbbbbbbbbbbb");
232 CHECK(comp.Store(string_9)); 232 CHECK(comp.Store(string_9));
233 // string_8 compressed using string_7. 233 // string_8 compressed using string_7.
234 CheckCompression(&comp, "xxn,#1:7"); 234 CheckCompression(&comp, "xx#1:5");
235 const Vector<const char> string_10 = 235 const Vector<const char> string_10 =
236 CStrVector("aaaaaaaaaaaaa,cccccccbbbbbbbbbb"); 236 CStrVector("aaaaaaaaaaaaa,cccccccbbbbbbbbbb");
237 CHECK(comp.Store(string_10)); 237 CHECK(comp.Store(string_10));
238 // string_9 hasn't been compressed. 238 // string_9 hasn't been compressed.
239 CheckCompression(&comp, string_9); 239 CheckCompression(&comp, string_9);
240 CHECK(comp.Store(string_1)); 240 CHECK(comp.Store(string_1));
241 // string_10 compressed using string_9. 241 // string_10 compressed using string_9.
242 CheckCompression(&comp, "aaaaaaaaaaaaa,ccccccc#1:21"); 242 CheckCompression(&comp, "aaaaaaaaaaaaa,ccccccc#1:21");
243 } 243 }
244 244
245 245
246 246
247 TEST(CompressorMultiLines) { 247 TEST(CompressorMultiLines) {
248 const int kWindowSize = 5; 248 const int kWindowSize = 3;
249 LogRecordCompressor comp(kWindowSize, strlen("xxx,")); 249 LogRecordCompressor comp(kWindowSize);
250 const Vector<const char> string_1 = CStrVector("eee,ddd,ccc,bbb,aaa"); 250 const Vector<const char> string_1 = CStrVector("eee,ddd,ccc,bbb,aaa");
251 CHECK(comp.Store(string_1)); 251 CHECK(comp.Store(string_1));
252 const Vector<const char> string_2 = CStrVector("iii,hhh,ggg,fff,aaa"); 252 const Vector<const char> string_2 = CStrVector("iii,hhh,ggg,fff,aaa");
253 CHECK(comp.Store(string_2)); 253 CHECK(comp.Store(string_2));
254 const Vector<const char> string_3 = CStrVector("mmm,lll,kkk,jjj,aaa"); 254 const Vector<const char> string_3 = CStrVector("mmm,lll,kkk,jjj,aaa");
255 CHECK(comp.Store(string_3)); 255 CHECK(comp.Store(string_3));
256 const Vector<const char> string_4 = CStrVector("nnn,hhh,ggg,fff,aaa"); 256 const Vector<const char> string_4 = CStrVector("nnn,hhh,ggg,fff,aaa");
257 CHECK(comp.Store(string_4)); 257 CHECK(comp.Store(string_4));
258 const Vector<const char> string_5 = CStrVector("ooo,lll,kkk,jjj,aaa"); 258 const Vector<const char> string_5 = CStrVector("ooo,lll,kkk,jjj,aaa");
259 CHECK(comp.Store(string_5)); 259 CHECK(comp.Store(string_5));
260 // string_4 compressed using string_2. 260 // string_4 compressed using string_2.
261 CheckCompression(&comp, "nnn,#2:4"); 261 CheckCompression(&comp, "nnn#2:3");
262 CHECK(comp.Store(string_1)); 262 CHECK(comp.Store(string_1));
263 // string_5 compressed using string_3. 263 // string_5 compressed using string_3.
264 CheckCompression(&comp, "ooo,#2:4"); 264 CheckCompression(&comp, "ooo#2:3");
265 CHECK(comp.Store(string_4)); 265 CHECK(comp.Store(string_4));
266 // string_1 is out of buffer by now, so it shouldn't be compressed. 266 // string_1 is out of buffer by now, so it shouldn't be compressed.
267 CHECK_GE(5, kWindowSize); 267 CHECK_GE(3, kWindowSize);
268 CheckCompression(&comp, string_1); 268 CheckCompression(&comp, string_1);
269 CHECK(comp.Store(string_2)); 269 CHECK(comp.Store(string_2));
270 // string_4 compressed using itself. 270 // string_4 compressed using itself.
271 CheckCompression(&comp, "nnn,#3:4"); 271 CheckCompression(&comp, "#3");
272 } 272 }
273 273
274 274
275 TEST(CompressorBestSelection) { 275 TEST(CompressorBestSelection) {
276 LogRecordCompressor comp(5, strlen("xxx,")); 276 LogRecordCompressor comp(3);
277 const Vector<const char> string_1 = CStrVector("eee,ddd,ccc,bbb,aaa"); 277 const Vector<const char> string_1 = CStrVector("eee,ddd,ccc,bbb,aaa");
278 CHECK(comp.Store(string_1)); 278 CHECK(comp.Store(string_1));
279 const Vector<const char> string_2 = CStrVector("ddd,ccc,bbb,aaa"); 279 const Vector<const char> string_2 = CStrVector("ddd,ccc,bbb,aaa");
280 CHECK(comp.Store(string_2)); 280 CHECK(comp.Store(string_2));
281 const Vector<const char> string_3 = CStrVector("fff,eee,ddd,ccc,bbb,aaa"); 281 const Vector<const char> string_3 = CStrVector("fff,eee,ddd,ccc,bbb,aaa");
282 CHECK(comp.Store(string_3)); 282 CHECK(comp.Store(string_3));
283 // string_2 compressed using string_1. 283 // string_2 compressed using string_1.
284 CheckCompression(&comp, "ddd,#1:8"); 284 CheckCompression(&comp, "#1:4");
285 const Vector<const char> string_4 = CStrVector("nnn,hhh,ggg,fff,aaa"); 285 const Vector<const char> string_4 = CStrVector("nnn,hhh,ggg,fff,aaa");
286 CHECK(comp.Store(string_4)); 286 CHECK(comp.Store(string_4));
287 // Compressing string_3 using string_1 gives a better compression than 287 // Compressing string_3 using string_1 gives a better compression than
288 // using string_2. 288 // using string_2.
289 CheckCompression(&comp, "fff,#2:0"); 289 CheckCompression(&comp, "fff,#2");
290 }
291
292
293 TEST(CompressorCompressibility) {
294 LogRecordCompressor comp(2);
295 const Vector<const char> string_1 = CStrVector("eee,ddd,ccc,bbb,aaa");
296 CHECK(comp.Store(string_1));
297 const Vector<const char> string_2 = CStrVector("ccc,bbb,aaa");
298 CHECK(comp.Store(string_2));
299 const Vector<const char> string_3 = CStrVector("aaa");
300 CHECK(comp.Store(string_3));
301 // string_2 compressed using string_1.
302 CheckCompression(&comp, "#1:8");
303 const Vector<const char> string_4 = CStrVector("xxx");
304 CHECK(comp.Store(string_4));
305 // string_3 can't be compressed using string_2 --- too short.
306 CheckCompression(&comp, string_3);
290 } 307 }
291 308
292 #endif // ENABLE_LOGGING_AND_PROFILING 309 #endif // ENABLE_LOGGING_AND_PROFILING
OLDNEW
« no previous file with comments | « src/log-utils.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698