fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 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 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 31 | #ifdef ENABLE_LOGGING_AND_PROFILING |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 32 | |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 33 | #include "profile-generator.h" |
| 34 | |
| 35 | namespace v8 { |
| 36 | namespace internal { |
| 37 | |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 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 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 48 | CodeEntry::CodeEntry(int security_token_id) |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 49 | : tag_(Logger::FUNCTION_TAG), |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 50 | name_prefix_(kEmptyNamePrefix), |
| 51 | name_(""), |
| 52 | resource_name_(""), |
| 53 | line_number_(0), |
| 54 | security_token_id_(security_token_id) { |
| 55 | } |
| 56 | |
| 57 | |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 58 | CodeEntry::CodeEntry(Logger::LogEventsAndTags tag, |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 59 | const char* name_prefix, |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 60 | const char* name, |
| 61 | const char* resource_name, |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 62 | int line_number, |
| 63 | int security_token_id) |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 64 | : tag_(tag), |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 65 | name_prefix_(name_prefix), |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 66 | name_(name), |
| 67 | resource_name_(resource_name), |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 68 | line_number_(line_number), |
| 69 | security_token_id_(security_token_id) { |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 73 | bool CodeEntry::is_js_function_tag(Logger::LogEventsAndTags tag) { |
| 74 | return tag == Logger::FUNCTION_TAG |
| 75 | || tag == Logger::LAZY_COMPILE_TAG |
| 76 | || tag == Logger::SCRIPT_TAG |
| 77 | || tag == Logger::NATIVE_FUNCTION_TAG |
| 78 | || tag == Logger::NATIVE_LAZY_COMPILE_TAG |
| 79 | || tag == Logger::NATIVE_SCRIPT_TAG; |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 83 | ProfileNode::ProfileNode(ProfileTree* tree, CodeEntry* entry) |
| 84 | : tree_(tree), |
| 85 | entry_(entry), |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 86 | total_ticks_(0), |
| 87 | self_ticks_(0), |
| 88 | children_(CodeEntriesMatch) { |
| 89 | } |
| 90 | |
| 91 | |
| 92 | void CodeMap::AddCode(Address addr, CodeEntry* entry, unsigned size) { |
| 93 | CodeTree::Locator locator; |
| 94 | tree_.Insert(addr, &locator); |
| 95 | locator.set_value(CodeEntryInfo(entry, size)); |
| 96 | } |
| 97 | |
| 98 | |
| 99 | void CodeMap::MoveCode(Address from, Address to) { |
| 100 | tree_.Move(from, to); |
| 101 | } |
| 102 | |
| 103 | void CodeMap::DeleteCode(Address addr) { |
| 104 | tree_.Remove(addr); |
| 105 | } |
| 106 | |
| 107 | |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 108 | template<class Visitor> |
| 109 | void HeapEntriesMap::UpdateEntries(Visitor* visitor) { |
| 110 | for (HashMap::Entry* p = entries_.Start(); |
| 111 | p != NULL; |
| 112 | p = entries_.Next(p)) { |
| 113 | if (!IsAlias(p->value)) { |
| 114 | EntryInfo* entry_info = reinterpret_cast<EntryInfo*>(p->value); |
| 115 | entry_info->entry = visitor->GetEntry( |
| 116 | reinterpret_cast<HeapObject*>(p->key), |
| 117 | entry_info->children_count, |
| 118 | entry_info->retainers_count); |
| 119 | entry_info->children_count = 0; |
| 120 | entry_info->retainers_count = 0; |
| 121 | } |
| 122 | } |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | |
| 126 | CodeEntry* ProfileGenerator::EntryForVMState(StateTag tag) { |
| 127 | switch (tag) { |
| 128 | case GC: |
| 129 | return gc_entry_; |
| 130 | case JS: |
| 131 | case COMPILER: |
| 132 | // DOM events handlers are reported as OTHER / EXTERNAL entries. |
| 133 | // To avoid confusing people, let's put all these entries into |
| 134 | // one bucket. |
| 135 | case OTHER: |
| 136 | case EXTERNAL: |
| 137 | return program_entry_; |
| 138 | default: return NULL; |
| 139 | } |
| 140 | } |
| 141 | |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 142 | } } // namespace v8::internal |
| 143 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 144 | #endif // ENABLE_LOGGING_AND_PROFILING |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 145 | |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 146 | #endif // V8_PROFILE_GENERATOR_INL_H_ |