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

Side by Side Diff: src/d8.cc

Issue 7281007: expose counter in d8 (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 5 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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 580 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 591
592 #ifdef LIVE_OBJECT_LIST 592 #ifdef LIVE_OBJECT_LIST
593 global_template->Set(String::New("lol_is_enabled"), Boolean::New(true)); 593 global_template->Set(String::New("lol_is_enabled"), Boolean::New(true));
594 #else 594 #else
595 global_template->Set(String::New("lol_is_enabled"), Boolean::New(false)); 595 global_template->Set(String::New("lol_is_enabled"), Boolean::New(false));
596 #endif 596 #endif
597 597
598 Handle<ObjectTemplate> os_templ = ObjectTemplate::New(); 598 Handle<ObjectTemplate> os_templ = ObjectTemplate::New();
599 AddOSMethods(os_templ); 599 AddOSMethods(os_templ);
600 global_template->Set(String::New("os"), os_templ); 600 global_template->Set(String::New("os"), os_templ);
601 601
Yang 2011/06/29 12:02:20 Add new object "counter".
602 Handle<ObjectTemplate> counter_templ = ObjectTemplate::New();
603 counter_templ->Set(String::New("get"),
604 FunctionTemplate::New(GetCounterValue));
605 counter_templ->Set(String::New("names"),
606 FunctionTemplate::New(GetCounterNames));
607 global_template->Set(String::New("counter"), counter_templ);
608
602 return global_template; 609 return global_template;
603 } 610 }
604 611
605 612
Yang 2011/06/29 12:02:20 counter.get() returns the counter by the name prov
613 Handle<Value> Shell::GetCounterValue(const Arguments& args) {
614 if (args.Length() != 1) {
615 return ThrowException(String::New("get() takes one argument"));
616 }
617 if (args[0]->IsString()) {
618 String::AsciiValue name(args[0]);
619 Counter* counter = counter_map_->Lookup(*name);
620 if (!counter) {
621 return ThrowException(String::New("invalid counter name"));
622 }
623 return Handle<Integer>::Cast(Integer::New(counter->count()));
624 }
625 return ThrowException(String::New("counter name must be a string"));
626 }
627
628
Yang 2011/06/29 12:02:20 counter.names() returns counter names as an array
629 Handle<Value> Shell::GetCounterNames(const Arguments& args) {
630 if (args.Length() != 0) {
631 return ThrowException(String::New("names() takes no arguments"));
632 }
633 Handle<Array> results = Handle<Array>::Cast(Array::New(0));
634 int j = 0;
635 for (CounterMap::Iterator i(counter_map_); i.More(); i.Next()) {
636 results->Set(j++, Handle<String>::Cast(String::New(i.CurrentKey())));
637 }
638 return results;
639 }
640
641
606 void Shell::Initialize(bool test_shell) { 642 void Shell::Initialize(bool test_shell) {
607 #ifdef COMPRESS_STARTUP_DATA_BZ2 643 #ifdef COMPRESS_STARTUP_DATA_BZ2
608 BZip2Decompressor startup_data_decompressor; 644 BZip2Decompressor startup_data_decompressor;
609 int bz2_result = startup_data_decompressor.Decompress(); 645 int bz2_result = startup_data_decompressor.Decompress();
610 if (bz2_result != BZ_OK) { 646 if (bz2_result != BZ_OK) {
611 fprintf(stderr, "bzip error code: %d\n", bz2_result); 647 fprintf(stderr, "bzip error code: %d\n", bz2_result);
612 exit(1); 648 exit(1);
613 } 649 }
614 #endif 650 #endif
615 651
616 Shell::counter_map_ = new CounterMap(); 652 Shell::counter_map_ = new CounterMap();
617 // Set up counters 653 // Set up counters
618 if (i::StrLength(i::FLAG_map_counters) != 0) 654 if (i::StrLength(i::FLAG_map_counters) != 0)
619 MapCounters(i::FLAG_map_counters); 655 MapCounters(i::FLAG_map_counters);
Yang 2011/06/29 12:02:20 Init counter in any case (not only upon --dump-cou
620 if (i::FLAG_dump_counters) { 656 V8::SetCounterFunction(LookupCounter);
621 V8::SetCounterFunction(LookupCounter); 657 V8::SetCreateHistogramFunction(CreateHistogram);
622 V8::SetCreateHistogramFunction(CreateHistogram); 658 V8::SetAddHistogramSampleFunction(AddHistogramSample);
623 V8::SetAddHistogramSampleFunction(AddHistogramSample);
624 }
625 659
626 if (test_shell) return; 660 if (test_shell) return;
627 661
628 Locker lock; 662 Locker lock;
629 HandleScope scope; 663 HandleScope scope;
630 Handle<ObjectTemplate> global_template = CreateGlobalTemplate(); 664 Handle<ObjectTemplate> global_template = CreateGlobalTemplate();
631 utility_context_ = Context::New(NULL, global_template); 665 utility_context_ = Context::New(NULL, global_template);
632 666
633 #ifdef ENABLE_DEBUGGER_SUPPORT 667 #ifdef ENABLE_DEBUGGER_SUPPORT
634 // Start the debugger agent if requested. 668 // Start the debugger agent if requested.
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
992 } 1026 }
993 1027
994 } // namespace v8 1028 } // namespace v8
995 1029
996 1030
997 #ifndef GOOGLE3 1031 #ifndef GOOGLE3
998 int main(int argc, char* argv[]) { 1032 int main(int argc, char* argv[]) {
999 return v8::Shell::Main(argc, argv); 1033 return v8::Shell::Main(argc, argv);
1000 } 1034 }
1001 #endif 1035 #endif
OLDNEW
« no previous file with comments | « src/d8.h ('k') | test/mjsunit/d8-counter.js » ('j') | test/mjsunit/d8-counter.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698