| OLD | NEW | 
|    1 // Copyright 2012 the V8 project authors. All rights reserved. |    1 // Copyright 2012 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 23 matching lines...) Expand all  Loading... | 
|   34     "native function getV8Statistics();"; |   34     "native function getV8Statistics();"; | 
|   35  |   35  | 
|   36  |   36  | 
|   37 v8::Handle<v8::FunctionTemplate> StatisticsExtension::GetNativeFunction( |   37 v8::Handle<v8::FunctionTemplate> StatisticsExtension::GetNativeFunction( | 
|   38     v8::Handle<v8::String> str) { |   38     v8::Handle<v8::String> str) { | 
|   39   ASSERT(strcmp(*v8::String::AsciiValue(str), "getV8Statistics") == 0); |   39   ASSERT(strcmp(*v8::String::AsciiValue(str), "getV8Statistics") == 0); | 
|   40   return v8::FunctionTemplate::New(StatisticsExtension::GetCounters); |   40   return v8::FunctionTemplate::New(StatisticsExtension::GetCounters); | 
|   41 } |   41 } | 
|   42  |   42  | 
|   43  |   43  | 
 |   44 static void AddProperty(v8::Local<v8::Object> object, | 
 |   45                         StatsCounter* counter, | 
 |   46                         const char* name) { | 
 |   47   if (counter->Enabled()) { | 
 |   48     object->Set(v8::String::New(name), | 
 |   49                 v8::Number::New(*counter->GetInternalPointer())); | 
 |   50   } | 
 |   51 } | 
 |   52  | 
 |   53  | 
|   44 v8::Handle<v8::Value> StatisticsExtension::GetCounters( |   54 v8::Handle<v8::Value> StatisticsExtension::GetCounters( | 
|   45     const v8::Arguments& args) { |   55     const v8::Arguments& args) { | 
|   46   Isolate* isolate = Isolate::Current(); |   56   Isolate* isolate = Isolate::Current(); | 
|   47   Heap* heap = isolate->heap(); |   57   Heap* heap = isolate->heap(); | 
 |   58  | 
|   48   if (args.Length() > 0) {  // GC if first argument evaluates to true. |   59   if (args.Length() > 0) {  // GC if first argument evaluates to true. | 
|   49     if (args[0]->IsBoolean() && args[0]->ToBoolean()->Value()) { |   60     if (args[0]->IsBoolean() && args[0]->ToBoolean()->Value()) { | 
|   50       heap->CollectAllGarbage(Heap::kNoGCFlags, "counters extension"); |   61       heap->CollectAllGarbage(Heap::kNoGCFlags, "counters extension"); | 
|   51     } |   62     } | 
|   52   } |   63   } | 
|   53  |   64  | 
|   54   Counters* counters = isolate->counters(); |   65   Counters* counters = isolate->counters(); | 
|   55   v8::Local<v8::Object> result = v8::Object::New(); |   66   v8::Local<v8::Object> result = v8::Object::New(); | 
|   56  |   67  | 
|   57   StatsCounter* counter = NULL; |  | 
|   58  |  | 
|   59 #define ADD_COUNTER(name, caption)                                             \ |   68 #define ADD_COUNTER(name, caption)                                             \ | 
|   60   counter = counters->name();                                                  \ |   69   AddProperty(result, counters->name(), #name); | 
|   61   if (counter->Enabled())                                                      \ |  | 
|   62     result->Set(v8::String::New(#name),                                        \ |  | 
|   63         v8::Number::New(*counter->GetInternalPointer())); |  | 
|   64  |   70  | 
|   65   STATS_COUNTER_LIST_1(ADD_COUNTER) |   71   STATS_COUNTER_LIST_1(ADD_COUNTER) | 
|   66   STATS_COUNTER_LIST_2(ADD_COUNTER) |   72   STATS_COUNTER_LIST_2(ADD_COUNTER) | 
|   67 #undef ADD_COUNTER |   73 #undef ADD_COUNTER | 
|   68 #define ADD_COUNTER(name)                                                      \ |   74 #define ADD_COUNTER(name)                                                      \ | 
|   69   counter = counters->count_of_##name();                                       \ |   75   AddProperty(result, counters->count_of_##name(), "count_of_" #name);         \ | 
|   70   if (counter->Enabled())                                                      \ |   76   AddProperty(result, counters->size_of_##name(),  "size_of_" #name); | 
|   71     result->Set(v8::String::New("count_of_" #name),                            \ |  | 
|   72         v8::Number::New(*counter->GetInternalPointer()));                      \ |  | 
|   73   counter = counters->size_of_##name();                                        \ |  | 
|   74   if (counter->Enabled())                                                      \ |  | 
|   75     result->Set(v8::String::New("size_of_" #name),                             \ |  | 
|   76         v8::Number::New(*counter->GetInternalPointer())); |  | 
|   77  |   77  | 
|   78   INSTANCE_TYPE_LIST(ADD_COUNTER) |   78   INSTANCE_TYPE_LIST(ADD_COUNTER) | 
|   79 #undef ADD_COUNTER |   79 #undef ADD_COUNTER | 
|   80 #define ADD_COUNTER(name)                                                      \ |   80 #define ADD_COUNTER(name)                                                      \ | 
|   81   result->Set(v8::String::New("count_of_CODE_TYPE_" #name),                    \ |   81   AddProperty(result, counters->count_of_CODE_TYPE_##name(),                   \ | 
|   82       v8::Number::New(                                                         \ |   82               "count_of_CODE_TYPE_" #name);                                    \ | 
|   83           *counters->count_of_CODE_TYPE_##name()->GetInternalPointer()));      \ |   83   AddProperty(result, counters->size_of_CODE_TYPE_##name(),                    \ | 
|   84   result->Set(v8::String::New("size_of_CODE_TYPE_" #name),                     \ |   84               "size_of_CODE_TYPE_" #name); | 
|   85         v8::Number::New(                                                       \ |  | 
|   86             *counters->size_of_CODE_TYPE_##name()->GetInternalPointer())); |  | 
|   87  |   85  | 
|   88   CODE_KIND_LIST(ADD_COUNTER) |   86   CODE_KIND_LIST(ADD_COUNTER) | 
|   89 #undef ADD_COUNTER |   87 #undef ADD_COUNTER | 
|   90 #define ADD_COUNTER(name)                                                      \ |   88 #define ADD_COUNTER(name)                                                      \ | 
|   91   result->Set(v8::String::New("count_of_FIXED_ARRAY_" #name),                  \ |   89   AddProperty(result, counters->count_of_FIXED_ARRAY_##name(),                 \ | 
|   92       v8::Number::New(                                                         \ |   90               "count_of_FIXED_ARRAY_" #name);                                  \ | 
|   93           *counters->count_of_FIXED_ARRAY_##name()->GetInternalPointer()));    \ |   91   AddProperty(result, counters->size_of_FIXED_ARRAY_##name(),                  \ | 
|   94   result->Set(v8::String::New("size_of_FIXED_ARRAY_" #name),                   \ |   92               "size_of_FIXED_ARRAY_" #name); | 
|   95         v8::Number::New(                                                       \ |  | 
|   96             *counters->size_of_FIXED_ARRAY_##name()->GetInternalPointer())); |  | 
|   97  |   93  | 
|   98   FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(ADD_COUNTER) |   94   FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(ADD_COUNTER) | 
|   99 #undef ADD_COUNTER |   95 #undef ADD_COUNTER | 
|  100  |   96  | 
|  101   return result; |   97   return result; | 
|  102 } |   98 } | 
|  103  |   99  | 
|  104  |  100  | 
|  105 void StatisticsExtension::Register() { |  101 void StatisticsExtension::Register() { | 
|  106   static StatisticsExtension statistics_extension; |  102   static StatisticsExtension statistics_extension; | 
|  107   static v8::DeclareExtension declaration(&statistics_extension); |  103   static v8::DeclareExtension declaration(&statistics_extension); | 
|  108 } |  104 } | 
|  109  |  105  | 
|  110 } }  // namespace v8::internal |  106 } }  // namespace v8::internal | 
| OLD | NEW |