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

Side by Side Diff: src/d8.cc

Issue 67100: Reenable d8 stats timers, using the histogram mechanism (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years, 8 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
« no previous file with comments | « src/d8.h ('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 2009 the V8 project authors. All rights reserved. 1 // Copyright 2009 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 Context::Scope context_scope(utility_context_); 261 Context::Scope context_scope(utility_context_);
262 Handle<Object> global = utility_context_->Global(); 262 Handle<Object> global = utility_context_->Global();
263 Handle<Value> fun = global->Get(String::New("DebugCommandToJSONRequest")); 263 Handle<Value> fun = global->Get(String::New("DebugCommandToJSONRequest"));
264 static const int kArgc = 1; 264 static const int kArgc = 1;
265 Handle<Value> argv[kArgc] = { command }; 265 Handle<Value> argv[kArgc] = { command };
266 Handle<Value> val = Handle<Function>::Cast(fun)->Call(global, kArgc, argv); 266 Handle<Value> val = Handle<Function>::Cast(fun)->Call(global, kArgc, argv);
267 return val; 267 return val;
268 } 268 }
269 269
270 270
271 int32_t* Counter::Bind(const char* name) { 271 int32_t* Counter::Bind(const char* name, bool is_histogram) {
272 int i; 272 int i;
273 for (i = 0; i < kMaxNameSize - 1 && name[i]; i++) 273 for (i = 0; i < kMaxNameSize - 1 && name[i]; i++)
274 name_[i] = static_cast<char>(name[i]); 274 name_[i] = static_cast<char>(name[i]);
275 name_[i] = '\0'; 275 name_[i] = '\0';
276 return &counter_; 276 is_histogram_ = is_histogram;
277 return ptr();
278 }
279
280
281 void Counter::AddSample(int32_t sample) {
282 count_++;
283 sample_total_ += sample;
277 } 284 }
278 285
279 286
280 CounterCollection::CounterCollection() { 287 CounterCollection::CounterCollection() {
281 magic_number_ = 0xDEADFACE; 288 magic_number_ = 0xDEADFACE;
282 max_counters_ = kMaxCounters; 289 max_counters_ = kMaxCounters;
283 max_name_size_ = Counter::kMaxNameSize; 290 max_name_size_ = Counter::kMaxNameSize;
284 counters_in_use_ = 0; 291 counters_in_use_ = 0;
285 } 292 }
286 293
287 294
288 Counter* CounterCollection::GetNextCounter() { 295 Counter* CounterCollection::GetNextCounter() {
289 if (counters_in_use_ == kMaxCounters) return NULL; 296 if (counters_in_use_ == kMaxCounters) return NULL;
290 return &counters_[counters_in_use_++]; 297 return &counters_[counters_in_use_++];
291 } 298 }
292 299
293 300
294 void Shell::MapCounters(const char* name) { 301 void Shell::MapCounters(const char* name) {
295 counters_file_ = i::OS::MemoryMappedFile::create(name, 302 counters_file_ = i::OS::MemoryMappedFile::create(name,
296 sizeof(CounterCollection), &local_counters_); 303 sizeof(CounterCollection), &local_counters_);
297 void* memory = (counters_file_ == NULL) ? 304 void* memory = (counters_file_ == NULL) ?
298 NULL : counters_file_->memory(); 305 NULL : counters_file_->memory();
299 if (memory == NULL) { 306 if (memory == NULL) {
300 printf("Could not map counters file %s\n", name); 307 printf("Could not map counters file %s\n", name);
301 exit(1); 308 exit(1);
302 } 309 }
303 counters_ = static_cast<CounterCollection*>(memory); 310 counters_ = static_cast<CounterCollection*>(memory);
304 V8::SetCounterFunction(LookupCounter); 311 V8::SetCounterFunction(LookupCounter);
312 V8::SetCreateHistogramFunction(CreateHistogram);
313 V8::SetAddHistogramSampleFunction(AddHistogramSample);
305 } 314 }
306 315
307 316
308 int CounterMap::Hash(const char* name) { 317 int CounterMap::Hash(const char* name) {
309 int h = 0; 318 int h = 0;
310 int c; 319 int c;
311 while ((c = *name++) != 0) { 320 while ((c = *name++) != 0) {
312 h += h << 5; 321 h += h << 5;
313 h += c; 322 h += c;
314 } 323 }
315 return h; 324 return h;
316 } 325 }
317 326
318 327
328 Counter* Shell::GetCounter(const char* name, bool is_histogram) {
329 Counter* counter = counter_map_->Lookup(name);
330
331 if (counter == NULL) {
332 counter = counters_->GetNextCounter();
333 if (counter != NULL) {
334 counter_map_->Set(name, counter);
335 counter->Bind(name, is_histogram);
336 }
337 } else {
338 ASSERT(counter->is_histogram() == is_histogram);
339 }
340 return counter;
341 }
342
343
319 int* Shell::LookupCounter(const char* name) { 344 int* Shell::LookupCounter(const char* name) {
320 Counter* counter = counter_map_->Lookup(name); 345 Counter* counter = GetCounter(name, false);
346
321 if (counter != NULL) { 347 if (counter != NULL) {
322 return counter->ptr(); 348 return counter->ptr();
349 } else {
350 return NULL;
323 } 351 }
324 Counter* result = counters_->GetNextCounter(); 352 }
325 if (result == NULL) return NULL; 353
326 counter_map_->Set(name, result); 354
327 return result->Bind(name); 355 void* Shell::CreateHistogram(const char* name,
356 int min,
357 int max,
358 size_t buckets) {
359 return GetCounter(name, true);
360 }
361
362
363 void Shell::AddHistogramSample(void* histogram, int sample) {
364 Counter* counter = reinterpret_cast<Counter*>(histogram);
365 counter->AddSample(sample);
328 } 366 }
329 367
330 368
331 void Shell::Initialize() { 369 void Shell::Initialize() {
332 Shell::counter_map_ = new CounterMap(); 370 Shell::counter_map_ = new CounterMap();
333 // Set up counters 371 // Set up counters
334 if (i::FLAG_map_counters != NULL) 372 if (i::FLAG_map_counters != NULL)
335 MapCounters(i::FLAG_map_counters); 373 MapCounters(i::FLAG_map_counters);
336 if (i::FLAG_dump_counters) 374 if (i::FLAG_dump_counters) {
337 V8::SetCounterFunction(LookupCounter); 375 V8::SetCounterFunction(LookupCounter);
376 V8::SetCreateHistogramFunction(CreateHistogram);
377 V8::SetAddHistogramSampleFunction(AddHistogramSample);
378 }
379
338 // Initialize the global objects 380 // Initialize the global objects
339 HandleScope scope; 381 HandleScope scope;
340 Handle<ObjectTemplate> global_template = ObjectTemplate::New(); 382 Handle<ObjectTemplate> global_template = ObjectTemplate::New();
341 global_template->Set(String::New("print"), FunctionTemplate::New(Print)); 383 global_template->Set(String::New("print"), FunctionTemplate::New(Print));
342 global_template->Set(String::New("load"), FunctionTemplate::New(Load)); 384 global_template->Set(String::New("load"), FunctionTemplate::New(Load));
343 global_template->Set(String::New("quit"), FunctionTemplate::New(Quit)); 385 global_template->Set(String::New("quit"), FunctionTemplate::New(Quit));
344 global_template->Set(String::New("version"), FunctionTemplate::New(Version)); 386 global_template->Set(String::New("version"), FunctionTemplate::New(Version));
345 387
346 Handle<ObjectTemplate> os_templ = ObjectTemplate::New(); 388 Handle<ObjectTemplate> os_templ = ObjectTemplate::New();
347 AddOSMethods(os_templ); 389 AddOSMethods(os_templ);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 } 441 }
400 442
401 443
402 void Shell::OnExit() { 444 void Shell::OnExit() {
403 if (i::FLAG_dump_counters) { 445 if (i::FLAG_dump_counters) {
404 ::printf("+----------------------------------------+-------------+\n"); 446 ::printf("+----------------------------------------+-------------+\n");
405 ::printf("| Name | Value |\n"); 447 ::printf("| Name | Value |\n");
406 ::printf("+----------------------------------------+-------------+\n"); 448 ::printf("+----------------------------------------+-------------+\n");
407 for (CounterMap::Iterator i(counter_map_); i.More(); i.Next()) { 449 for (CounterMap::Iterator i(counter_map_); i.More(); i.Next()) {
408 Counter* counter = i.CurrentValue(); 450 Counter* counter = i.CurrentValue();
409 ::printf("| %-38s | %11i |\n", i.CurrentKey(), counter->value()); 451 if (counter->is_histogram()) {
452 ::printf("| c:%-36s | %11i |\n", i.CurrentKey(), counter->count());
453 ::printf("| t:%-36s | %11i |\n",
454 i.CurrentKey(),
455 counter->sample_total());
456 } else {
457 ::printf("| %-38s | %11i |\n", i.CurrentKey(), counter->count());
458 }
410 } 459 }
411 ::printf("+----------------------------------------+-------------+\n"); 460 ::printf("+----------------------------------------+-------------+\n");
412 } 461 }
413 if (counters_file_ != NULL) 462 if (counters_file_ != NULL)
414 delete counters_file_; 463 delete counters_file_;
415 } 464 }
416 465
417 466
418 static char* ReadChars(const char *name, int* size_out) { 467 static char* ReadChars(const char *name, int* size_out) {
419 v8::Unlocker unlocker; // Release the V8 lock while reading files. 468 v8::Unlocker unlocker; // Release the V8 lock while reading files.
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 return 0; 717 return 0;
669 } 718 }
670 719
671 720
672 } // namespace v8 721 } // namespace v8
673 722
674 723
675 int main(int argc, char* argv[]) { 724 int main(int argc, char* argv[]) {
676 return v8::Shell::Main(argc, argv); 725 return v8::Shell::Main(argc, argv);
677 } 726 }
OLDNEW
« no previous file with comments | « src/d8.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698