Reviewers: Christian Plesner Hansen, Description: Fixed the --dump-counters option. The map previously used for counters is now fully removed and the counters collection used for dump counters.
Please review this at http://codereview.chromium.org/13167 SVN Base: http://v8.googlecode.com/svn/branches/bleeding_edge/ Affected files: M src/d8.h M src/d8.cc Index: src/d8.cc =================================================================== --- src/d8.cc (revision 919) +++ src/d8.cc (working copy) @@ -83,7 +83,6 @@ } -Shell::CounterMap Shell::counter_map_; i::OS::MemoryMappedFile* Shell::counters_file_ = NULL; CounterCollection Shell::local_counters_; CounterCollection* Shell::counters_ = &local_counters_; @@ -229,6 +228,17 @@ } +uint32_t CounterCollection::GetNumberOfCounters() { + return counters_in_use_; +} + + +Counter* CounterCollection::GetCounter(uint32_t index) { + if (index >= counters_in_use_) return NULL; + return &counters_[index]; +} + + Counter* CounterCollection::GetNextCounter() { if (counters_in_use_ == kMaxCounters) return NULL; return &counters_[counters_in_use_++]; @@ -250,11 +260,6 @@ int* Shell::LookupCounter(const char* name) { - CounterMap::iterator item = counter_map_.find(name); - if (item != counter_map_.end()) { - Counter* result = (*item).second; - return result->ptr(); - } Counter* result = counters_->GetNextCounter(); if (result == NULL) return NULL; return result->Bind(name); @@ -265,7 +270,7 @@ // Set up counters if (i::FLAG_map_counters != NULL) MapCounters(i::FLAG_map_counters); - if (i::FLAG_dump_counters) + if (i::FLAG_dump_counters && !i::FLAG_map_counters) V8::SetCounterFunction(LookupCounter); // Initialize the global objects HandleScope scope; @@ -324,11 +329,10 @@ ::printf("+----------------------------------------+----------+\n"); ::printf("| Name | Value |\n"); ::printf("+----------------------------------------+----------+\n"); - for (CounterMap::iterator i = counter_map_.begin(); - i != counter_map_.end(); - i++) { - Counter* counter = (*i).second; - ::printf("| %-38s | %8i |\n", (*i).first, counter->value()); + for (uint32_t i = 0; i < counters_->GetNumberOfCounters(); i++) { + + Counter* counter = counters_->GetCounter(i); + ::printf("| %-38s | %8i |\n", counter->name(), counter->value()); } ::printf("+----------------------------------------+----------+\n"); } Index: src/d8.h =================================================================== --- src/d8.h (revision 919) +++ src/d8.h (working copy) @@ -49,6 +49,7 @@ int32_t* Bind(const char* name); int32_t* ptr() { return &counter_; } int32_t value() { return counter_; } + const char* name() { return reinterpret_cast<const char *>(&name_); } private: int32_t counter_; uint8_t name_[kMaxNameSize]; @@ -61,6 +62,8 @@ class CounterCollection { public: CounterCollection(); + uint32_t GetNumberOfCounters(); + Counter* GetCounter(uint32_t index); Counter* GetNextCounter(); private: static const unsigned kMaxCounters = 256; @@ -99,8 +102,6 @@ private: static Persistent<Context> utility_context_; static Persistent<Context> evaluation_context_; - typedef std::map<const char*, Counter*> CounterMap; - static CounterMap counter_map_; // We statically allocate a set of local counters to be used if we // don't want to store the stats in a memory-mapped file static CounterCollection local_counters_; --~--~---------~--~----~------------~-------~--~----~ v8-dev mailing list [email protected] http://groups.google.com/group/v8-dev -~----------~----~----~----~------~----~------~--~---
