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

Unified 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, 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 side-by-side diff with in-line comments
Download patch
Index: src/d8.cc
diff --git a/src/d8.cc b/src/d8.cc
index 7655aad4b53dfefc4f19bc3fb15d7cea965dd098..51352ab4530fe34faa3aa51f03492f7514162e86 100644
--- a/src/d8.cc
+++ b/src/d8.cc
@@ -599,10 +599,46 @@ Handle<ObjectTemplate> Shell::CreateGlobalTemplate() {
AddOSMethods(os_templ);
global_template->Set(String::New("os"), os_templ);
Yang 2011/06/29 12:02:20 Add new object "counter".
+ Handle<ObjectTemplate> counter_templ = ObjectTemplate::New();
+ counter_templ->Set(String::New("get"),
+ FunctionTemplate::New(GetCounterValue));
+ counter_templ->Set(String::New("names"),
+ FunctionTemplate::New(GetCounterNames));
+ global_template->Set(String::New("counter"), counter_templ);
+
return global_template;
}
Yang 2011/06/29 12:02:20 counter.get() returns the counter by the name prov
+Handle<Value> Shell::GetCounterValue(const Arguments& args) {
+ if (args.Length() != 1) {
+ return ThrowException(String::New("get() takes one argument"));
+ }
+ if (args[0]->IsString()) {
+ String::AsciiValue name(args[0]);
+ Counter* counter = counter_map_->Lookup(*name);
+ if (!counter) {
+ return ThrowException(String::New("invalid counter name"));
+ }
+ return Handle<Integer>::Cast(Integer::New(counter->count()));
+ }
+ return ThrowException(String::New("counter name must be a string"));
+}
+
+
Yang 2011/06/29 12:02:20 counter.names() returns counter names as an array
+Handle<Value> Shell::GetCounterNames(const Arguments& args) {
+ if (args.Length() != 0) {
+ return ThrowException(String::New("names() takes no arguments"));
+ }
+ Handle<Array> results = Handle<Array>::Cast(Array::New(0));
+ int j = 0;
+ for (CounterMap::Iterator i(counter_map_); i.More(); i.Next()) {
+ results->Set(j++, Handle<String>::Cast(String::New(i.CurrentKey())));
+ }
+ return results;
+}
+
+
void Shell::Initialize(bool test_shell) {
#ifdef COMPRESS_STARTUP_DATA_BZ2
BZip2Decompressor startup_data_decompressor;
@@ -617,11 +653,9 @@ void Shell::Initialize(bool test_shell) {
// Set up counters
if (i::StrLength(i::FLAG_map_counters) != 0)
MapCounters(i::FLAG_map_counters);
Yang 2011/06/29 12:02:20 Init counter in any case (not only upon --dump-cou
- if (i::FLAG_dump_counters) {
- V8::SetCounterFunction(LookupCounter);
- V8::SetCreateHistogramFunction(CreateHistogram);
- V8::SetAddHistogramSampleFunction(AddHistogramSample);
- }
+ V8::SetCounterFunction(LookupCounter);
+ V8::SetCreateHistogramFunction(CreateHistogram);
+ V8::SetAddHistogramSampleFunction(AddHistogramSample);
if (test_shell) return;
« 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