Home | History | Annotate | Download | only in src
      1 // Copyright 2010 the V8 project authors. All rights reserved.
      2 // Redistribution and use in source and binary forms, with or without
      3 // modification, are permitted provided that the following conditions are
      4 // met:
      5 //
      6 //     * Redistributions of source code must retain the above copyright
      7 //       notice, this list of conditions and the following disclaimer.
      8 //     * Redistributions in binary form must reproduce the above
      9 //       copyright notice, this list of conditions and the following
     10 //       disclaimer in the documentation and/or other materials provided
     11 //       with the distribution.
     12 //     * Neither the name of Google Inc. nor the names of its
     13 //       contributors may be used to endorse or promote products derived
     14 //       from this software without specific prior written permission.
     15 //
     16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27 
     28 #ifndef V8_PROFILE_GENERATOR_INL_H_
     29 #define V8_PROFILE_GENERATOR_INL_H_
     30 
     31 #include "profile-generator.h"
     32 
     33 namespace v8 {
     34 namespace internal {
     35 
     36 const char* StringsStorage::GetFunctionName(Name* name) {
     37   return GetFunctionName(GetName(name));
     38 }
     39 
     40 
     41 const char* StringsStorage::GetFunctionName(const char* name) {
     42   return strlen(name) > 0 ? name : ProfileGenerator::kAnonymousFunctionName;
     43 }
     44 
     45 
     46 CodeEntry::CodeEntry(Logger::LogEventsAndTags tag,
     47                      const char* name,
     48                      const char* name_prefix,
     49                      const char* resource_name,
     50                      int line_number)
     51     : tag_(tag),
     52       builtin_id_(Builtins::builtin_count),
     53       name_prefix_(name_prefix),
     54       name_(name),
     55       resource_name_(resource_name),
     56       line_number_(line_number),
     57       shared_id_(0),
     58       script_id_(v8::Script::kNoScriptId),
     59       no_frame_ranges_(NULL) {
     60 }
     61 
     62 
     63 bool CodeEntry::is_js_function_tag(Logger::LogEventsAndTags tag) {
     64   return tag == Logger::FUNCTION_TAG
     65       || tag == Logger::LAZY_COMPILE_TAG
     66       || tag == Logger::SCRIPT_TAG
     67       || tag == Logger::NATIVE_FUNCTION_TAG
     68       || tag == Logger::NATIVE_LAZY_COMPILE_TAG
     69       || tag == Logger::NATIVE_SCRIPT_TAG;
     70 }
     71 
     72 
     73 ProfileNode::ProfileNode(ProfileTree* tree, CodeEntry* entry)
     74     : tree_(tree),
     75       entry_(entry),
     76       total_ticks_(0),
     77       self_ticks_(0),
     78       children_(CodeEntriesMatch),
     79       id_(tree->next_node_id()) {
     80 }
     81 
     82 
     83 CodeEntry* ProfileGenerator::EntryForVMState(StateTag tag) {
     84   switch (tag) {
     85     case GC:
     86       return gc_entry_;
     87     case JS:
     88     case COMPILER:
     89     // DOM events handlers are reported as OTHER / EXTERNAL entries.
     90     // To avoid confusing people, let's put all these entries into
     91     // one bucket.
     92     case OTHER:
     93     case EXTERNAL:
     94       return program_entry_;
     95     case IDLE:
     96       return idle_entry_;
     97     default: return NULL;
     98   }
     99 }
    100 
    101 } }  // namespace v8::internal
    102 
    103 #endif  // V8_PROFILE_GENERATOR_INL_H_
    104