ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1 | // Copyright 2011 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 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 | #include <stdarg.h> |
| 29 | |
| 30 | #include "v8.h" |
| 31 | |
kasperl@chromium.org | f5aa837 | 2009-03-24 14:47:14 +0000 | [diff] [blame] | 32 | #include "bootstrapper.h" |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 33 | #include "code-stubs.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 34 | #include "deoptimizer.h" |
ager@chromium.org | 01beca7 | 2009-11-24 14:29:16 +0000 | [diff] [blame] | 35 | #include "global-handles.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 36 | #include "log.h" |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 37 | #include "macro-assembler.h" |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 38 | #include "platform.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 39 | #include "runtime-profiler.h" |
kasperl@chromium.org | f5aa837 | 2009-03-24 14:47:14 +0000 | [diff] [blame] | 40 | #include "serialize.h" |
| 41 | #include "string-stream.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 42 | #include "vm-state-inl.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 43 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 44 | namespace v8 { |
| 45 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 46 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 47 | // The Profiler samples pc and sp values for the main thread. |
| 48 | // Each sample is appended to a circular buffer. |
| 49 | // An independent thread removes data and writes it to the log. |
| 50 | // This design minimizes the time spent in the sampler. |
| 51 | // |
| 52 | class Profiler: public Thread { |
| 53 | public: |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 54 | explicit Profiler(Isolate* isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 55 | void Engage(); |
| 56 | void Disengage(); |
| 57 | |
| 58 | // Inserts collected profiling data into buffer. |
| 59 | void Insert(TickSample* sample) { |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 60 | if (paused_) |
| 61 | return; |
| 62 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 63 | if (Succ(head_) == tail_) { |
| 64 | overflow_ = true; |
| 65 | } else { |
| 66 | buffer_[head_] = *sample; |
| 67 | head_ = Succ(head_); |
| 68 | buffer_semaphore_->Signal(); // Tell we have an element. |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | // Waits for a signal and removes profiling data. |
| 73 | bool Remove(TickSample* sample) { |
| 74 | buffer_semaphore_->Wait(); // Wait for an element. |
| 75 | *sample = buffer_[tail_]; |
| 76 | bool result = overflow_; |
| 77 | tail_ = Succ(tail_); |
| 78 | overflow_ = false; |
| 79 | return result; |
| 80 | } |
| 81 | |
| 82 | void Run(); |
| 83 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 84 | // Pause and Resume TickSample data collection. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 85 | bool paused() const { return paused_; } |
| 86 | void pause() { paused_ = true; } |
| 87 | void resume() { paused_ = false; } |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 88 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 89 | private: |
| 90 | // Returns the next index in the cyclic buffer. |
| 91 | int Succ(int index) { return (index + 1) % kBufferSize; } |
| 92 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 93 | Isolate* isolate_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 94 | // Cyclic buffer for communicating profiling samples |
| 95 | // between the signal handler and the worker thread. |
| 96 | static const int kBufferSize = 128; |
| 97 | TickSample buffer_[kBufferSize]; // Buffer storage. |
| 98 | int head_; // Index to the buffer head. |
| 99 | int tail_; // Index to the buffer tail. |
| 100 | bool overflow_; // Tell whether a buffer overflow has occurred. |
| 101 | Semaphore* buffer_semaphore_; // Sempahore used for buffer synchronization. |
| 102 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 103 | // Tells whether profiler is engaged, that is, processing thread is stated. |
| 104 | bool engaged_; |
| 105 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 106 | // Tells whether worker thread should continue running. |
| 107 | bool running_; |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 108 | |
| 109 | // Tells whether we are currently recording tick samples. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 110 | bool paused_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 111 | }; |
| 112 | |
| 113 | |
| 114 | // |
| 115 | // Ticker used to provide ticks to the profiler and the sliding state |
| 116 | // window. |
| 117 | // |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 118 | class Ticker: public Sampler { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 119 | public: |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 120 | Ticker(Isolate* isolate, int interval): |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 121 | Sampler(isolate, interval), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 122 | profiler_(NULL) {} |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 123 | |
| 124 | ~Ticker() { if (IsActive()) Stop(); } |
| 125 | |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 126 | virtual void Tick(TickSample* sample) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 127 | if (profiler_) profiler_->Insert(sample); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | void SetProfiler(Profiler* profiler) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 131 | ASSERT(profiler_ == NULL); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 132 | profiler_ = profiler; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 133 | IncreaseProfilingDepth(); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 134 | if (!FLAG_prof_lazy && !IsActive()) Start(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | void ClearProfiler() { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 138 | DecreaseProfilingDepth(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 139 | profiler_ = NULL; |
jkummerow@chromium.org | 5323a9c | 2012-12-10 19:00:50 +0000 | [diff] [blame] | 140 | if (IsActive()) Stop(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | private: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 144 | Profiler* profiler_; |
| 145 | }; |
| 146 | |
| 147 | |
| 148 | // |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 149 | // Profiler implementation. |
| 150 | // |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 151 | Profiler::Profiler(Isolate* isolate) |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 152 | : Thread("v8:Profiler"), |
| 153 | isolate_(isolate), |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 154 | head_(0), |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 155 | tail_(0), |
| 156 | overflow_(false), |
| 157 | buffer_semaphore_(OS::CreateSemaphore(0)), |
| 158 | engaged_(false), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 159 | running_(false), |
| 160 | paused_(false) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | |
| 164 | void Profiler::Engage() { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 165 | if (engaged_) return; |
| 166 | engaged_ = true; |
| 167 | |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 168 | OS::LogSharedLibraryAddresses(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 169 | |
| 170 | // Start thread processing the profiler buffer. |
| 171 | running_ = true; |
| 172 | Start(); |
| 173 | |
| 174 | // Register to get ticks. |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 175 | Logger* logger = isolate_->logger(); |
| 176 | logger->ticker_->SetProfiler(this); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 177 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 178 | logger->ProfilerBeginEvent(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | |
| 182 | void Profiler::Disengage() { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 183 | if (!engaged_) return; |
| 184 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 185 | // Stop receiving ticks. |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 186 | isolate_->logger()->ticker_->ClearProfiler(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 187 | |
| 188 | // Terminate the worker thread by setting running_ to false, |
| 189 | // inserting a fake element in the queue and then wait for |
| 190 | // the thread to terminate. |
| 191 | running_ = false; |
| 192 | TickSample sample; |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 193 | // Reset 'paused_' flag, otherwise semaphore may not be signalled. |
| 194 | resume(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 195 | Insert(&sample); |
| 196 | Join(); |
| 197 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 198 | LOG(ISOLATE, UncheckedStringEvent("profiler", "end")); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | |
| 202 | void Profiler::Run() { |
| 203 | TickSample sample; |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 204 | bool overflow = Remove(&sample); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 205 | while (running_) { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 206 | LOG(isolate_, TickEvent(&sample, overflow)); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 207 | overflow = Remove(&sample); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 208 | } |
| 209 | } |
| 210 | |
| 211 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 212 | // Low-level profiling event structures. |
| 213 | |
| 214 | struct LowLevelCodeCreateStruct { |
| 215 | static const char kTag = 'C'; |
| 216 | |
| 217 | int32_t name_size; |
| 218 | Address code_address; |
| 219 | int32_t code_size; |
| 220 | }; |
| 221 | |
| 222 | |
| 223 | struct LowLevelCodeMoveStruct { |
| 224 | static const char kTag = 'M'; |
| 225 | |
| 226 | Address from_address; |
| 227 | Address to_address; |
| 228 | }; |
| 229 | |
| 230 | |
| 231 | struct LowLevelCodeDeleteStruct { |
| 232 | static const char kTag = 'D'; |
| 233 | |
| 234 | Address address; |
| 235 | }; |
| 236 | |
| 237 | |
| 238 | struct LowLevelSnapshotPositionStruct { |
| 239 | static const char kTag = 'P'; |
| 240 | |
| 241 | Address address; |
| 242 | int32_t position; |
| 243 | }; |
| 244 | |
| 245 | |
| 246 | static const char kCodeMovingGCTag = 'G'; |
| 247 | |
| 248 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 249 | // |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 250 | // Logger class implementation. |
| 251 | // |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 252 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 253 | class Logger::NameMap { |
| 254 | public: |
| 255 | NameMap() : impl_(&PointerEquals) {} |
| 256 | |
| 257 | ~NameMap() { |
| 258 | for (HashMap::Entry* p = impl_.Start(); p != NULL; p = impl_.Next(p)) { |
| 259 | DeleteArray(static_cast<const char*>(p->value)); |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | void Insert(Address code_address, const char* name, int name_size) { |
| 264 | HashMap::Entry* entry = FindOrCreateEntry(code_address); |
| 265 | if (entry->value == NULL) { |
| 266 | entry->value = CopyName(name, name_size); |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | const char* Lookup(Address code_address) { |
| 271 | HashMap::Entry* entry = FindEntry(code_address); |
| 272 | return (entry != NULL) ? static_cast<const char*>(entry->value) : NULL; |
| 273 | } |
| 274 | |
| 275 | void Remove(Address code_address) { |
| 276 | HashMap::Entry* entry = FindEntry(code_address); |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 277 | if (entry != NULL) { |
| 278 | DeleteArray(static_cast<char*>(entry->value)); |
| 279 | RemoveEntry(entry); |
| 280 | } |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | void Move(Address from, Address to) { |
| 284 | if (from == to) return; |
| 285 | HashMap::Entry* from_entry = FindEntry(from); |
| 286 | ASSERT(from_entry != NULL); |
| 287 | void* value = from_entry->value; |
| 288 | RemoveEntry(from_entry); |
| 289 | HashMap::Entry* to_entry = FindOrCreateEntry(to); |
| 290 | ASSERT(to_entry->value == NULL); |
| 291 | to_entry->value = value; |
| 292 | } |
| 293 | |
| 294 | private: |
| 295 | static bool PointerEquals(void* lhs, void* rhs) { |
| 296 | return lhs == rhs; |
| 297 | } |
| 298 | |
| 299 | static char* CopyName(const char* name, int name_size) { |
| 300 | char* result = NewArray<char>(name_size + 1); |
| 301 | for (int i = 0; i < name_size; ++i) { |
| 302 | char c = name[i]; |
| 303 | if (c == '\0') c = ' '; |
| 304 | result[i] = c; |
| 305 | } |
| 306 | result[name_size] = '\0'; |
| 307 | return result; |
| 308 | } |
| 309 | |
| 310 | HashMap::Entry* FindOrCreateEntry(Address code_address) { |
| 311 | return impl_.Lookup(code_address, ComputePointerHash(code_address), true); |
| 312 | } |
| 313 | |
| 314 | HashMap::Entry* FindEntry(Address code_address) { |
| 315 | return impl_.Lookup(code_address, ComputePointerHash(code_address), false); |
| 316 | } |
| 317 | |
| 318 | void RemoveEntry(HashMap::Entry* entry) { |
| 319 | impl_.Remove(entry->key, entry->hash); |
| 320 | } |
| 321 | |
| 322 | HashMap impl_; |
| 323 | |
| 324 | DISALLOW_COPY_AND_ASSIGN(NameMap); |
| 325 | }; |
| 326 | |
| 327 | |
| 328 | class Logger::NameBuffer { |
| 329 | public: |
| 330 | NameBuffer() { Reset(); } |
| 331 | |
| 332 | void Reset() { |
| 333 | utf8_pos_ = 0; |
| 334 | } |
| 335 | |
| 336 | void AppendString(String* str) { |
| 337 | if (str == NULL) return; |
yangguo@chromium.org | 154ff99 | 2012-03-13 08:09:54 +0000 | [diff] [blame] | 338 | int uc16_length = Min(str->length(), kUtf16BufferSize); |
| 339 | String::WriteToFlat(str, utf16_buffer, 0, uc16_length); |
| 340 | int previous = unibrow::Utf16::kNoPreviousCharacter; |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 341 | for (int i = 0; i < uc16_length && utf8_pos_ < kUtf8BufferSize; ++i) { |
yangguo@chromium.org | 154ff99 | 2012-03-13 08:09:54 +0000 | [diff] [blame] | 342 | uc16 c = utf16_buffer[i]; |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 343 | if (c <= unibrow::Utf8::kMaxOneByteChar) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 344 | utf8_buffer_[utf8_pos_++] = static_cast<char>(c); |
| 345 | } else { |
yangguo@chromium.org | 154ff99 | 2012-03-13 08:09:54 +0000 | [diff] [blame] | 346 | int char_length = unibrow::Utf8::Length(c, previous); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 347 | if (utf8_pos_ + char_length > kUtf8BufferSize) break; |
yangguo@chromium.org | 154ff99 | 2012-03-13 08:09:54 +0000 | [diff] [blame] | 348 | unibrow::Utf8::Encode(utf8_buffer_ + utf8_pos_, c, previous); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 349 | utf8_pos_ += char_length; |
| 350 | } |
yangguo@chromium.org | 154ff99 | 2012-03-13 08:09:54 +0000 | [diff] [blame] | 351 | previous = c; |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 352 | } |
| 353 | } |
| 354 | |
| 355 | void AppendBytes(const char* bytes, int size) { |
| 356 | size = Min(size, kUtf8BufferSize - utf8_pos_); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 357 | OS::MemCopy(utf8_buffer_ + utf8_pos_, bytes, size); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 358 | utf8_pos_ += size; |
| 359 | } |
| 360 | |
| 361 | void AppendBytes(const char* bytes) { |
| 362 | AppendBytes(bytes, StrLength(bytes)); |
| 363 | } |
| 364 | |
| 365 | void AppendByte(char c) { |
| 366 | if (utf8_pos_ >= kUtf8BufferSize) return; |
| 367 | utf8_buffer_[utf8_pos_++] = c; |
| 368 | } |
| 369 | |
| 370 | void AppendInt(int n) { |
| 371 | Vector<char> buffer(utf8_buffer_ + utf8_pos_, kUtf8BufferSize - utf8_pos_); |
| 372 | int size = OS::SNPrintF(buffer, "%d", n); |
| 373 | if (size > 0 && utf8_pos_ + size <= kUtf8BufferSize) { |
| 374 | utf8_pos_ += size; |
| 375 | } |
| 376 | } |
| 377 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 378 | void AppendHex(uint32_t n) { |
| 379 | Vector<char> buffer(utf8_buffer_ + utf8_pos_, kUtf8BufferSize - utf8_pos_); |
| 380 | int size = OS::SNPrintF(buffer, "%x", n); |
| 381 | if (size > 0 && utf8_pos_ + size <= kUtf8BufferSize) { |
| 382 | utf8_pos_ += size; |
| 383 | } |
| 384 | } |
| 385 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 386 | const char* get() { return utf8_buffer_; } |
| 387 | int size() const { return utf8_pos_; } |
| 388 | |
| 389 | private: |
| 390 | static const int kUtf8BufferSize = 512; |
yangguo@chromium.org | 154ff99 | 2012-03-13 08:09:54 +0000 | [diff] [blame] | 391 | static const int kUtf16BufferSize = 128; |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 392 | |
| 393 | int utf8_pos_; |
| 394 | char utf8_buffer_[kUtf8BufferSize]; |
yangguo@chromium.org | 154ff99 | 2012-03-13 08:09:54 +0000 | [diff] [blame] | 395 | uc16 utf16_buffer[kUtf16BufferSize]; |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 396 | }; |
| 397 | |
| 398 | |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 399 | Logger::Logger(Isolate* isolate) |
| 400 | : isolate_(isolate), |
| 401 | ticker_(NULL), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 402 | profiler_(NULL), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 403 | log_events_(NULL), |
| 404 | logging_nesting_(0), |
| 405 | cpu_profiler_nesting_(0), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 406 | log_(new Log(this)), |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 407 | name_buffer_(new NameBuffer), |
| 408 | address_to_name_map_(NULL), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 409 | is_initialized_(false), |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 410 | code_event_handler_(NULL), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 411 | last_address_(NULL), |
| 412 | prev_sp_(NULL), |
| 413 | prev_function_(NULL), |
| 414 | prev_to_(NULL), |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 415 | prev_code_(NULL), |
| 416 | epoch_(0) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 417 | } |
| 418 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 419 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 420 | Logger::~Logger() { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 421 | delete address_to_name_map_; |
| 422 | delete name_buffer_; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 423 | delete log_; |
| 424 | } |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 425 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 426 | |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 427 | void Logger::IssueCodeAddedEvent(Code* code, |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 428 | Script* script, |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 429 | const char* name, |
| 430 | size_t name_len) { |
| 431 | JitCodeEvent event; |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 432 | memset(&event, 0, sizeof(event)); |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 433 | event.type = JitCodeEvent::CODE_ADDED; |
| 434 | event.code_start = code->instruction_start(); |
| 435 | event.code_len = code->instruction_size(); |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 436 | Handle<Script> script_handle = |
| 437 | script != NULL ? Handle<Script>(script) : Handle<Script>(); |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 438 | event.script = ToApiHandle<v8::Script>(script_handle); |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 439 | event.name.str = name; |
| 440 | event.name.len = name_len; |
| 441 | |
| 442 | code_event_handler_(&event); |
| 443 | } |
| 444 | |
| 445 | |
| 446 | void Logger::IssueCodeMovedEvent(Address from, Address to) { |
| 447 | Code* from_code = Code::cast(HeapObject::FromAddress(from)); |
| 448 | |
| 449 | JitCodeEvent event; |
| 450 | event.type = JitCodeEvent::CODE_MOVED; |
| 451 | event.code_start = from_code->instruction_start(); |
| 452 | event.code_len = from_code->instruction_size(); |
| 453 | |
| 454 | // Calculate the header size. |
| 455 | const size_t header_size = |
| 456 | from_code->instruction_start() - reinterpret_cast<byte*>(from_code); |
| 457 | |
| 458 | // Calculate the new start address of the instructions. |
| 459 | event.new_code_start = |
| 460 | reinterpret_cast<byte*>(HeapObject::FromAddress(to)) + header_size; |
| 461 | |
| 462 | code_event_handler_(&event); |
| 463 | } |
| 464 | |
| 465 | |
| 466 | void Logger::IssueCodeRemovedEvent(Address from) { |
| 467 | Code* from_code = Code::cast(HeapObject::FromAddress(from)); |
| 468 | |
| 469 | JitCodeEvent event; |
| 470 | event.type = JitCodeEvent::CODE_REMOVED; |
| 471 | event.code_start = from_code->instruction_start(); |
| 472 | event.code_len = from_code->instruction_size(); |
| 473 | |
| 474 | code_event_handler_(&event); |
| 475 | } |
| 476 | |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 477 | void Logger::IssueAddCodeLinePosInfoEvent( |
| 478 | void* jit_handler_data, |
| 479 | int pc_offset, |
| 480 | int position, |
| 481 | JitCodeEvent::PositionType position_type) { |
| 482 | JitCodeEvent event; |
| 483 | memset(&event, 0, sizeof(event)); |
| 484 | event.type = JitCodeEvent::CODE_ADD_LINE_POS_INFO; |
| 485 | event.user_data = jit_handler_data; |
| 486 | event.line_info.offset = pc_offset; |
| 487 | event.line_info.pos = position; |
| 488 | event.line_info.position_type = position_type; |
| 489 | |
| 490 | code_event_handler_(&event); |
| 491 | } |
| 492 | |
| 493 | void* Logger::IssueStartCodePosInfoEvent() { |
| 494 | JitCodeEvent event; |
| 495 | memset(&event, 0, sizeof(event)); |
| 496 | event.type = JitCodeEvent::CODE_START_LINE_INFO_RECORDING; |
| 497 | |
| 498 | code_event_handler_(&event); |
| 499 | return event.user_data; |
| 500 | } |
| 501 | |
| 502 | void Logger::IssueEndCodePosInfoEvent(Code* code, void* jit_handler_data) { |
| 503 | JitCodeEvent event; |
| 504 | memset(&event, 0, sizeof(event)); |
| 505 | event.type = JitCodeEvent::CODE_END_LINE_INFO_RECORDING; |
| 506 | event.code_start = code->instruction_start(); |
| 507 | event.user_data = jit_handler_data; |
| 508 | |
| 509 | code_event_handler_(&event); |
| 510 | } |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 511 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 512 | #define DECLARE_EVENT(ignore1, name) name, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 513 | static const char* const kLogEventsNames[Logger::NUMBER_OF_LOG_EVENTS] = { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 514 | LOG_EVENTS_AND_TAGS_LIST(DECLARE_EVENT) |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 515 | }; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 516 | #undef DECLARE_EVENT |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 517 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 518 | |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 519 | void Logger::ProfilerBeginEvent() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 520 | if (!log_->IsEnabled()) return; |
| 521 | LogMessageBuilder msg(this); |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 522 | msg.Append("profiler,\"begin\",%d\n", kSamplingIntervalMs); |
| 523 | msg.WriteToLogFile(); |
| 524 | } |
| 525 | |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 526 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 527 | void Logger::StringEvent(const char* name, const char* value) { |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 528 | if (FLAG_log) UncheckedStringEvent(name, value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 532 | void Logger::UncheckedStringEvent(const char* name, const char* value) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 533 | if (!log_->IsEnabled()) return; |
| 534 | LogMessageBuilder msg(this); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 535 | msg.Append("%s,\"%s\"\n", name, value); |
| 536 | msg.WriteToLogFile(); |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 537 | } |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 538 | |
| 539 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 540 | void Logger::IntEvent(const char* name, int value) { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 541 | if (FLAG_log) UncheckedIntEvent(name, value); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 545 | void Logger::IntPtrTEvent(const char* name, intptr_t value) { |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 546 | if (FLAG_log) UncheckedIntPtrTEvent(name, value); |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 547 | } |
| 548 | |
| 549 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 550 | void Logger::UncheckedIntEvent(const char* name, int value) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 551 | if (!log_->IsEnabled()) return; |
| 552 | LogMessageBuilder msg(this); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 553 | msg.Append("%s,%d\n", name, value); |
| 554 | msg.WriteToLogFile(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 555 | } |
| 556 | |
| 557 | |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 558 | void Logger::UncheckedIntPtrTEvent(const char* name, intptr_t value) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 559 | if (!log_->IsEnabled()) return; |
| 560 | LogMessageBuilder msg(this); |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 561 | msg.Append("%s,%" V8_PTR_PREFIX "d\n", name, value); |
| 562 | msg.WriteToLogFile(); |
| 563 | } |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 564 | |
| 565 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 566 | void Logger::HandleEvent(const char* name, Object** location) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 567 | if (!log_->IsEnabled() || !FLAG_log_handles) return; |
| 568 | LogMessageBuilder msg(this); |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 569 | msg.Append("%s,0x%" V8PRIxPTR "\n", name, location); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 570 | msg.WriteToLogFile(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 574 | // ApiEvent is private so all the calls come from the Logger class. It is the |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 575 | // caller's responsibility to ensure that log is enabled and that |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 576 | // FLAG_log_api is true. |
| 577 | void Logger::ApiEvent(const char* format, ...) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 578 | ASSERT(log_->IsEnabled() && FLAG_log_api); |
| 579 | LogMessageBuilder msg(this); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 580 | va_list ap; |
| 581 | va_start(ap, format); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 582 | msg.AppendVA(format, ap); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 583 | va_end(ap); |
| 584 | msg.WriteToLogFile(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 585 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 586 | |
| 587 | |
| 588 | void Logger::ApiNamedSecurityCheck(Object* key) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 589 | if (!log_->IsEnabled() || !FLAG_log_api) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 590 | if (key->IsString()) { |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 591 | SmartArrayPointer<char> str = |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 592 | String::cast(key)->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
| 593 | ApiEvent("api,check-security,\"%s\"\n", *str); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 594 | } else if (key->IsSymbol()) { |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 595 | Symbol* symbol = Symbol::cast(key); |
| 596 | if (symbol->name()->IsUndefined()) { |
| 597 | ApiEvent("api,check-security,symbol(hash %x)\n", |
| 598 | Symbol::cast(key)->Hash()); |
| 599 | } else { |
| 600 | SmartArrayPointer<char> str = String::cast(symbol->name())->ToCString( |
| 601 | DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
| 602 | ApiEvent("api,check-security,symbol(\"%s\" hash %x)\n", |
| 603 | *str, |
| 604 | Symbol::cast(key)->Hash()); |
| 605 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 606 | } else if (key->IsUndefined()) { |
| 607 | ApiEvent("api,check-security,undefined\n"); |
| 608 | } else { |
| 609 | ApiEvent("api,check-security,['no-name']\n"); |
| 610 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | |
| 614 | void Logger::SharedLibraryEvent(const char* library_path, |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 615 | uintptr_t start, |
| 616 | uintptr_t end) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 617 | if (!log_->IsEnabled() || !FLAG_prof) return; |
| 618 | LogMessageBuilder msg(this); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 619 | msg.Append("shared-library,\"%s\",0x%08" V8PRIxPTR ",0x%08" V8PRIxPTR "\n", |
| 620 | library_path, |
| 621 | start, |
| 622 | end); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 623 | msg.WriteToLogFile(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | |
| 627 | void Logger::SharedLibraryEvent(const wchar_t* library_path, |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 628 | uintptr_t start, |
| 629 | uintptr_t end) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 630 | if (!log_->IsEnabled() || !FLAG_prof) return; |
| 631 | LogMessageBuilder msg(this); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 632 | msg.Append("shared-library,\"%ls\",0x%08" V8PRIxPTR ",0x%08" V8PRIxPTR "\n", |
| 633 | library_path, |
| 634 | start, |
| 635 | end); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 636 | msg.WriteToLogFile(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 637 | } |
| 638 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 639 | |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 640 | void Logger::TimerEvent(StartEnd se, const char* name) { |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 641 | if (!log_->IsEnabled()) return; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 642 | ASSERT(FLAG_log_internal_timer_events); |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 643 | LogMessageBuilder msg(this); |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 644 | int since_epoch = static_cast<int>(OS::Ticks() - epoch_); |
| 645 | const char* format = (se == START) ? "timer-event-start,\"%s\",%ld\n" |
| 646 | : "timer-event-end,\"%s\",%ld\n"; |
| 647 | msg.Append(format, name, since_epoch); |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 648 | msg.WriteToLogFile(); |
| 649 | } |
| 650 | |
| 651 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 652 | void Logger::EnterExternal(Isolate* isolate) { |
| 653 | LOG(isolate, TimerEvent(START, TimerEventScope::v8_external)); |
| 654 | ASSERT(isolate->current_vm_state() == JS); |
| 655 | isolate->set_current_vm_state(EXTERNAL); |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 659 | void Logger::LeaveExternal(Isolate* isolate) { |
| 660 | LOG(isolate, TimerEvent(END, TimerEventScope::v8_external)); |
| 661 | ASSERT(isolate->current_vm_state() == EXTERNAL); |
| 662 | isolate->set_current_vm_state(JS); |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 663 | } |
| 664 | |
| 665 | |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 666 | void Logger::TimerEventScope::LogTimerEvent(StartEnd se) { |
| 667 | LOG(isolate_, TimerEvent(se, name_)); |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 671 | const char* Logger::TimerEventScope::v8_recompile_synchronous = |
| 672 | "V8.RecompileSynchronous"; |
| 673 | const char* Logger::TimerEventScope::v8_recompile_parallel = |
| 674 | "V8.RecompileParallel"; |
| 675 | const char* Logger::TimerEventScope::v8_compile_full_code = |
| 676 | "V8.CompileFullCode"; |
| 677 | const char* Logger::TimerEventScope::v8_execute = "V8.Execute"; |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 678 | const char* Logger::TimerEventScope::v8_external = "V8.External"; |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 679 | |
| 680 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 681 | void Logger::LogRegExpSource(Handle<JSRegExp> regexp) { |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 682 | // Prints "/" + re.source + "/" + |
| 683 | // (re.global?"g":"") + (re.ignorecase?"i":"") + (re.multiline?"m":"") |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 684 | LogMessageBuilder msg(this); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 685 | |
| 686 | Handle<Object> source = GetProperty(regexp, "source"); |
| 687 | if (!source->IsString()) { |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 688 | msg.Append("no source"); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 689 | return; |
| 690 | } |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 691 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 692 | switch (regexp->TypeTag()) { |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 693 | case JSRegExp::ATOM: |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 694 | msg.Append('a'); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 695 | break; |
| 696 | default: |
| 697 | break; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 698 | } |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 699 | msg.Append('/'); |
| 700 | msg.AppendDetailed(*Handle<String>::cast(source), false); |
| 701 | msg.Append('/'); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 702 | |
| 703 | // global flag |
| 704 | Handle<Object> global = GetProperty(regexp, "global"); |
| 705 | if (global->IsTrue()) { |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 706 | msg.Append('g'); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 707 | } |
| 708 | // ignorecase flag |
| 709 | Handle<Object> ignorecase = GetProperty(regexp, "ignoreCase"); |
| 710 | if (ignorecase->IsTrue()) { |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 711 | msg.Append('i'); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 712 | } |
| 713 | // multiline flag |
| 714 | Handle<Object> multiline = GetProperty(regexp, "multiline"); |
| 715 | if (multiline->IsTrue()) { |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 716 | msg.Append('m'); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 717 | } |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 718 | |
| 719 | msg.WriteToLogFile(); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 720 | } |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 721 | |
| 722 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 723 | void Logger::RegExpCompileEvent(Handle<JSRegExp> regexp, bool in_cache) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 724 | if (!log_->IsEnabled() || !FLAG_log_regexp) return; |
| 725 | LogMessageBuilder msg(this); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 726 | msg.Append("regexp-compile,"); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 727 | LogRegExpSource(regexp); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 728 | msg.Append(in_cache ? ",hit\n" : ",miss\n"); |
| 729 | msg.WriteToLogFile(); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 733 | void Logger::LogRuntime(Vector<const char> format, |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 734 | JSArray* args) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 735 | if (!log_->IsEnabled() || !FLAG_log_runtime) return; |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 736 | HandleScope scope(isolate_); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 737 | LogMessageBuilder msg(this); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 738 | for (int i = 0; i < format.length(); i++) { |
| 739 | char c = format[i]; |
| 740 | if (c == '%' && i <= format.length() - 2) { |
| 741 | i++; |
| 742 | ASSERT('0' <= format[i] && format[i] <= '9'); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 743 | MaybeObject* maybe = args->GetElement(format[i] - '0'); |
| 744 | Object* obj; |
| 745 | if (!maybe->ToObject(&obj)) { |
| 746 | msg.Append("<exception>"); |
| 747 | continue; |
| 748 | } |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 749 | i++; |
| 750 | switch (format[i]) { |
| 751 | case 's': |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 752 | msg.AppendDetailed(String::cast(obj), false); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 753 | break; |
| 754 | case 'S': |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 755 | msg.AppendDetailed(String::cast(obj), true); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 756 | break; |
| 757 | case 'r': |
| 758 | Logger::LogRegExpSource(Handle<JSRegExp>(JSRegExp::cast(obj))); |
| 759 | break; |
| 760 | case 'x': |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 761 | msg.Append("0x%x", Smi::cast(obj)->value()); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 762 | break; |
| 763 | case 'i': |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 764 | msg.Append("%i", Smi::cast(obj)->value()); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 765 | break; |
| 766 | default: |
| 767 | UNREACHABLE(); |
| 768 | } |
| 769 | } else { |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 770 | msg.Append(c); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 771 | } |
| 772 | } |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 773 | msg.Append('\n'); |
| 774 | msg.WriteToLogFile(); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 775 | } |
| 776 | |
| 777 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 778 | void Logger::ApiIndexedSecurityCheck(uint32_t index) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 779 | if (!log_->IsEnabled() || !FLAG_log_api) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 780 | ApiEvent("api,check-security,%u\n", index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 781 | } |
| 782 | |
| 783 | |
| 784 | void Logger::ApiNamedPropertyAccess(const char* tag, |
| 785 | JSObject* holder, |
| 786 | Object* name) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 787 | ASSERT(name->IsName()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 788 | if (!log_->IsEnabled() || !FLAG_log_api) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 789 | String* class_name_obj = holder->class_name(); |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 790 | SmartArrayPointer<char> class_name = |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 791 | class_name_obj->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 792 | if (name->IsString()) { |
| 793 | SmartArrayPointer<char> property_name = |
| 794 | String::cast(name)->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
| 795 | ApiEvent("api,%s,\"%s\",\"%s\"\n", tag, *class_name, *property_name); |
| 796 | } else { |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 797 | Symbol* symbol = Symbol::cast(name); |
| 798 | uint32_t hash = symbol->Hash(); |
| 799 | if (symbol->name()->IsUndefined()) { |
| 800 | ApiEvent("api,%s,\"%s\",symbol(hash %x)\n", tag, *class_name, hash); |
| 801 | } else { |
| 802 | SmartArrayPointer<char> str = String::cast(symbol->name())->ToCString( |
| 803 | DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
| 804 | ApiEvent("api,%s,\"%s\",symbol(\"%s\" hash %x)\n", |
| 805 | tag, *class_name, *str, hash); |
| 806 | } |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 807 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 808 | } |
| 809 | |
| 810 | void Logger::ApiIndexedPropertyAccess(const char* tag, |
| 811 | JSObject* holder, |
| 812 | uint32_t index) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 813 | if (!log_->IsEnabled() || !FLAG_log_api) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 814 | String* class_name_obj = holder->class_name(); |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 815 | SmartArrayPointer<char> class_name = |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 816 | class_name_obj->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 817 | ApiEvent("api,%s,\"%s\",%u\n", tag, *class_name, index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 818 | } |
| 819 | |
| 820 | void Logger::ApiObjectAccess(const char* tag, JSObject* object) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 821 | if (!log_->IsEnabled() || !FLAG_log_api) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 822 | String* class_name_obj = object->class_name(); |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 823 | SmartArrayPointer<char> class_name = |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 824 | class_name_obj->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 825 | ApiEvent("api,%s,\"%s\"\n", tag, *class_name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 826 | } |
| 827 | |
| 828 | |
| 829 | void Logger::ApiEntryCall(const char* name) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 830 | if (!log_->IsEnabled() || !FLAG_log_api) return; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 831 | ApiEvent("api,%s\n", name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 832 | } |
| 833 | |
| 834 | |
| 835 | void Logger::NewEvent(const char* name, void* object, size_t size) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 836 | if (!log_->IsEnabled() || !FLAG_log) return; |
| 837 | LogMessageBuilder msg(this); |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 838 | msg.Append("new,%s,0x%" V8PRIxPTR ",%u\n", name, object, |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 839 | static_cast<unsigned int>(size)); |
| 840 | msg.WriteToLogFile(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 841 | } |
| 842 | |
| 843 | |
| 844 | void Logger::DeleteEvent(const char* name, void* object) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 845 | if (!log_->IsEnabled() || !FLAG_log) return; |
| 846 | LogMessageBuilder msg(this); |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 847 | msg.Append("delete,%s,0x%" V8PRIxPTR "\n", name, object); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 848 | msg.WriteToLogFile(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 849 | } |
| 850 | |
| 851 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 852 | void Logger::NewEventStatic(const char* name, void* object, size_t size) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 853 | Isolate::Current()->logger()->NewEvent(name, object, size); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 854 | } |
| 855 | |
| 856 | |
| 857 | void Logger::DeleteEventStatic(const char* name, void* object) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 858 | Isolate::Current()->logger()->DeleteEvent(name, object); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 859 | } |
| 860 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 861 | void Logger::CallbackEventInternal(const char* prefix, Name* name, |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 862 | Address entry_point) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 863 | if (!log_->IsEnabled() || !FLAG_log_code) return; |
| 864 | LogMessageBuilder msg(this); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame^] | 865 | msg.Append("%s,%s,-2,", |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 866 | kLogEventsNames[CODE_CREATION_EVENT], |
| 867 | kLogEventsNames[CALLBACK_TAG]); |
ager@chromium.org | 01beca7 | 2009-11-24 14:29:16 +0000 | [diff] [blame] | 868 | msg.AppendAddress(entry_point); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 869 | if (name->IsString()) { |
| 870 | SmartArrayPointer<char> str = |
| 871 | String::cast(name)->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
| 872 | msg.Append(",1,\"%s%s\"", prefix, *str); |
| 873 | } else { |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 874 | Symbol* symbol = Symbol::cast(name); |
| 875 | if (symbol->name()->IsUndefined()) { |
| 876 | msg.Append(",1,symbol(hash %x)", prefix, symbol->Hash()); |
| 877 | } else { |
| 878 | SmartArrayPointer<char> str = String::cast(symbol->name())->ToCString( |
| 879 | DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
| 880 | msg.Append(",1,symbol(\"%s\" hash %x)", prefix, *str, symbol->Hash()); |
| 881 | } |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 882 | } |
ager@chromium.org | 01beca7 | 2009-11-24 14:29:16 +0000 | [diff] [blame] | 883 | msg.Append('\n'); |
| 884 | msg.WriteToLogFile(); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 885 | } |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 886 | |
| 887 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 888 | void Logger::CallbackEvent(Name* name, Address entry_point) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 889 | if (!log_->IsEnabled() || !FLAG_log_code) return; |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 890 | CallbackEventInternal("", name, entry_point); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 891 | } |
| 892 | |
| 893 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 894 | void Logger::GetterCallbackEvent(Name* name, Address entry_point) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 895 | if (!log_->IsEnabled() || !FLAG_log_code) return; |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 896 | CallbackEventInternal("get ", name, entry_point); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 897 | } |
| 898 | |
| 899 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 900 | void Logger::SetterCallbackEvent(Name* name, Address entry_point) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 901 | if (!log_->IsEnabled() || !FLAG_log_code) return; |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 902 | CallbackEventInternal("set ", name, entry_point); |
ager@chromium.org | 01beca7 | 2009-11-24 14:29:16 +0000 | [diff] [blame] | 903 | } |
| 904 | |
| 905 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame^] | 906 | void Logger::AppendName(Name* name) { |
| 907 | if (name->IsString()) { |
| 908 | name_buffer_->AppendString(String::cast(name)); |
| 909 | } else { |
| 910 | Symbol* symbol = Symbol::cast(name); |
| 911 | name_buffer_->AppendBytes("symbol("); |
| 912 | if (!symbol->name()->IsUndefined()) { |
| 913 | name_buffer_->AppendBytes("\""); |
| 914 | name_buffer_->AppendString(String::cast(symbol->name())); |
| 915 | name_buffer_->AppendBytes("\" "); |
| 916 | } |
| 917 | name_buffer_->AppendBytes("hash "); |
| 918 | name_buffer_->AppendHex(symbol->Hash()); |
| 919 | name_buffer_->AppendByte(')'); |
| 920 | } |
| 921 | } |
| 922 | |
| 923 | |
| 924 | void Logger::InitNameBuffer(LogEventsAndTags tag) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 925 | name_buffer_->Reset(); |
| 926 | name_buffer_->AppendBytes(kLogEventsNames[tag]); |
| 927 | name_buffer_->AppendByte(':'); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame^] | 928 | } |
| 929 | |
| 930 | |
| 931 | void Logger::LogRecordedBuffer(Code* code, SharedFunctionInfo* shared) { |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 932 | if (code_event_handler_ != NULL) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame^] | 933 | Script* script = shared && shared->script()->IsScript() ? |
| 934 | Script::cast(shared->script()) : NULL; |
| 935 | IssueCodeAddedEvent(code, |
| 936 | script, |
| 937 | name_buffer_->get(), |
| 938 | name_buffer_->size()); |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 939 | } |
| 940 | if (!log_->IsEnabled()) return; |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 941 | if (FLAG_ll_prof) { |
| 942 | LowLevelCodeCreateEvent(code, name_buffer_->get(), name_buffer_->size()); |
| 943 | } |
| 944 | if (Serializer::enabled()) { |
| 945 | RegisterSnapshotCodeName(code, name_buffer_->get(), name_buffer_->size()); |
| 946 | } |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame^] | 947 | } |
| 948 | |
| 949 | |
| 950 | void Logger::AppendCodeCreateHeader(LogMessageBuilder* msg, |
| 951 | LogEventsAndTags tag, |
| 952 | Code* code) { |
| 953 | ASSERT(msg); |
| 954 | msg->Append("%s,%s,%d,", |
| 955 | kLogEventsNames[CODE_CREATION_EVENT], |
| 956 | kLogEventsNames[tag], |
| 957 | code->kind()); |
| 958 | msg->AppendAddress(code->address()); |
| 959 | msg->Append(",%d,", code->ExecutableSize()); |
| 960 | } |
| 961 | |
| 962 | |
| 963 | void Logger::AppendSymbolName(LogMessageBuilder* msg, |
| 964 | Symbol* symbol) { |
| 965 | ASSERT(symbol); |
| 966 | msg->Append("symbol("); |
| 967 | if (!symbol->name()->IsUndefined()) { |
| 968 | msg->Append("\""); |
| 969 | msg->AppendDetailed(String::cast(symbol->name()), false); |
| 970 | msg->Append("\" "); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 971 | } |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame^] | 972 | msg->Append("hash %x)", symbol->Hash()); |
| 973 | } |
| 974 | |
| 975 | |
| 976 | void Logger::CodeCreateEvent(LogEventsAndTags tag, |
| 977 | Code* code, |
| 978 | const char* comment) { |
| 979 | if (!is_logging_code_events()) return; |
| 980 | if (FLAG_ll_prof || Serializer::enabled() || code_event_handler_ != NULL) { |
| 981 | InitNameBuffer(tag); |
| 982 | name_buffer_->AppendBytes(comment); |
| 983 | LogRecordedBuffer(code, NULL); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 984 | } |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame^] | 985 | |
| 986 | if (!FLAG_log_code || !log_->IsEnabled()) return; |
| 987 | LogMessageBuilder msg(this); |
| 988 | AppendCodeCreateHeader(&msg, tag, code); |
| 989 | msg.AppendDoubleQuotedString(comment); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 990 | msg.Append('\n'); |
| 991 | msg.WriteToLogFile(); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 992 | } |
| 993 | |
| 994 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 995 | void Logger::CodeCreateEvent(LogEventsAndTags tag, |
| 996 | Code* code, |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 997 | Name* name) { |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 998 | if (!is_logging_code_events()) return; |
| 999 | if (FLAG_ll_prof || Serializer::enabled() || code_event_handler_ != NULL) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame^] | 1000 | InitNameBuffer(tag); |
| 1001 | AppendName(name); |
| 1002 | LogRecordedBuffer(code, NULL); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1003 | } |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame^] | 1004 | |
| 1005 | if (!FLAG_log_code || !log_->IsEnabled()) return; |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1006 | LogMessageBuilder msg(this); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame^] | 1007 | AppendCodeCreateHeader(&msg, tag, code); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1008 | if (name->IsString()) { |
| 1009 | msg.Append('"'); |
| 1010 | msg.AppendDetailed(String::cast(name), false); |
| 1011 | msg.Append('"'); |
| 1012 | } else { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame^] | 1013 | AppendSymbolName(&msg, Symbol::cast(name)); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1014 | } |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1015 | msg.Append('\n'); |
| 1016 | msg.WriteToLogFile(); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1017 | } |
| 1018 | |
| 1019 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1020 | // ComputeMarker must only be used when SharedFunctionInfo is known. |
| 1021 | static const char* ComputeMarker(Code* code) { |
| 1022 | switch (code->kind()) { |
| 1023 | case Code::FUNCTION: return code->optimizable() ? "~" : ""; |
| 1024 | case Code::OPTIMIZED_FUNCTION: return "*"; |
| 1025 | default: return ""; |
| 1026 | } |
| 1027 | } |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1028 | |
| 1029 | |
| 1030 | void Logger::CodeCreateEvent(LogEventsAndTags tag, |
| 1031 | Code* code, |
| 1032 | SharedFunctionInfo* shared, |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1033 | CompilationInfo* info, |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1034 | Name* name) { |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 1035 | if (!is_logging_code_events()) return; |
| 1036 | if (FLAG_ll_prof || Serializer::enabled() || code_event_handler_ != NULL) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame^] | 1037 | InitNameBuffer(tag); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1038 | name_buffer_->AppendBytes(ComputeMarker(code)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame^] | 1039 | AppendName(name); |
| 1040 | LogRecordedBuffer(code, shared); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1041 | } |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame^] | 1042 | |
| 1043 | if (!FLAG_log_code || !log_->IsEnabled()) return; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1044 | if (code == Isolate::Current()->builtins()->builtin( |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1045 | Builtins::kLazyCompile)) |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1046 | return; |
| 1047 | |
| 1048 | LogMessageBuilder msg(this); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame^] | 1049 | AppendCodeCreateHeader(&msg, tag, code); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1050 | if (name->IsString()) { |
| 1051 | SmartArrayPointer<char> str = |
| 1052 | String::cast(name)->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
| 1053 | msg.Append("\"%s\"", *str); |
| 1054 | } else { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame^] | 1055 | AppendSymbolName(&msg, Symbol::cast(name)); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1056 | } |
| 1057 | msg.Append(','); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1058 | msg.AppendAddress(shared->address()); |
| 1059 | msg.Append(",%s", ComputeMarker(code)); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 1060 | msg.Append('\n'); |
| 1061 | msg.WriteToLogFile(); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 1062 | } |
| 1063 | |
| 1064 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1065 | // Although, it is possible to extract source and line from |
| 1066 | // the SharedFunctionInfo object, we left it to caller |
| 1067 | // to leave logging functions free from heap allocations. |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 1068 | void Logger::CodeCreateEvent(LogEventsAndTags tag, |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1069 | Code* code, |
| 1070 | SharedFunctionInfo* shared, |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1071 | CompilationInfo* info, |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1072 | Name* source, int line) { |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 1073 | if (!is_logging_code_events()) return; |
| 1074 | if (FLAG_ll_prof || Serializer::enabled() || code_event_handler_ != NULL) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame^] | 1075 | InitNameBuffer(tag); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1076 | name_buffer_->AppendBytes(ComputeMarker(code)); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1077 | name_buffer_->AppendString(shared->DebugName()); |
| 1078 | name_buffer_->AppendByte(' '); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1079 | if (source->IsString()) { |
| 1080 | name_buffer_->AppendString(String::cast(source)); |
| 1081 | } else { |
| 1082 | name_buffer_->AppendBytes("symbol(hash "); |
| 1083 | name_buffer_->AppendHex(Name::cast(source)->Hash()); |
| 1084 | name_buffer_->AppendByte(')'); |
| 1085 | } |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1086 | name_buffer_->AppendByte(':'); |
| 1087 | name_buffer_->AppendInt(line); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame^] | 1088 | LogRecordedBuffer(code, shared); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1089 | } |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame^] | 1090 | |
| 1091 | if (!FLAG_log_code || !log_->IsEnabled()) return; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1092 | LogMessageBuilder msg(this); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame^] | 1093 | AppendCodeCreateHeader(&msg, tag, code); |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 1094 | SmartArrayPointer<char> name = |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1095 | shared->DebugName()->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame^] | 1096 | msg.Append("\"%s ", *name); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1097 | if (source->IsString()) { |
| 1098 | SmartArrayPointer<char> sourcestr = |
| 1099 | String::cast(source)->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
| 1100 | msg.Append("%s", *sourcestr); |
| 1101 | } else { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame^] | 1102 | AppendSymbolName(&msg, Symbol::cast(source)); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1103 | } |
| 1104 | msg.Append(":%d\",", line); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1105 | msg.AppendAddress(shared->address()); |
| 1106 | msg.Append(",%s", ComputeMarker(code)); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 1107 | msg.Append('\n'); |
| 1108 | msg.WriteToLogFile(); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 1109 | } |
| 1110 | |
| 1111 | |
| 1112 | void Logger::CodeCreateEvent(LogEventsAndTags tag, Code* code, int args_count) { |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 1113 | if (!is_logging_code_events()) return; |
| 1114 | if (FLAG_ll_prof || Serializer::enabled() || code_event_handler_ != NULL) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame^] | 1115 | InitNameBuffer(tag); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1116 | name_buffer_->AppendInt(args_count); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame^] | 1117 | LogRecordedBuffer(code, NULL); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1118 | } |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame^] | 1119 | |
| 1120 | if (!FLAG_log_code || !log_->IsEnabled()) return; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1121 | LogMessageBuilder msg(this); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame^] | 1122 | AppendCodeCreateHeader(&msg, tag, code); |
| 1123 | msg.Append("\"args_count: %d\"", args_count); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 1124 | msg.Append('\n'); |
| 1125 | msg.WriteToLogFile(); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 1126 | } |
| 1127 | |
| 1128 | |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 1129 | void Logger::CodeMovingGCEvent() { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1130 | if (!log_->IsEnabled() || !FLAG_ll_prof) return; |
| 1131 | LowLevelLogWriteBytes(&kCodeMovingGCTag, sizeof(kCodeMovingGCTag)); |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 1132 | OS::SignalCodeMovingGC(); |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 1133 | } |
| 1134 | |
| 1135 | |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 1136 | void Logger::RegExpCodeCreateEvent(Code* code, String* source) { |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 1137 | if (!is_logging_code_events()) return; |
| 1138 | if (FLAG_ll_prof || Serializer::enabled() || code_event_handler_ != NULL) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame^] | 1139 | InitNameBuffer(REG_EXP_TAG); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1140 | name_buffer_->AppendString(source); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame^] | 1141 | LogRecordedBuffer(code, NULL); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1142 | } |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame^] | 1143 | |
| 1144 | if (!FLAG_log_code || !log_->IsEnabled()) return; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1145 | LogMessageBuilder msg(this); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame^] | 1146 | AppendCodeCreateHeader(&msg, REG_EXP_TAG, code); |
| 1147 | msg.Append('"'); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 1148 | msg.AppendDetailed(source, false); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame^] | 1149 | msg.Append('"'); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 1150 | msg.Append('\n'); |
| 1151 | msg.WriteToLogFile(); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 1152 | } |
| 1153 | |
| 1154 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1155 | void Logger::CodeMoveEvent(Address from, Address to) { |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 1156 | if (code_event_handler_ != NULL) IssueCodeMovedEvent(from, to); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1157 | if (!log_->IsEnabled()) return; |
| 1158 | if (FLAG_ll_prof) LowLevelCodeMoveEvent(from, to); |
| 1159 | if (Serializer::enabled() && address_to_name_map_ != NULL) { |
| 1160 | address_to_name_map_->Move(from, to); |
| 1161 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1162 | MoveEventInternal(CODE_MOVE_EVENT, from, to); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1163 | } |
| 1164 | |
| 1165 | |
| 1166 | void Logger::CodeDeleteEvent(Address from) { |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 1167 | if (code_event_handler_ != NULL) IssueCodeRemovedEvent(from); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1168 | if (!log_->IsEnabled()) return; |
| 1169 | if (FLAG_ll_prof) LowLevelCodeDeleteEvent(from); |
| 1170 | if (Serializer::enabled() && address_to_name_map_ != NULL) { |
| 1171 | address_to_name_map_->Remove(from); |
| 1172 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1173 | DeleteEventInternal(CODE_DELETE_EVENT, from); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1174 | } |
| 1175 | |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 1176 | void Logger::CodeLinePosInfoAddPositionEvent(void* jit_handler_data, |
| 1177 | int pc_offset, |
| 1178 | int position) { |
| 1179 | if (code_event_handler_ != NULL) { |
| 1180 | IssueAddCodeLinePosInfoEvent(jit_handler_data, |
| 1181 | pc_offset, |
| 1182 | position, |
| 1183 | JitCodeEvent::POSITION); |
| 1184 | } |
| 1185 | } |
| 1186 | |
| 1187 | void Logger::CodeLinePosInfoAddStatementPositionEvent(void* jit_handler_data, |
| 1188 | int pc_offset, |
| 1189 | int position) { |
| 1190 | if (code_event_handler_ != NULL) { |
| 1191 | IssueAddCodeLinePosInfoEvent(jit_handler_data, |
| 1192 | pc_offset, |
| 1193 | position, |
| 1194 | JitCodeEvent::STATEMENT_POSITION); |
| 1195 | } |
| 1196 | } |
| 1197 | |
| 1198 | void Logger::CodeStartLinePosInfoRecordEvent(PositionsRecorder* pos_recorder) { |
| 1199 | if (code_event_handler_ != NULL) { |
| 1200 | pos_recorder->AttachJITHandlerData(IssueStartCodePosInfoEvent()); |
| 1201 | } |
| 1202 | } |
| 1203 | |
| 1204 | void Logger::CodeEndLinePosInfoRecordEvent(Code* code, |
| 1205 | void* jit_handler_data) { |
| 1206 | if (code_event_handler_ != NULL) { |
| 1207 | IssueEndCodePosInfoEvent(code, jit_handler_data); |
| 1208 | } |
| 1209 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1210 | |
| 1211 | void Logger::SnapshotPositionEvent(Address addr, int pos) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1212 | if (!log_->IsEnabled()) return; |
| 1213 | if (FLAG_ll_prof) LowLevelSnapshotPositionEvent(addr, pos); |
| 1214 | if (Serializer::enabled() && address_to_name_map_ != NULL) { |
| 1215 | const char* code_name = address_to_name_map_->Lookup(addr); |
| 1216 | if (code_name == NULL) return; // Not a code object. |
| 1217 | LogMessageBuilder msg(this); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame^] | 1218 | msg.Append("%s,%d,", kLogEventsNames[SNAPSHOT_CODE_NAME_EVENT], pos); |
| 1219 | msg.AppendDoubleQuotedString(code_name); |
| 1220 | msg.Append("\n"); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1221 | msg.WriteToLogFile(); |
| 1222 | } |
| 1223 | if (!FLAG_log_snapshot_positions) return; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1224 | LogMessageBuilder msg(this); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1225 | msg.Append("%s,", kLogEventsNames[SNAPSHOT_POSITION_EVENT]); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1226 | msg.AppendAddress(addr); |
| 1227 | msg.Append(",%d", pos); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1228 | msg.Append('\n'); |
| 1229 | msg.WriteToLogFile(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1230 | } |
| 1231 | |
| 1232 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 1233 | void Logger::SharedFunctionInfoMoveEvent(Address from, Address to) { |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 1234 | MoveEventInternal(SHARED_FUNC_MOVE_EVENT, from, to); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1235 | } |
| 1236 | |
| 1237 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1238 | void Logger::MoveEventInternal(LogEventsAndTags event, |
| 1239 | Address from, |
| 1240 | Address to) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1241 | if (!log_->IsEnabled() || !FLAG_log_code) return; |
| 1242 | LogMessageBuilder msg(this); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1243 | msg.Append("%s,", kLogEventsNames[event]); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1244 | msg.AppendAddress(from); |
| 1245 | msg.Append(','); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1246 | msg.AppendAddress(to); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1247 | msg.Append('\n'); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 1248 | msg.WriteToLogFile(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1249 | } |
| 1250 | |
| 1251 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1252 | void Logger::DeleteEventInternal(LogEventsAndTags event, Address from) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1253 | if (!log_->IsEnabled() || !FLAG_log_code) return; |
| 1254 | LogMessageBuilder msg(this); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1255 | msg.Append("%s,", kLogEventsNames[event]); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1256 | msg.AppendAddress(from); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1257 | msg.Append('\n'); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 1258 | msg.WriteToLogFile(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1259 | } |
| 1260 | |
| 1261 | |
| 1262 | void Logger::ResourceEvent(const char* name, const char* tag) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1263 | if (!log_->IsEnabled() || !FLAG_log) return; |
| 1264 | LogMessageBuilder msg(this); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 1265 | msg.Append("%s,%s,", name, tag); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1266 | |
| 1267 | uint32_t sec, usec; |
| 1268 | if (OS::GetUserTime(&sec, &usec) != -1) { |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 1269 | msg.Append("%d,%d,", sec, usec); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1270 | } |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 1271 | msg.Append("%.0f", OS::TimeCurrentMillis()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1272 | |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 1273 | msg.Append('\n'); |
| 1274 | msg.WriteToLogFile(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1275 | } |
| 1276 | |
| 1277 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1278 | void Logger::SuspectReadEvent(Name* name, Object* obj) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1279 | if (!log_->IsEnabled() || !FLAG_log_suspect) return; |
| 1280 | LogMessageBuilder msg(this); |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 1281 | String* class_name = obj->IsJSObject() |
| 1282 | ? JSObject::cast(obj)->class_name() |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 1283 | : isolate_->heap()->empty_string(); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 1284 | msg.Append("suspect-read,"); |
| 1285 | msg.Append(class_name); |
| 1286 | msg.Append(','); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1287 | if (name->IsString()) { |
| 1288 | msg.Append('"'); |
| 1289 | msg.Append(String::cast(name)); |
| 1290 | msg.Append('"'); |
| 1291 | } else { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame^] | 1292 | AppendSymbolName(&msg, Symbol::cast(name)); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1293 | } |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 1294 | msg.Append('\n'); |
| 1295 | msg.WriteToLogFile(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1296 | } |
| 1297 | |
| 1298 | |
| 1299 | void Logger::HeapSampleBeginEvent(const char* space, const char* kind) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1300 | if (!log_->IsEnabled() || !FLAG_log_gc) return; |
| 1301 | LogMessageBuilder msg(this); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 1302 | // Using non-relative system time in order to be able to synchronize with |
| 1303 | // external memory profiling events (e.g. DOM memory size). |
| 1304 | msg.Append("heap-sample-begin,\"%s\",\"%s\",%.0f\n", |
| 1305 | space, kind, OS::TimeCurrentMillis()); |
| 1306 | msg.WriteToLogFile(); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 1307 | } |
| 1308 | |
| 1309 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1310 | void Logger::HeapSampleEndEvent(const char* space, const char* kind) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1311 | if (!log_->IsEnabled() || !FLAG_log_gc) return; |
| 1312 | LogMessageBuilder msg(this); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 1313 | msg.Append("heap-sample-end,\"%s\",\"%s\"\n", space, kind); |
| 1314 | msg.WriteToLogFile(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1315 | } |
| 1316 | |
| 1317 | |
| 1318 | void Logger::HeapSampleItemEvent(const char* type, int number, int bytes) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1319 | if (!log_->IsEnabled() || !FLAG_log_gc) return; |
| 1320 | LogMessageBuilder msg(this); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 1321 | msg.Append("heap-sample-item,%s,%d,%d\n", type, number, bytes); |
| 1322 | msg.WriteToLogFile(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1323 | } |
| 1324 | |
| 1325 | |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 1326 | void Logger::DebugTag(const char* call_site_tag) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1327 | if (!log_->IsEnabled() || !FLAG_log) return; |
| 1328 | LogMessageBuilder msg(this); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 1329 | msg.Append("debug-tag,%s\n", call_site_tag); |
| 1330 | msg.WriteToLogFile(); |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 1331 | } |
| 1332 | |
| 1333 | |
| 1334 | void Logger::DebugEvent(const char* event_type, Vector<uint16_t> parameter) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1335 | if (!log_->IsEnabled() || !FLAG_log) return; |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 1336 | StringBuilder s(parameter.length() + 1); |
| 1337 | for (int i = 0; i < parameter.length(); ++i) { |
| 1338 | s.AddCharacter(static_cast<char>(parameter[i])); |
| 1339 | } |
| 1340 | char* parameter_string = s.Finalize(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1341 | LogMessageBuilder msg(this); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 1342 | msg.Append("debug-queue-event,%s,%15.3f,%s\n", |
| 1343 | event_type, |
| 1344 | OS::TimeCurrentMillis(), |
| 1345 | parameter_string); |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 1346 | DeleteArray(parameter_string); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 1347 | msg.WriteToLogFile(); |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 1348 | } |
| 1349 | |
| 1350 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1351 | void Logger::TickEvent(TickSample* sample, bool overflow) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1352 | if (!log_->IsEnabled() || !FLAG_prof) return; |
| 1353 | LogMessageBuilder msg(this); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1354 | msg.Append("%s,", kLogEventsNames[TICK_EVENT]); |
| 1355 | msg.AppendAddress(sample->pc); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1356 | msg.Append(','); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1357 | msg.AppendAddress(sample->sp); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1358 | msg.Append(",%ld", static_cast<int>(OS::Ticks() - epoch_)); |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 1359 | if (sample->has_external_callback) { |
| 1360 | msg.Append(",1,"); |
| 1361 | msg.AppendAddress(sample->external_callback); |
| 1362 | } else { |
| 1363 | msg.Append(",0,"); |
| 1364 | msg.AppendAddress(sample->tos); |
| 1365 | } |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1366 | msg.Append(",%d", static_cast<int>(sample->state)); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 1367 | if (overflow) { |
| 1368 | msg.Append(",overflow"); |
| 1369 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1370 | for (int i = 0; i < sample->frames_count; ++i) { |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1371 | msg.Append(','); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1372 | msg.AppendAddress(sample->stack[i]); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 1373 | } |
| 1374 | msg.Append('\n'); |
| 1375 | msg.WriteToLogFile(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1376 | } |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 1377 | |
| 1378 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 1379 | bool Logger::IsProfilerPaused() { |
| 1380 | return profiler_ == NULL || profiler_->paused(); |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 1381 | } |
| 1382 | |
| 1383 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 1384 | void Logger::PauseProfiler() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1385 | if (!log_->IsEnabled()) return; |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 1386 | if (profiler_ != NULL) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1387 | // It is OK to have negative nesting. |
| 1388 | if (--cpu_profiler_nesting_ == 0) { |
| 1389 | profiler_->pause(); |
| 1390 | if (FLAG_prof_lazy) { |
jkummerow@chromium.org | 5323a9c | 2012-12-10 19:00:50 +0000 | [diff] [blame] | 1391 | ticker_->Stop(); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1392 | FLAG_log_code = false; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1393 | LOG(ISOLATE, UncheckedStringEvent("profiler", "pause")); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1394 | } |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1395 | --logging_nesting_; |
sgjesse@chromium.org | b9d7da1 | 2009-08-05 08:38:10 +0000 | [diff] [blame] | 1396 | } |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 1397 | } |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 1398 | } |
| 1399 | |
| 1400 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 1401 | void Logger::ResumeProfiler() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1402 | if (!log_->IsEnabled()) return; |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 1403 | if (profiler_ != NULL) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1404 | if (cpu_profiler_nesting_++ == 0) { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1405 | ++logging_nesting_; |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1406 | if (FLAG_prof_lazy) { |
| 1407 | profiler_->Engage(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1408 | LOG(ISOLATE, UncheckedStringEvent("profiler", "resume")); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1409 | FLAG_log_code = true; |
| 1410 | LogCompiledFunctions(); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1411 | LogAccessorCallbacks(); |
jkummerow@chromium.org | 5323a9c | 2012-12-10 19:00:50 +0000 | [diff] [blame] | 1412 | if (!ticker_->IsActive()) ticker_->Start(); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1413 | } |
| 1414 | profiler_->resume(); |
sgjesse@chromium.org | b9d7da1 | 2009-08-05 08:38:10 +0000 | [diff] [blame] | 1415 | } |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 1416 | } |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 1417 | } |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1418 | |
| 1419 | |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 1420 | // This function can be called when Log's mutex is acquired, |
| 1421 | // either from main or Profiler's thread. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1422 | void Logger::LogFailure() { |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 1423 | PauseProfiler(); |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 1424 | } |
| 1425 | |
| 1426 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1427 | class EnumerateOptimizedFunctionsVisitor: public OptimizedFunctionVisitor { |
| 1428 | public: |
| 1429 | EnumerateOptimizedFunctionsVisitor(Handle<SharedFunctionInfo>* sfis, |
| 1430 | Handle<Code>* code_objects, |
| 1431 | int* count) |
| 1432 | : sfis_(sfis), code_objects_(code_objects), count_(count) { } |
| 1433 | |
| 1434 | virtual void EnterContext(Context* context) {} |
| 1435 | virtual void LeaveContext(Context* context) {} |
| 1436 | |
| 1437 | virtual void VisitFunction(JSFunction* function) { |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1438 | SharedFunctionInfo* sfi = SharedFunctionInfo::cast(function->shared()); |
| 1439 | Object* maybe_script = sfi->script(); |
| 1440 | if (maybe_script->IsScript() |
| 1441 | && !Script::cast(maybe_script)->HasValidSource()) return; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1442 | if (sfis_ != NULL) { |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1443 | sfis_[*count_] = Handle<SharedFunctionInfo>(sfi); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1444 | } |
| 1445 | if (code_objects_ != NULL) { |
| 1446 | ASSERT(function->code()->kind() == Code::OPTIMIZED_FUNCTION); |
| 1447 | code_objects_[*count_] = Handle<Code>(function->code()); |
| 1448 | } |
| 1449 | *count_ = *count_ + 1; |
| 1450 | } |
| 1451 | |
| 1452 | private: |
| 1453 | Handle<SharedFunctionInfo>* sfis_; |
| 1454 | Handle<Code>* code_objects_; |
| 1455 | int* count_; |
| 1456 | }; |
| 1457 | |
| 1458 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1459 | static int EnumerateCompiledFunctions(Heap* heap, |
| 1460 | Handle<SharedFunctionInfo>* sfis, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1461 | Handle<Code>* code_objects) { |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1462 | HeapIterator iterator(heap); |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 1463 | DisallowHeapAllocation no_gc; |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 1464 | int compiled_funcs_count = 0; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1465 | |
| 1466 | // Iterate the heap to find shared function info objects and record |
| 1467 | // the unoptimized code for them. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1468 | for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) { |
sgjesse@chromium.org | 152a0b0 | 2009-10-07 13:50:16 +0000 | [diff] [blame] | 1469 | if (!obj->IsSharedFunctionInfo()) continue; |
| 1470 | SharedFunctionInfo* sfi = SharedFunctionInfo::cast(obj); |
| 1471 | if (sfi->is_compiled() |
| 1472 | && (!sfi->script()->IsScript() |
| 1473 | || Script::cast(sfi->script())->HasValidSource())) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1474 | if (sfis != NULL) { |
sgjesse@chromium.org | 152a0b0 | 2009-10-07 13:50:16 +0000 | [diff] [blame] | 1475 | sfis[compiled_funcs_count] = Handle<SharedFunctionInfo>(sfi); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1476 | } |
| 1477 | if (code_objects != NULL) { |
| 1478 | code_objects[compiled_funcs_count] = Handle<Code>(sfi->code()); |
| 1479 | } |
sgjesse@chromium.org | 152a0b0 | 2009-10-07 13:50:16 +0000 | [diff] [blame] | 1480 | ++compiled_funcs_count; |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 1481 | } |
| 1482 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1483 | |
| 1484 | // Iterate all optimized functions in all contexts. |
| 1485 | EnumerateOptimizedFunctionsVisitor visitor(sfis, |
| 1486 | code_objects, |
| 1487 | &compiled_funcs_count); |
svenpanne@chromium.org | 876cca8 | 2013-03-18 14:43:20 +0000 | [diff] [blame] | 1488 | Deoptimizer::VisitAllOptimizedFunctions(heap->isolate(), &visitor); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1489 | |
sgjesse@chromium.org | 152a0b0 | 2009-10-07 13:50:16 +0000 | [diff] [blame] | 1490 | return compiled_funcs_count; |
| 1491 | } |
| 1492 | |
| 1493 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1494 | void Logger::LogCodeObject(Object* object) { |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 1495 | Code* code_object = Code::cast(object); |
| 1496 | LogEventsAndTags tag = Logger::STUB_TAG; |
| 1497 | const char* description = "Unknown code from the snapshot"; |
| 1498 | switch (code_object->kind()) { |
| 1499 | case Code::FUNCTION: |
| 1500 | case Code::OPTIMIZED_FUNCTION: |
| 1501 | return; // We log this later using LogCompiledFunctions. |
| 1502 | case Code::UNARY_OP_IC: // fall through |
| 1503 | case Code::BINARY_OP_IC: // fall through |
| 1504 | case Code::COMPARE_IC: // fall through |
| 1505 | case Code::COMPARE_NIL_IC: // fall through |
| 1506 | case Code::TO_BOOLEAN_IC: // fall through |
| 1507 | case Code::STUB: |
| 1508 | description = |
| 1509 | CodeStub::MajorName(CodeStub::GetMajorKey(code_object), true); |
| 1510 | if (description == NULL) |
| 1511 | description = "A stub from the snapshot"; |
| 1512 | tag = Logger::STUB_TAG; |
| 1513 | break; |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame^] | 1514 | case Code::REGEXP: |
| 1515 | description = "Regular expression code"; |
| 1516 | tag = Logger::REG_EXP_TAG; |
| 1517 | break; |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 1518 | case Code::BUILTIN: |
| 1519 | description = "A builtin from the snapshot"; |
| 1520 | tag = Logger::BUILTIN_TAG; |
| 1521 | break; |
| 1522 | case Code::KEYED_LOAD_IC: |
| 1523 | description = "A keyed load IC from the snapshot"; |
| 1524 | tag = Logger::KEYED_LOAD_IC_TAG; |
| 1525 | break; |
| 1526 | case Code::LOAD_IC: |
| 1527 | description = "A load IC from the snapshot"; |
| 1528 | tag = Logger::LOAD_IC_TAG; |
| 1529 | break; |
| 1530 | case Code::STORE_IC: |
| 1531 | description = "A store IC from the snapshot"; |
| 1532 | tag = Logger::STORE_IC_TAG; |
| 1533 | break; |
| 1534 | case Code::KEYED_STORE_IC: |
| 1535 | description = "A keyed store IC from the snapshot"; |
| 1536 | tag = Logger::KEYED_STORE_IC_TAG; |
| 1537 | break; |
| 1538 | case Code::CALL_IC: |
| 1539 | description = "A call IC from the snapshot"; |
| 1540 | tag = Logger::CALL_IC_TAG; |
| 1541 | break; |
| 1542 | case Code::KEYED_CALL_IC: |
| 1543 | description = "A keyed call IC from the snapshot"; |
| 1544 | tag = Logger::KEYED_CALL_IC_TAG; |
| 1545 | break; |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame^] | 1546 | case Code::NUMBER_OF_KINDS: |
| 1547 | break; |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1548 | } |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 1549 | PROFILE(isolate_, CodeCreateEvent(tag, code_object, description)); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1550 | } |
| 1551 | |
| 1552 | |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 1553 | void Logger::LogCodeInfo() { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1554 | if (!log_->IsEnabled() || !FLAG_ll_prof) return; |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 1555 | #if V8_TARGET_ARCH_IA32 |
| 1556 | const char arch[] = "ia32"; |
| 1557 | #elif V8_TARGET_ARCH_X64 |
| 1558 | const char arch[] = "x64"; |
| 1559 | #elif V8_TARGET_ARCH_ARM |
| 1560 | const char arch[] = "arm"; |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 1561 | #elif V8_TARGET_ARCH_MIPS |
| 1562 | const char arch[] = "mips"; |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 1563 | #else |
| 1564 | const char arch[] = "unknown"; |
| 1565 | #endif |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1566 | LowLevelLogWriteBytes(arch, sizeof(arch)); |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 1567 | } |
| 1568 | |
| 1569 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1570 | void Logger::RegisterSnapshotCodeName(Code* code, |
| 1571 | const char* name, |
| 1572 | int name_size) { |
| 1573 | ASSERT(Serializer::enabled()); |
| 1574 | if (address_to_name_map_ == NULL) { |
| 1575 | address_to_name_map_ = new NameMap; |
| 1576 | } |
| 1577 | address_to_name_map_->Insert(code->address(), name, name_size); |
| 1578 | } |
| 1579 | |
| 1580 | |
| 1581 | void Logger::LowLevelCodeCreateEvent(Code* code, |
| 1582 | const char* name, |
| 1583 | int name_size) { |
| 1584 | if (log_->ll_output_handle_ == NULL) return; |
| 1585 | LowLevelCodeCreateStruct event; |
| 1586 | event.name_size = name_size; |
| 1587 | event.code_address = code->instruction_start(); |
| 1588 | ASSERT(event.code_address == code->address() + Code::kHeaderSize); |
| 1589 | event.code_size = code->instruction_size(); |
| 1590 | LowLevelLogWriteStruct(event); |
| 1591 | LowLevelLogWriteBytes(name, name_size); |
| 1592 | LowLevelLogWriteBytes( |
| 1593 | reinterpret_cast<const char*>(code->instruction_start()), |
| 1594 | code->instruction_size()); |
| 1595 | } |
| 1596 | |
| 1597 | |
| 1598 | void Logger::LowLevelCodeMoveEvent(Address from, Address to) { |
| 1599 | if (log_->ll_output_handle_ == NULL) return; |
| 1600 | LowLevelCodeMoveStruct event; |
| 1601 | event.from_address = from + Code::kHeaderSize; |
| 1602 | event.to_address = to + Code::kHeaderSize; |
| 1603 | LowLevelLogWriteStruct(event); |
| 1604 | } |
| 1605 | |
| 1606 | |
| 1607 | void Logger::LowLevelCodeDeleteEvent(Address from) { |
| 1608 | if (log_->ll_output_handle_ == NULL) return; |
| 1609 | LowLevelCodeDeleteStruct event; |
| 1610 | event.address = from + Code::kHeaderSize; |
| 1611 | LowLevelLogWriteStruct(event); |
| 1612 | } |
| 1613 | |
| 1614 | |
| 1615 | void Logger::LowLevelSnapshotPositionEvent(Address addr, int pos) { |
| 1616 | if (log_->ll_output_handle_ == NULL) return; |
| 1617 | LowLevelSnapshotPositionStruct event; |
| 1618 | event.address = addr + Code::kHeaderSize; |
| 1619 | event.position = pos; |
| 1620 | LowLevelLogWriteStruct(event); |
| 1621 | } |
| 1622 | |
| 1623 | |
| 1624 | void Logger::LowLevelLogWriteBytes(const char* bytes, int size) { |
| 1625 | size_t rv = fwrite(bytes, 1, size, log_->ll_output_handle_); |
| 1626 | ASSERT(static_cast<size_t>(size) == rv); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1627 | USE(rv); |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 1628 | } |
| 1629 | |
| 1630 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1631 | void Logger::LogCodeObjects() { |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 1632 | Heap* heap = isolate_->heap(); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1633 | heap->CollectAllGarbage(Heap::kMakeHeapIterableMask, |
rossberg@chromium.org | 994edf6 | 2012-02-06 10:12:55 +0000 | [diff] [blame] | 1634 | "Logger::LogCodeObjects"); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1635 | HeapIterator iterator(heap); |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 1636 | DisallowHeapAllocation no_gc; |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1637 | for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) { |
| 1638 | if (obj->IsCode()) LogCodeObject(obj); |
| 1639 | } |
| 1640 | } |
| 1641 | |
| 1642 | |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1643 | void Logger::LogExistingFunction(Handle<SharedFunctionInfo> shared, |
| 1644 | Handle<Code> code) { |
| 1645 | Handle<String> func_name(shared->DebugName()); |
| 1646 | if (shared->script()->IsScript()) { |
| 1647 | Handle<Script> script(Script::cast(shared->script())); |
| 1648 | if (script->name()->IsString()) { |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 1649 | Handle<String> script_name(String::cast(script->name())); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1650 | int line_num = GetScriptLineNumber(script, shared->start_position()); |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 1651 | if (line_num > 0) { |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 1652 | PROFILE(isolate_, |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1653 | CodeCreateEvent( |
| 1654 | Logger::ToNativeByScript(Logger::LAZY_COMPILE_TAG, *script), |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1655 | *code, *shared, NULL, |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1656 | *script_name, line_num + 1)); |
| 1657 | } else { |
| 1658 | // Can't distinguish eval and script here, so always use Script. |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 1659 | PROFILE(isolate_, |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1660 | CodeCreateEvent( |
| 1661 | Logger::ToNativeByScript(Logger::SCRIPT_TAG, *script), |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1662 | *code, *shared, NULL, *script_name)); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1663 | } |
| 1664 | } else { |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 1665 | PROFILE(isolate_, |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1666 | CodeCreateEvent( |
| 1667 | Logger::ToNativeByScript(Logger::LAZY_COMPILE_TAG, *script), |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1668 | *code, *shared, NULL, *func_name)); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1669 | } |
| 1670 | } else if (shared->IsApiFunction()) { |
| 1671 | // API function. |
| 1672 | FunctionTemplateInfo* fun_data = shared->get_api_func_data(); |
| 1673 | Object* raw_call_data = fun_data->call_code(); |
| 1674 | if (!raw_call_data->IsUndefined()) { |
| 1675 | CallHandlerInfo* call_data = CallHandlerInfo::cast(raw_call_data); |
| 1676 | Object* callback_obj = call_data->callback(); |
| 1677 | Address entry_point = v8::ToCData<Address>(callback_obj); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 1678 | PROFILE(isolate_, CallbackEvent(*func_name, entry_point)); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1679 | } |
| 1680 | } else { |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 1681 | PROFILE(isolate_, |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1682 | CodeCreateEvent( |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1683 | Logger::LAZY_COMPILE_TAG, *code, *shared, NULL, *func_name)); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1684 | } |
| 1685 | } |
| 1686 | |
| 1687 | |
sgjesse@chromium.org | 152a0b0 | 2009-10-07 13:50:16 +0000 | [diff] [blame] | 1688 | void Logger::LogCompiledFunctions() { |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 1689 | Heap* heap = isolate_->heap(); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1690 | heap->CollectAllGarbage(Heap::kMakeHeapIterableMask, |
rossberg@chromium.org | 994edf6 | 2012-02-06 10:12:55 +0000 | [diff] [blame] | 1691 | "Logger::LogCompiledFunctions"); |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 1692 | HandleScope scope(isolate_); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1693 | const int compiled_funcs_count = EnumerateCompiledFunctions(heap, NULL, NULL); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1694 | ScopedVector< Handle<SharedFunctionInfo> > sfis(compiled_funcs_count); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1695 | ScopedVector< Handle<Code> > code_objects(compiled_funcs_count); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1696 | EnumerateCompiledFunctions(heap, sfis.start(), code_objects.start()); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 1697 | |
| 1698 | // During iteration, there can be heap allocation due to |
| 1699 | // GetScriptLineNumber call. |
| 1700 | for (int i = 0; i < compiled_funcs_count; ++i) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1701 | if (*code_objects[i] == Isolate::Current()->builtins()->builtin( |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1702 | Builtins::kLazyCompile)) |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1703 | continue; |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1704 | LogExistingFunction(sfis[i], code_objects[i]); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 1705 | } |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 1706 | } |
| 1707 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 1708 | |
| 1709 | void Logger::LogAccessorCallbacks() { |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 1710 | Heap* heap = isolate_->heap(); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1711 | heap->CollectAllGarbage(Heap::kMakeHeapIterableMask, |
rossberg@chromium.org | 994edf6 | 2012-02-06 10:12:55 +0000 | [diff] [blame] | 1712 | "Logger::LogAccessorCallbacks"); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1713 | HeapIterator iterator(heap); |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 1714 | DisallowHeapAllocation no_gc; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1715 | for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) { |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1716 | if (!obj->IsExecutableAccessorInfo()) continue; |
| 1717 | ExecutableAccessorInfo* ai = ExecutableAccessorInfo::cast(obj); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1718 | if (!ai->name()->IsName()) continue; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 1719 | Address getter_entry = v8::ToCData<Address>(ai->getter()); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1720 | Name* name = Name::cast(ai->name()); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 1721 | if (getter_entry != 0) { |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 1722 | PROFILE(isolate_, GetterCallbackEvent(name, getter_entry)); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 1723 | } |
| 1724 | Address setter_entry = v8::ToCData<Address>(ai->setter()); |
| 1725 | if (setter_entry != 0) { |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 1726 | PROFILE(isolate_, SetterCallbackEvent(name, setter_entry)); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 1727 | } |
| 1728 | } |
| 1729 | } |
| 1730 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1731 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 1732 | bool Logger::SetUp(Isolate* isolate) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1733 | // Tests and EnsureInitialize() can call this twice in a row. It's harmless. |
| 1734 | if (is_initialized_) return true; |
| 1735 | is_initialized_ = true; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1736 | |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 1737 | // --ll-prof implies --log-code and --log-snapshot-positions. |
| 1738 | if (FLAG_ll_prof) { |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 1739 | FLAG_log_snapshot_positions = true; |
| 1740 | } |
| 1741 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 1742 | // --prof_lazy controls --log-code, implies --noprof_auto. |
| 1743 | if (FLAG_prof_lazy) { |
| 1744 | FLAG_log_code = false; |
| 1745 | FLAG_prof_auto = false; |
| 1746 | } |
| 1747 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1748 | log_->Initialize(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1749 | |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 1750 | if (FLAG_ll_prof) LogCodeInfo(); |
| 1751 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1752 | ticker_ = new Ticker(isolate, kSamplingIntervalMs); |
| 1753 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 1754 | if (Log::InitLogAtStart()) { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1755 | logging_nesting_ = 1; |
| 1756 | } |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 1757 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1758 | if (FLAG_prof) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1759 | profiler_ = new Profiler(isolate); |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 1760 | if (!FLAG_prof_auto) { |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 1761 | profiler_->pause(); |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 1762 | } else { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1763 | logging_nesting_ = 1; |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 1764 | } |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1765 | if (!FLAG_prof_lazy) { |
| 1766 | profiler_->Engage(); |
| 1767 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1768 | } |
| 1769 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1770 | if (FLAG_log_internal_timer_events || FLAG_prof) epoch_ = OS::Ticks(); |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 1771 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1772 | return true; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1773 | } |
| 1774 | |
| 1775 | |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 1776 | void Logger::SetCodeEventHandler(uint32_t options, |
| 1777 | JitCodeEventHandler event_handler) { |
| 1778 | code_event_handler_ = event_handler; |
| 1779 | |
| 1780 | if (code_event_handler_ != NULL && (options & kJitCodeEventEnumExisting)) { |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 1781 | HandleScope scope(Isolate::Current()); |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 1782 | LogCodeObjects(); |
| 1783 | LogCompiledFunctions(); |
| 1784 | } |
| 1785 | } |
| 1786 | |
| 1787 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1788 | Sampler* Logger::sampler() { |
| 1789 | return ticker_; |
| 1790 | } |
| 1791 | |
| 1792 | |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 1793 | FILE* Logger::TearDown() { |
| 1794 | if (!is_initialized_) return NULL; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1795 | is_initialized_ = false; |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 1796 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1797 | // Stop the profiler before closing the file. |
| 1798 | if (profiler_ != NULL) { |
| 1799 | profiler_->Disengage(); |
| 1800 | delete profiler_; |
| 1801 | profiler_ = NULL; |
| 1802 | } |
| 1803 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1804 | delete ticker_; |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 1805 | ticker_ = NULL; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1806 | |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 1807 | return log_->Close(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1808 | } |
| 1809 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1810 | } } // namespace v8::internal |