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 #ifdef ENABLE_LOGGING_AND_PROFILING
     32 
     33 #include "profile-generator.h"
     34 
     35 namespace v8 {
     36 namespace internal {
     37 
     38 const char* StringsStorage::GetFunctionName(String* name) {
     39   return GetFunctionName(GetName(name));
     40 }
     41 
     42 
     43 const char* StringsStorage::GetFunctionName(const char* name) {
     44   return strlen(name) > 0 ? name : ProfileGenerator::kAnonymousFunctionName;
     45 }
     46 
     47 
     48 CodeEntry::CodeEntry(Logger::LogEventsAndTags tag,
     49                      const char* name_prefix,
     50                      const char* name,
     51                      const char* resource_name,
     52                      int line_number,
     53                      int security_token_id)
     54     : tag_(tag),
     55       name_prefix_(name_prefix),
     56       name_(name),
     57       resource_name_(resource_name),
     58       line_number_(line_number),
     59       shared_id_(0),
     60       security_token_id_(security_token_id) {
     61 }
     62 
     63 
     64 bool CodeEntry::is_js_function_tag(Logger::LogEventsAndTags tag) {
     65   return tag == Logger::FUNCTION_TAG
     66       || tag == Logger::LAZY_COMPILE_TAG
     67       || tag == Logger::SCRIPT_TAG
     68       || tag == Logger::NATIVE_FUNCTION_TAG
     69       || tag == Logger::NATIVE_LAZY_COMPILE_TAG
     70       || tag == Logger::NATIVE_SCRIPT_TAG;
     71 }
     72 
     73 
     74 ProfileNode::ProfileNode(ProfileTree* tree, CodeEntry* entry)
     75     : tree_(tree),
     76       entry_(entry),
     77       total_ticks_(0),
     78       self_ticks_(0),
     79       children_(CodeEntriesMatch) {
     80 }
     81 
     82 
     83 void CodeMap::AddCode(Address addr, CodeEntry* entry, unsigned size) {
     84   CodeTree::Locator locator;
     85   tree_.Insert(addr, &locator);
     86   locator.set_value(CodeEntryInfo(entry, size));
     87 }
     88 
     89 
     90 void CodeMap::MoveCode(Address from, Address to) {
     91   tree_.Move(from, to);
     92 }
     93 
     94 void CodeMap::DeleteCode(Address addr) {
     95   tree_.Remove(addr);
     96 }
     97 
     98 
     99 CodeEntry* ProfileGenerator::EntryForVMState(StateTag tag) {
    100   switch (tag) {
    101     case GC:
    102       return gc_entry_;
    103     case JS:
    104     case COMPILER:
    105     // DOM events handlers are reported as OTHER / EXTERNAL entries.
    106     // To avoid confusing people, let's put all these entries into
    107     // one bucket.
    108     case OTHER:
    109     case EXTERNAL:
    110       return program_entry_;
    111     default: return NULL;
    112   }
    113 }
    114 
    115 
    116 uint64_t HeapEntry::id() {
    117   union {
    118     Id stored_id;
    119     uint64_t returned_id;
    120   } id_adaptor = {id_};
    121   return id_adaptor.returned_id;
    122 }
    123 
    124 } }  // namespace v8::internal
    125 
    126 #endif  // ENABLE_LOGGING_AND_PROFILING
    127 
    128 #endif  // V8_PROFILE_GENERATOR_INL_H_
    129