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