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 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 108 | CodeEntry* ProfileGenerator::EntryForVMState(StateTag tag) { |
| 109 | switch (tag) { |
| 110 | case GC: |
| 111 | return gc_entry_; |
| 112 | case JS: |
| 113 | case COMPILER: |
| 114 | // DOM events handlers are reported as OTHER / EXTERNAL entries. |
| 115 | // To avoid confusing people, let's put all these entries into |
| 116 | // one bucket. |
| 117 | case OTHER: |
| 118 | case EXTERNAL: |
| 119 | return program_entry_; |
| 120 | default: return NULL; |
| 121 | } |
| 122 | } |
| 123 | |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 124 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 125 | uint64_t HeapEntry::id() { |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 126 | union { |
| 127 | Id stored_id; |
| 128 | uint64_t returned_id; |
| 129 | } id_adaptor = {id_}; |
| 130 | return id_adaptor.returned_id; |
| 131 | } |
| 132 | |
| 133 | |
| 134 | template<class Visitor> |
| 135 | void HeapEntriesMap::UpdateEntries(Visitor* visitor) { |
| 136 | for (HashMap::Entry* p = entries_.Start(); |
| 137 | p != NULL; |
| 138 | p = entries_.Next(p)) { |
| 139 | EntryInfo* entry_info = reinterpret_cast<EntryInfo*>(p->value); |
| 140 | entry_info->entry = visitor->GetEntry( |
| 141 | reinterpret_cast<HeapObject*>(p->key), |
| 142 | entry_info->children_count, |
| 143 | entry_info->retainers_count); |
| 144 | entry_info->children_count = 0; |
| 145 | entry_info->retainers_count = 0; |
| 146 | } |
| 147 | } |
| 148 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 149 | |
| 150 | bool HeapSnapshotGenerator::ReportProgress(bool force) { |
| 151 | const int kProgressReportGranularity = 10000; |
| 152 | if (control_ != NULL |
| 153 | && (force || progress_counter_ % kProgressReportGranularity == 0)) { |
| 154 | return |
| 155 | control_->ReportProgressValue(progress_counter_, progress_total_) == |
| 156 | v8::ActivityControl::kContinue; |
| 157 | } |
| 158 | return true; |
| 159 | } |
| 160 | |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 161 | } } // namespace v8::internal |
| 162 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 163 | #endif // ENABLE_LOGGING_AND_PROFILING |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 164 | |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 165 | #endif // V8_PROFILE_GENERATOR_INL_H_ |