Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(175)

Side by Side Diff: src/log.cc

Issue 19724007: Logger: introduce abstract interface for CodeEvent listeners. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« src/log.h ('K') | « src/log.h ('k') | src/serialize.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 namespace internal { 47 namespace internal {
48 48
49 49
50 #define DECLARE_EVENT(ignore1, name) name, 50 #define DECLARE_EVENT(ignore1, name) name,
51 static const char* const kLogEventsNames[Logger::NUMBER_OF_LOG_EVENTS] = { 51 static const char* const kLogEventsNames[Logger::NUMBER_OF_LOG_EVENTS] = {
52 LOG_EVENTS_AND_TAGS_LIST(DECLARE_EVENT) 52 LOG_EVENTS_AND_TAGS_LIST(DECLARE_EVENT)
53 }; 53 };
54 #undef DECLARE_EVENT 54 #undef DECLARE_EVENT
55 55
56 56
57 #define CALL_LOGGERS(Call) \
58 for (int i = 0; i < loggers_.length(); ++i) { \
59 loggers_[i]->Call; \
60 }
61
57 #define PROFILER_LOG(Call) \ 62 #define PROFILER_LOG(Call) \
58 do { \ 63 do { \
59 CpuProfiler* cpu_profiler = isolate_->cpu_profiler(); \ 64 CpuProfiler* cpu_profiler = isolate_->cpu_profiler(); \
60 if (cpu_profiler->is_profiling()) { \ 65 if (cpu_profiler->is_profiling()) { \
61 cpu_profiler->Call; \ 66 cpu_profiler->Call; \
62 } \ 67 } \
63 } while (false); 68 } while (false);
64 69
65 // ComputeMarker must only be used when SharedFunctionInfo is known. 70 // ComputeMarker must only be used when SharedFunctionInfo is known.
66 static const char* ComputeMarker(Code* code) { 71 static const char* ComputeMarker(Code* code) {
67 switch (code->kind()) { 72 switch (code->kind()) {
68 case Code::FUNCTION: return code->optimizable() ? "~" : ""; 73 case Code::FUNCTION: return code->optimizable() ? "~" : "";
69 case Code::OPTIMIZED_FUNCTION: return "*"; 74 case Code::OPTIMIZED_FUNCTION: return "*";
70 default: return ""; 75 default: return "";
71 } 76 }
72 } 77 }
73 78
74 79
75 class CodeEventLogger { 80 class CodeEventLogger::NameBuffer {
76 public: 81 public:
77 virtual ~CodeEventLogger() { } 82 NameBuffer() { Reset(); }
78 83
79 void CodeCreateEvent(Logger::LogEventsAndTags tag, 84 void Reset() {
80 Code* code, 85 utf8_pos_ = 0;
81 const char* comment); 86 }
82 void CodeCreateEvent(Logger::LogEventsAndTags tag,
83 Code* code,
84 Name* name);
85 void CodeCreateEvent(Logger::LogEventsAndTags tag,
86 Code* code,
87 int args_count);
88 void CodeCreateEvent(Logger::LogEventsAndTags tag,
89 Code* code,
90 SharedFunctionInfo* shared,
91 CompilationInfo* info,
92 Name* name);
93 void CodeCreateEvent(Logger::LogEventsAndTags tag,
94 Code* code,
95 SharedFunctionInfo* shared,
96 CompilationInfo* info,
97 Name* source,
98 int line);
99 void RegExpCodeCreateEvent(Code* code, String* source);
100 87
101 protected: 88 void Init(Logger::LogEventsAndTags tag) {
102 class NameBuffer { 89 Reset();
103 public: 90 AppendBytes(kLogEventsNames[tag]);
104 NameBuffer() { Reset(); } 91 AppendByte(':');
92 }
105 93
106 void Reset() { 94 void AppendName(Name* name) {
107 utf8_pos_ = 0; 95 if (name->IsString()) {
96 AppendString(String::cast(name));
97 } else {
98 Symbol* symbol = Symbol::cast(name);
99 AppendBytes("symbol(");
100 if (!symbol->name()->IsUndefined()) {
101 AppendBytes("\"");
102 AppendString(String::cast(symbol->name()));
103 AppendBytes("\" ");
104 }
105 AppendBytes("hash ");
106 AppendHex(symbol->Hash());
107 AppendByte(')');
108 } 108 }
109 }
109 110
110 void Init(Logger::LogEventsAndTags tag) { 111 void AppendString(String* str) {
111 Reset(); 112 if (str == NULL) return;
112 AppendBytes(kLogEventsNames[tag]); 113 int uc16_length = Min(str->length(), kUtf16BufferSize);
113 AppendByte(':'); 114 String::WriteToFlat(str, utf16_buffer, 0, uc16_length);
115 int previous = unibrow::Utf16::kNoPreviousCharacter;
116 for (int i = 0; i < uc16_length && utf8_pos_ < kUtf8BufferSize; ++i) {
117 uc16 c = utf16_buffer[i];
118 if (c <= unibrow::Utf8::kMaxOneByteChar) {
119 utf8_buffer_[utf8_pos_++] = static_cast<char>(c);
120 } else {
121 int char_length = unibrow::Utf8::Length(c, previous);
122 if (utf8_pos_ + char_length > kUtf8BufferSize) break;
123 unibrow::Utf8::Encode(utf8_buffer_ + utf8_pos_, c, previous);
124 utf8_pos_ += char_length;
125 }
126 previous = c;
114 } 127 }
128 }
115 129
116 void AppendName(Name* name) { 130 void AppendBytes(const char* bytes, int size) {
117 if (name->IsString()) { 131 size = Min(size, kUtf8BufferSize - utf8_pos_);
118 AppendString(String::cast(name)); 132 OS::MemCopy(utf8_buffer_ + utf8_pos_, bytes, size);
119 } else { 133 utf8_pos_ += size;
120 Symbol* symbol = Symbol::cast(name); 134 }
121 AppendBytes("symbol(");
122 if (!symbol->name()->IsUndefined()) {
123 AppendBytes("\"");
124 AppendString(String::cast(symbol->name()));
125 AppendBytes("\" ");
126 }
127 AppendBytes("hash ");
128 AppendHex(symbol->Hash());
129 AppendByte(')');
130 }
131 }
132 135
133 void AppendString(String* str) { 136 void AppendBytes(const char* bytes) {
134 if (str == NULL) return; 137 AppendBytes(bytes, StrLength(bytes));
135 int uc16_length = Min(str->length(), kUtf16BufferSize); 138 }
136 String::WriteToFlat(str, utf16_buffer, 0, uc16_length);
137 int previous = unibrow::Utf16::kNoPreviousCharacter;
138 for (int i = 0; i < uc16_length && utf8_pos_ < kUtf8BufferSize; ++i) {
139 uc16 c = utf16_buffer[i];
140 if (c <= unibrow::Utf8::kMaxOneByteChar) {
141 utf8_buffer_[utf8_pos_++] = static_cast<char>(c);
142 } else {
143 int char_length = unibrow::Utf8::Length(c, previous);
144 if (utf8_pos_ + char_length > kUtf8BufferSize) break;
145 unibrow::Utf8::Encode(utf8_buffer_ + utf8_pos_, c, previous);
146 utf8_pos_ += char_length;
147 }
148 previous = c;
149 }
150 }
151 139
152 void AppendBytes(const char* bytes, int size) { 140 void AppendByte(char c) {
153 size = Min(size, kUtf8BufferSize - utf8_pos_); 141 if (utf8_pos_ >= kUtf8BufferSize) return;
154 OS::MemCopy(utf8_buffer_ + utf8_pos_, bytes, size); 142 utf8_buffer_[utf8_pos_++] = c;
143 }
144
145 void AppendInt(int n) {
146 Vector<char> buffer(utf8_buffer_ + utf8_pos_,
147 kUtf8BufferSize - utf8_pos_);
148 int size = OS::SNPrintF(buffer, "%d", n);
149 if (size > 0 && utf8_pos_ + size <= kUtf8BufferSize) {
155 utf8_pos_ += size; 150 utf8_pos_ += size;
156 } 151 }
152 }
157 153
158 void AppendBytes(const char* bytes) { 154 void AppendHex(uint32_t n) {
159 AppendBytes(bytes, StrLength(bytes)); 155 Vector<char> buffer(utf8_buffer_ + utf8_pos_,
156 kUtf8BufferSize - utf8_pos_);
157 int size = OS::SNPrintF(buffer, "%x", n);
158 if (size > 0 && utf8_pos_ + size <= kUtf8BufferSize) {
159 utf8_pos_ += size;
160 } 160 }
161 }
161 162
162 void AppendByte(char c) { 163 const char* get() { return utf8_buffer_; }
163 if (utf8_pos_ >= kUtf8BufferSize) return; 164 int size() const { return utf8_pos_; }
164 utf8_buffer_[utf8_pos_++] = c;
165 }
166
167 void AppendInt(int n) {
168 Vector<char> buffer(utf8_buffer_ + utf8_pos_,
169 kUtf8BufferSize - utf8_pos_);
170 int size = OS::SNPrintF(buffer, "%d", n);
171 if (size > 0 && utf8_pos_ + size <= kUtf8BufferSize) {
172 utf8_pos_ += size;
173 }
174 }
175
176 void AppendHex(uint32_t n) {
177 Vector<char> buffer(utf8_buffer_ + utf8_pos_,
178 kUtf8BufferSize - utf8_pos_);
179 int size = OS::SNPrintF(buffer, "%x", n);
180 if (size > 0 && utf8_pos_ + size <= kUtf8BufferSize) {
181 utf8_pos_ += size;
182 }
183 }
184
185 const char* get() { return utf8_buffer_; }
186 int size() const { return utf8_pos_; }
187
188 private:
189 static const int kUtf8BufferSize = 512;
190 static const int kUtf16BufferSize = 128;
191
192 int utf8_pos_;
193 char utf8_buffer_[kUtf8BufferSize];
194 uc16 utf16_buffer[kUtf16BufferSize];
195 };
196 165
197 private: 166 private:
198 virtual void LogRecordedBuffer(Code* code, 167 static const int kUtf8BufferSize = 512;
199 SharedFunctionInfo* shared, 168 static const int kUtf16BufferSize = 128;
200 NameBuffer* name_buffer) = 0;
201 169
202 NameBuffer name_buffer_; 170 int utf8_pos_;
171 char utf8_buffer_[kUtf8BufferSize];
172 uc16 utf16_buffer[kUtf16BufferSize];
203 }; 173 };
204 174
205 175
176 CodeEventLogger::CodeEventLogger() : name_buffer_(new NameBuffer) { }
177
178 CodeEventLogger::~CodeEventLogger() { delete name_buffer_; }
179
180
206 void CodeEventLogger::CodeCreateEvent(Logger::LogEventsAndTags tag, 181 void CodeEventLogger::CodeCreateEvent(Logger::LogEventsAndTags tag,
207 Code* code, 182 Code* code,
208 const char* comment) { 183 const char* comment) {
209 name_buffer_.Init(tag); 184 name_buffer_->Init(tag);
210 name_buffer_.AppendBytes(comment); 185 name_buffer_->AppendBytes(comment);
211 LogRecordedBuffer(code, NULL, &name_buffer_); 186 LogRecordedBuffer(code, NULL, name_buffer_->get(), name_buffer_->size());
212 } 187 }
213 188
214 189
215 void CodeEventLogger::CodeCreateEvent(Logger::LogEventsAndTags tag, 190 void CodeEventLogger::CodeCreateEvent(Logger::LogEventsAndTags tag,
216 Code* code, 191 Code* code,
217 Name* name) { 192 Name* name) {
218 name_buffer_.Init(tag); 193 name_buffer_->Init(tag);
219 name_buffer_.AppendName(name); 194 name_buffer_->AppendName(name);
220 LogRecordedBuffer(code, NULL, &name_buffer_); 195 LogRecordedBuffer(code, NULL, name_buffer_->get(), name_buffer_->size());
221 } 196 }
222 197
223 198
224 void CodeEventLogger::CodeCreateEvent(Logger::LogEventsAndTags tag, 199 void CodeEventLogger::CodeCreateEvent(Logger::LogEventsAndTags tag,
225 Code* code, 200 Code* code,
226 SharedFunctionInfo* shared, 201 SharedFunctionInfo* shared,
227 CompilationInfo* info, 202 CompilationInfo* info,
228 Name* name) { 203 Name* name) {
229 name_buffer_.Init(tag); 204 name_buffer_->Init(tag);
230 name_buffer_.AppendBytes(ComputeMarker(code)); 205 name_buffer_->AppendBytes(ComputeMarker(code));
231 name_buffer_.AppendName(name); 206 name_buffer_->AppendName(name);
232 LogRecordedBuffer(code, shared, &name_buffer_); 207 LogRecordedBuffer(code, shared, name_buffer_->get(), name_buffer_->size());
233 } 208 }
234 209
235 210
236 void CodeEventLogger::CodeCreateEvent(Logger::LogEventsAndTags tag, 211 void CodeEventLogger::CodeCreateEvent(Logger::LogEventsAndTags tag,
237 Code* code, 212 Code* code,
238 SharedFunctionInfo* shared, 213 SharedFunctionInfo* shared,
239 CompilationInfo* info, 214 CompilationInfo* info,
240 Name* source, int line) { 215 Name* source, int line) {
241 name_buffer_.Init(tag); 216 name_buffer_->Init(tag);
242 name_buffer_.AppendBytes(ComputeMarker(code)); 217 name_buffer_->AppendBytes(ComputeMarker(code));
243 name_buffer_.AppendString(shared->DebugName()); 218 name_buffer_->AppendString(shared->DebugName());
244 name_buffer_.AppendByte(' '); 219 name_buffer_->AppendByte(' ');
245 if (source->IsString()) { 220 if (source->IsString()) {
246 name_buffer_.AppendString(String::cast(source)); 221 name_buffer_->AppendString(String::cast(source));
247 } else { 222 } else {
248 name_buffer_.AppendBytes("symbol(hash "); 223 name_buffer_->AppendBytes("symbol(hash ");
249 name_buffer_.AppendHex(Name::cast(source)->Hash()); 224 name_buffer_->AppendHex(Name::cast(source)->Hash());
250 name_buffer_.AppendByte(')'); 225 name_buffer_->AppendByte(')');
251 } 226 }
252 name_buffer_.AppendByte(':'); 227 name_buffer_->AppendByte(':');
253 name_buffer_.AppendInt(line); 228 name_buffer_->AppendInt(line);
254 LogRecordedBuffer(code, shared, &name_buffer_); 229 LogRecordedBuffer(code, shared, name_buffer_->get(), name_buffer_->size());
255 } 230 }
256 231
257 232
258 void CodeEventLogger::CodeCreateEvent(Logger::LogEventsAndTags tag, 233 void CodeEventLogger::CodeCreateEvent(Logger::LogEventsAndTags tag,
259 Code* code, 234 Code* code,
260 int args_count) { 235 int args_count) {
261 name_buffer_.Init(tag); 236 name_buffer_->Init(tag);
262 name_buffer_.AppendInt(args_count); 237 name_buffer_->AppendInt(args_count);
263 LogRecordedBuffer(code, NULL, &name_buffer_); 238 LogRecordedBuffer(code, NULL, name_buffer_->get(), name_buffer_->size());
264 } 239 }
265 240
266 241
267 void CodeEventLogger::RegExpCodeCreateEvent(Code* code, String* source) { 242 void CodeEventLogger::RegExpCodeCreateEvent(Code* code, String* source) {
268 name_buffer_.Init(Logger::REG_EXP_TAG); 243 name_buffer_->Init(Logger::REG_EXP_TAG);
269 name_buffer_.AppendString(source); 244 name_buffer_->AppendString(source);
270 LogRecordedBuffer(code, NULL, &name_buffer_); 245 LogRecordedBuffer(code, NULL, name_buffer_->get(), name_buffer_->size());
271 } 246 }
272 247
273 248
274 // Low-level logging support. 249 // Low-level logging support.
250 #define LL_LOG(Call) if (ll_logger_) ll_logger_->Call;
251
275 class LowLevelLogger : public CodeEventLogger { 252 class LowLevelLogger : public CodeEventLogger {
276 public: 253 public:
277 explicit LowLevelLogger(const char* file_name); 254 explicit LowLevelLogger(const char* file_name);
278 virtual ~LowLevelLogger(); 255 virtual ~LowLevelLogger();
279 256
280 void CodeMoveEvent(Address from, Address to); 257 void CodeMoveEvent(Address from, Address to);
281 void CodeDeleteEvent(Address from); 258 void CodeDeleteEvent(Address from);
282 void SnapshotPositionEvent(Address addr, int pos); 259 void SnapshotPositionEvent(Address addr, int pos);
283 void CodeMovingGCEvent(); 260 void CodeMovingGCEvent();
284 261
285 private: 262 private:
286 virtual void LogRecordedBuffer(Code* code, 263 virtual void LogRecordedBuffer(Code* code,
287 SharedFunctionInfo* shared, 264 SharedFunctionInfo* shared,
288 NameBuffer* name_buffer); 265 const char* name,
266 int length);
289 267
290 // Low-level profiling event structures. 268 // Low-level profiling event structures.
291 struct CodeCreateStruct { 269 struct CodeCreateStruct {
292 static const char kTag = 'C'; 270 static const char kTag = 'C';
293 271
294 int32_t name_size; 272 int32_t name_size;
295 Address code_address; 273 Address code_address;
296 int32_t code_size; 274 int32_t code_size;
297 }; 275 };
298 276
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 const char arch[] = "mips"; 354 const char arch[] = "mips";
377 #else 355 #else
378 const char arch[] = "unknown"; 356 const char arch[] = "unknown";
379 #endif 357 #endif
380 LogWriteBytes(arch, sizeof(arch)); 358 LogWriteBytes(arch, sizeof(arch));
381 } 359 }
382 360
383 361
384 void LowLevelLogger::LogRecordedBuffer(Code* code, 362 void LowLevelLogger::LogRecordedBuffer(Code* code,
385 SharedFunctionInfo*, 363 SharedFunctionInfo*,
386 NameBuffer* name_buffer) { 364 const char* name,
365 int length) {
387 CodeCreateStruct event; 366 CodeCreateStruct event;
388 event.name_size = name_buffer->size(); 367 event.name_size = length;
389 event.code_address = code->instruction_start(); 368 event.code_address = code->instruction_start();
390 ASSERT(event.code_address == code->address() + Code::kHeaderSize); 369 ASSERT(event.code_address == code->address() + Code::kHeaderSize);
391 event.code_size = code->instruction_size(); 370 event.code_size = code->instruction_size();
392 LogWriteStruct(event); 371 LogWriteStruct(event);
393 LogWriteBytes(name_buffer->get(), name_buffer->size()); 372 LogWriteBytes(name, length);
394 LogWriteBytes( 373 LogWriteBytes(
395 reinterpret_cast<const char*>(code->instruction_start()), 374 reinterpret_cast<const char*>(code->instruction_start()),
396 code->instruction_size()); 375 code->instruction_size());
397 } 376 }
398 377
399 378
400 void LowLevelLogger::CodeMoveEvent(Address from, Address to) { 379 void LowLevelLogger::CodeMoveEvent(Address from, Address to) {
401 CodeMoveStruct event; 380 CodeMoveStruct event;
402 event.from_address = from + Code::kHeaderSize; 381 event.from_address = from + Code::kHeaderSize;
403 event.to_address = to + Code::kHeaderSize; 382 event.to_address = to + Code::kHeaderSize;
(...skipping 23 matching lines...) Expand all
427 } 406 }
428 407
429 408
430 void LowLevelLogger::CodeMovingGCEvent() { 409 void LowLevelLogger::CodeMovingGCEvent() {
431 const char tag = kCodeMovingGCTag; 410 const char tag = kCodeMovingGCTag;
432 411
433 LogWriteBytes(&tag, sizeof(tag)); 412 LogWriteBytes(&tag, sizeof(tag));
434 } 413 }
435 414
436 415
437 #define LL_LOG(Call) if (ll_logger_) ll_logger_->Call; 416 #define JIT_LOG(Call) if (jit_logger_) jit_logger_->Call;
438
439
440 class CodeAddressMap: public CodeEventLogger {
441 public:
442 CodeAddressMap() { }
443 virtual ~CodeAddressMap() { }
444
445 void CodeMoveEvent(Address from, Address to) {
446 address_to_name_map_.Move(from, to);
447 }
448
449 void CodeDeleteEvent(Address from) {
450 address_to_name_map_.Remove(from);
451 }
452
453 const char* Lookup(Address address) {
454 return address_to_name_map_.Lookup(address);
455 }
456
457 private:
458 class NameMap {
459 public:
460 NameMap() : impl_(&PointerEquals) {}
461
462 ~NameMap() {
463 for (HashMap::Entry* p = impl_.Start(); p != NULL; p = impl_.Next(p)) {
464 DeleteArray(static_cast<const char*>(p->value));
465 }
466 }
467
468 void Insert(Address code_address, const char* name, int name_size) {
469 HashMap::Entry* entry = FindOrCreateEntry(code_address);
470 if (entry->value == NULL) {
471 entry->value = CopyName(name, name_size);
472 }
473 }
474
475 const char* Lookup(Address code_address) {
476 HashMap::Entry* entry = FindEntry(code_address);
477 return (entry != NULL) ? static_cast<const char*>(entry->value) : NULL;
478 }
479
480 void Remove(Address code_address) {
481 HashMap::Entry* entry = FindEntry(code_address);
482 if (entry != NULL) {
483 DeleteArray(static_cast<char*>(entry->value));
484 RemoveEntry(entry);
485 }
486 }
487
488 void Move(Address from, Address to) {
489 if (from == to) return;
490 HashMap::Entry* from_entry = FindEntry(from);
491 ASSERT(from_entry != NULL);
492 void* value = from_entry->value;
493 RemoveEntry(from_entry);
494 HashMap::Entry* to_entry = FindOrCreateEntry(to);
495 ASSERT(to_entry->value == NULL);
496 to_entry->value = value;
497 }
498
499 private:
500 static bool PointerEquals(void* lhs, void* rhs) {
501 return lhs == rhs;
502 }
503
504 static char* CopyName(const char* name, int name_size) {
505 char* result = NewArray<char>(name_size + 1);
506 for (int i = 0; i < name_size; ++i) {
507 char c = name[i];
508 if (c == '\0') c = ' ';
509 result[i] = c;
510 }
511 result[name_size] = '\0';
512 return result;
513 }
514
515 HashMap::Entry* FindOrCreateEntry(Address code_address) {
516 return impl_.Lookup(code_address, ComputePointerHash(code_address), true);
517 }
518
519 HashMap::Entry* FindEntry(Address code_address) {
520 return impl_.Lookup(code_address,
521 ComputePointerHash(code_address),
522 false);
523 }
524
525 void RemoveEntry(HashMap::Entry* entry) {
526 impl_.Remove(entry->key, entry->hash);
527 }
528
529 HashMap impl_;
530
531 DISALLOW_COPY_AND_ASSIGN(NameMap);
532 };
533
534 virtual void LogRecordedBuffer(Code* code,
535 SharedFunctionInfo*,
536 NameBuffer* name_buffer) {
537 address_to_name_map_.Insert(code->address(),
538 name_buffer->get(),
539 name_buffer->size());
540 }
541
542 NameMap address_to_name_map_;
543 };
544
545
546 #define CODE_ADDRESS_MAP_LOG(Call)\
547 if (Serializer::enabled()) code_address_map_->Call;
548 417
549 418
550 class JitLogger : public CodeEventLogger { 419 class JitLogger : public CodeEventLogger {
551 public: 420 public:
552 explicit JitLogger(JitCodeEventHandler code_event_handler); 421 explicit JitLogger(JitCodeEventHandler code_event_handler);
553 422
554 void CodeMoveEvent(Address from, Address to); 423 void CodeMoveEvent(Address from, Address to);
555 void CodeDeleteEvent(Address from); 424 void CodeDeleteEvent(Address from);
556 void AddCodeLinePosInfoEvent( 425 void AddCodeLinePosInfoEvent(
557 void* jit_handler_data, 426 void* jit_handler_data,
558 int pc_offset, 427 int pc_offset,
559 int position, 428 int position,
560 JitCodeEvent::PositionType position_type); 429 JitCodeEvent::PositionType position_type);
561 void* StartCodePosInfoEvent(); 430 void* StartCodePosInfoEvent();
562 void EndCodePosInfoEvent(Code* code, void* jit_handler_data); 431 void EndCodePosInfoEvent(Code* code, void* jit_handler_data);
563 432
564 private: 433 private:
565 virtual void LogRecordedBuffer(Code* code, 434 virtual void LogRecordedBuffer(Code* code,
566 SharedFunctionInfo* shared, 435 SharedFunctionInfo* shared,
567 CodeEventLogger::NameBuffer* name_buffer); 436 const char* name,
437 int length);
568 438
569 JitCodeEventHandler code_event_handler_; 439 JitCodeEventHandler code_event_handler_;
570 }; 440 };
571 441
572 #define JIT_LOG(Call) if (jit_logger_) jit_logger_->Call;
573
574 442
575 JitLogger::JitLogger(JitCodeEventHandler code_event_handler) 443 JitLogger::JitLogger(JitCodeEventHandler code_event_handler)
576 : code_event_handler_(code_event_handler) { 444 : code_event_handler_(code_event_handler) {
577 } 445 }
578 446
579 447
580 void JitLogger::LogRecordedBuffer(Code* code, 448 void JitLogger::LogRecordedBuffer(Code* code,
581 SharedFunctionInfo* shared, 449 SharedFunctionInfo* shared,
582 CodeEventLogger::NameBuffer* name_buffer) { 450 const char* name,
451 int length) {
583 JitCodeEvent event; 452 JitCodeEvent event;
584 memset(&event, 0, sizeof(event)); 453 memset(&event, 0, sizeof(event));
585 event.type = JitCodeEvent::CODE_ADDED; 454 event.type = JitCodeEvent::CODE_ADDED;
586 event.code_start = code->instruction_start(); 455 event.code_start = code->instruction_start();
587 event.code_len = code->instruction_size(); 456 event.code_len = code->instruction_size();
588 Handle<Script> script_handle; 457 Handle<Script> script_handle;
589 if (shared && shared->script()->IsScript()) { 458 if (shared && shared->script()->IsScript()) {
590 script_handle = Handle<Script>(Script::cast(shared->script())); 459 script_handle = Handle<Script>(Script::cast(shared->script()));
591 } 460 }
592 event.script = ToApiHandle<v8::Script>(script_handle); 461 event.script = ToApiHandle<v8::Script>(script_handle);
593 event.name.str = name_buffer->get(); 462 event.name.str = name;
594 event.name.len = name_buffer->size(); 463 event.name.len = length;
595 code_event_handler_(&event); 464 code_event_handler_(&event);
596 } 465 }
597 466
598 467
599 void JitLogger::CodeMoveEvent(Address from, Address to) { 468 void JitLogger::CodeMoveEvent(Address from, Address to) {
600 Code* from_code = Code::cast(HeapObject::FromAddress(from)); 469 Code* from_code = Code::cast(HeapObject::FromAddress(from));
601 470
602 JitCodeEvent event; 471 JitCodeEvent event;
603 event.type = JitCodeEvent::CODE_MOVED; 472 event.type = JitCodeEvent::CODE_MOVED;
604 event.code_start = from_code->instruction_start(); 473 event.code_start = from_code->instruction_start();
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
837 Logger::Logger(Isolate* isolate) 706 Logger::Logger(Isolate* isolate)
838 : isolate_(isolate), 707 : isolate_(isolate),
839 ticker_(NULL), 708 ticker_(NULL),
840 profiler_(NULL), 709 profiler_(NULL),
841 log_events_(NULL), 710 log_events_(NULL),
842 logging_nesting_(0), 711 logging_nesting_(0),
843 cpu_profiler_nesting_(0), 712 cpu_profiler_nesting_(0),
844 log_(new Log(this)), 713 log_(new Log(this)),
845 ll_logger_(NULL), 714 ll_logger_(NULL),
846 jit_logger_(NULL), 715 jit_logger_(NULL),
847 code_address_map_(new CodeAddressMap), 716 loggers_(5),
848 is_initialized_(false), 717 is_initialized_(false),
849 last_address_(NULL), 718 last_address_(NULL),
850 prev_sp_(NULL), 719 prev_sp_(NULL),
851 prev_function_(NULL), 720 prev_function_(NULL),
852 prev_to_(NULL), 721 prev_to_(NULL),
853 prev_code_(NULL), 722 prev_code_(NULL),
854 epoch_(0) { 723 epoch_(0) {
855 } 724 }
856 725
857 726
858 Logger::~Logger() { 727 Logger::~Logger() {
859 delete code_address_map_;
860 delete log_; 728 delete log_;
861 } 729 }
862 730
863 731
732 void Logger::addLogger(CodeEventLoggerBase* logger) {
733 ASSERT(!hasLogger(logger));
734 loggers_.Add(logger);
735 }
736
737
738 void Logger::removeLogger(CodeEventLoggerBase* logger) {
739 ASSERT(hasLogger(logger));
740 loggers_.RemoveElement(logger);
741 }
742
743
744 bool Logger::hasLogger(CodeEventLoggerBase* logger) {
745 return loggers_.Contains(logger);
746 }
747
748
864 void Logger::ProfilerBeginEvent() { 749 void Logger::ProfilerBeginEvent() {
865 if (!log_->IsEnabled()) return; 750 if (!log_->IsEnabled()) return;
866 Log::MessageBuilder msg(log_); 751 Log::MessageBuilder msg(log_);
867 msg.Append("profiler,\"begin\",%d\n", kSamplingIntervalMs); 752 msg.Append("profiler,\"begin\",%d\n", kSamplingIntervalMs);
868 msg.WriteToLogFile(); 753 msg.WriteToLogFile();
869 } 754 }
870 755
871 756
872 void Logger::StringEvent(const char* name, const char* value) { 757 void Logger::StringEvent(const char* name, const char* value) {
873 if (FLAG_log) UncheckedStringEvent(name, value); 758 if (FLAG_log) UncheckedStringEvent(name, value);
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
1272 msg->Append(",%d,", code->ExecutableSize()); 1157 msg->Append(",%d,", code->ExecutableSize());
1273 } 1158 }
1274 1159
1275 1160
1276 void Logger::CodeCreateEvent(LogEventsAndTags tag, 1161 void Logger::CodeCreateEvent(LogEventsAndTags tag,
1277 Code* code, 1162 Code* code,
1278 const char* comment) { 1163 const char* comment) {
1279 PROFILER_LOG(CodeCreateEvent(tag, code, comment)); 1164 PROFILER_LOG(CodeCreateEvent(tag, code, comment));
1280 1165
1281 if (!is_logging_code_events()) return; 1166 if (!is_logging_code_events()) return;
1282 JIT_LOG(CodeCreateEvent(tag, code, comment)); 1167 CALL_LOGGERS(CodeCreateEvent(tag, code, comment));
1283 LL_LOG(CodeCreateEvent(tag, code, comment));
1284 CODE_ADDRESS_MAP_LOG(CodeCreateEvent(tag, code, comment));
1285 1168
1286 if (!FLAG_log_code || !log_->IsEnabled()) return; 1169 if (!FLAG_log_code || !log_->IsEnabled()) return;
1287 Log::MessageBuilder msg(log_); 1170 Log::MessageBuilder msg(log_);
1288 AppendCodeCreateHeader(&msg, tag, code); 1171 AppendCodeCreateHeader(&msg, tag, code);
1289 msg.AppendDoubleQuotedString(comment); 1172 msg.AppendDoubleQuotedString(comment);
1290 msg.Append('\n'); 1173 msg.Append('\n');
1291 msg.WriteToLogFile(); 1174 msg.WriteToLogFile();
1292 } 1175 }
1293 1176
1294 1177
1295 void Logger::CodeCreateEvent(LogEventsAndTags tag, 1178 void Logger::CodeCreateEvent(LogEventsAndTags tag,
1296 Code* code, 1179 Code* code,
1297 Name* name) { 1180 Name* name) {
1298 PROFILER_LOG(CodeCreateEvent(tag, code, name)); 1181 PROFILER_LOG(CodeCreateEvent(tag, code, name));
1299 1182
1300 if (!is_logging_code_events()) return; 1183 if (!is_logging_code_events()) return;
1301 JIT_LOG(CodeCreateEvent(tag, code, name)); 1184 CALL_LOGGERS(CodeCreateEvent(tag, code, name));
1302 LL_LOG(CodeCreateEvent(tag, code, name));
1303 CODE_ADDRESS_MAP_LOG(CodeCreateEvent(tag, code, name));
1304 1185
1305 if (!FLAG_log_code || !log_->IsEnabled()) return; 1186 if (!FLAG_log_code || !log_->IsEnabled()) return;
1306 Log::MessageBuilder msg(log_); 1187 Log::MessageBuilder msg(log_);
1307 AppendCodeCreateHeader(&msg, tag, code); 1188 AppendCodeCreateHeader(&msg, tag, code);
1308 if (name->IsString()) { 1189 if (name->IsString()) {
1309 msg.Append('"'); 1190 msg.Append('"');
1310 msg.AppendDetailed(String::cast(name), false); 1191 msg.AppendDetailed(String::cast(name), false);
1311 msg.Append('"'); 1192 msg.Append('"');
1312 } else { 1193 } else {
1313 msg.AppendSymbolName(Symbol::cast(name)); 1194 msg.AppendSymbolName(Symbol::cast(name));
1314 } 1195 }
1315 msg.Append('\n'); 1196 msg.Append('\n');
1316 msg.WriteToLogFile(); 1197 msg.WriteToLogFile();
1317 } 1198 }
1318 1199
1319 1200
1320 void Logger::CodeCreateEvent(LogEventsAndTags tag, 1201 void Logger::CodeCreateEvent(LogEventsAndTags tag,
1321 Code* code, 1202 Code* code,
1322 SharedFunctionInfo* shared, 1203 SharedFunctionInfo* shared,
1323 CompilationInfo* info, 1204 CompilationInfo* info,
1324 Name* name) { 1205 Name* name) {
1325 PROFILER_LOG(CodeCreateEvent(tag, code, shared, info, name)); 1206 PROFILER_LOG(CodeCreateEvent(tag, code, shared, info, name));
1326 1207
1327 if (!is_logging_code_events()) return; 1208 if (!is_logging_code_events()) return;
1328 JIT_LOG(CodeCreateEvent(tag, code, shared, info, name)); 1209 CALL_LOGGERS(CodeCreateEvent(tag, code, shared, info, name));
1329 LL_LOG(CodeCreateEvent(tag, code, shared, info, name));
1330 CODE_ADDRESS_MAP_LOG(CodeCreateEvent(tag, code, shared, info, name));
1331 1210
1332 if (!FLAG_log_code || !log_->IsEnabled()) return; 1211 if (!FLAG_log_code || !log_->IsEnabled()) return;
1333 if (code == isolate_->builtins()->builtin( 1212 if (code == isolate_->builtins()->builtin(
1334 Builtins::kLazyCompile)) 1213 Builtins::kLazyCompile))
1335 return; 1214 return;
1336 1215
1337 Log::MessageBuilder msg(log_); 1216 Log::MessageBuilder msg(log_);
1338 AppendCodeCreateHeader(&msg, tag, code); 1217 AppendCodeCreateHeader(&msg, tag, code);
1339 if (name->IsString()) { 1218 if (name->IsString()) {
1340 SmartArrayPointer<char> str = 1219 SmartArrayPointer<char> str =
(...skipping 14 matching lines...) Expand all
1355 // the SharedFunctionInfo object, we left it to caller 1234 // the SharedFunctionInfo object, we left it to caller
1356 // to leave logging functions free from heap allocations. 1235 // to leave logging functions free from heap allocations.
1357 void Logger::CodeCreateEvent(LogEventsAndTags tag, 1236 void Logger::CodeCreateEvent(LogEventsAndTags tag,
1358 Code* code, 1237 Code* code,
1359 SharedFunctionInfo* shared, 1238 SharedFunctionInfo* shared,
1360 CompilationInfo* info, 1239 CompilationInfo* info,
1361 Name* source, int line) { 1240 Name* source, int line) {
1362 PROFILER_LOG(CodeCreateEvent(tag, code, shared, info, source, line)); 1241 PROFILER_LOG(CodeCreateEvent(tag, code, shared, info, source, line));
1363 1242
1364 if (!is_logging_code_events()) return; 1243 if (!is_logging_code_events()) return;
1365 JIT_LOG(CodeCreateEvent(tag, code, shared, info, source, line)); 1244 CALL_LOGGERS(CodeCreateEvent(tag, code, shared, info, source, line));
1366 LL_LOG(CodeCreateEvent(tag, code, shared, info, source, line));
1367 CODE_ADDRESS_MAP_LOG(CodeCreateEvent(tag, code, shared, info, source, line));
1368 1245
1369 if (!FLAG_log_code || !log_->IsEnabled()) return; 1246 if (!FLAG_log_code || !log_->IsEnabled()) return;
1370 Log::MessageBuilder msg(log_); 1247 Log::MessageBuilder msg(log_);
1371 AppendCodeCreateHeader(&msg, tag, code); 1248 AppendCodeCreateHeader(&msg, tag, code);
1372 SmartArrayPointer<char> name = 1249 SmartArrayPointer<char> name =
1373 shared->DebugName()->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); 1250 shared->DebugName()->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
1374 msg.Append("\"%s ", *name); 1251 msg.Append("\"%s ", *name);
1375 if (source->IsString()) { 1252 if (source->IsString()) {
1376 SmartArrayPointer<char> sourcestr = 1253 SmartArrayPointer<char> sourcestr =
1377 String::cast(source)->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); 1254 String::cast(source)->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
1378 msg.Append("%s", *sourcestr); 1255 msg.Append("%s", *sourcestr);
1379 } else { 1256 } else {
1380 msg.AppendSymbolName(Symbol::cast(source)); 1257 msg.AppendSymbolName(Symbol::cast(source));
1381 } 1258 }
1382 msg.Append(":%d\",", line); 1259 msg.Append(":%d\",", line);
1383 msg.AppendAddress(shared->address()); 1260 msg.AppendAddress(shared->address());
1384 msg.Append(",%s", ComputeMarker(code)); 1261 msg.Append(",%s", ComputeMarker(code));
1385 msg.Append('\n'); 1262 msg.Append('\n');
1386 msg.WriteToLogFile(); 1263 msg.WriteToLogFile();
1387 } 1264 }
1388 1265
1389 1266
1390 void Logger::CodeCreateEvent(LogEventsAndTags tag, 1267 void Logger::CodeCreateEvent(LogEventsAndTags tag,
1391 Code* code, 1268 Code* code,
1392 int args_count) { 1269 int args_count) {
1393 PROFILER_LOG(CodeCreateEvent(tag, code, args_count)); 1270 PROFILER_LOG(CodeCreateEvent(tag, code, args_count));
1394 1271
1395 if (!is_logging_code_events()) return; 1272 if (!is_logging_code_events()) return;
1396 JIT_LOG(CodeCreateEvent(tag, code, args_count)); 1273 CALL_LOGGERS(CodeCreateEvent(tag, code, args_count));
1397 LL_LOG(CodeCreateEvent(tag, code, args_count));
1398 CODE_ADDRESS_MAP_LOG(CodeCreateEvent(tag, code, args_count));
1399 1274
1400 if (!FLAG_log_code || !log_->IsEnabled()) return; 1275 if (!FLAG_log_code || !log_->IsEnabled()) return;
1401 Log::MessageBuilder msg(log_); 1276 Log::MessageBuilder msg(log_);
1402 AppendCodeCreateHeader(&msg, tag, code); 1277 AppendCodeCreateHeader(&msg, tag, code);
1403 msg.Append("\"args_count: %d\"", args_count); 1278 msg.Append("\"args_count: %d\"", args_count);
1404 msg.Append('\n'); 1279 msg.Append('\n');
1405 msg.WriteToLogFile(); 1280 msg.WriteToLogFile();
1406 } 1281 }
1407 1282
1408 1283
1409 void Logger::CodeMovingGCEvent() { 1284 void Logger::CodeMovingGCEvent() {
1410 PROFILER_LOG(CodeMovingGCEvent()); 1285 PROFILER_LOG(CodeMovingGCEvent());
1411 1286
1412 if (!is_logging_code_events()) return; 1287 if (!is_logging_code_events()) return;
1413 if (!log_->IsEnabled() || !FLAG_ll_prof) return; 1288 if (!log_->IsEnabled() || !FLAG_ll_prof) return;
1414 LL_LOG(CodeMovingGCEvent()); 1289 CALL_LOGGERS(CodeMovingGCEvent());
1415 OS::SignalCodeMovingGC(); 1290 OS::SignalCodeMovingGC();
1416 } 1291 }
1417 1292
1418 1293
1419 void Logger::RegExpCodeCreateEvent(Code* code, String* source) { 1294 void Logger::RegExpCodeCreateEvent(Code* code, String* source) {
1420 PROFILER_LOG(RegExpCodeCreateEvent(code, source)); 1295 PROFILER_LOG(RegExpCodeCreateEvent(code, source));
1421 1296
1422 if (!is_logging_code_events()) return; 1297 if (!is_logging_code_events()) return;
1423 JIT_LOG(RegExpCodeCreateEvent(code, source)); 1298 CALL_LOGGERS(RegExpCodeCreateEvent(code, source));
1424 LL_LOG(RegExpCodeCreateEvent(code, source));
1425 CODE_ADDRESS_MAP_LOG(RegExpCodeCreateEvent(code, source));
1426 1299
1427 if (!FLAG_log_code || !log_->IsEnabled()) return; 1300 if (!FLAG_log_code || !log_->IsEnabled()) return;
1428 Log::MessageBuilder msg(log_); 1301 Log::MessageBuilder msg(log_);
1429 AppendCodeCreateHeader(&msg, REG_EXP_TAG, code); 1302 AppendCodeCreateHeader(&msg, REG_EXP_TAG, code);
1430 msg.Append('"'); 1303 msg.Append('"');
1431 msg.AppendDetailed(source, false); 1304 msg.AppendDetailed(source, false);
1432 msg.Append('"'); 1305 msg.Append('"');
1433 msg.Append('\n'); 1306 msg.Append('\n');
1434 msg.WriteToLogFile(); 1307 msg.WriteToLogFile();
1435 } 1308 }
1436 1309
1437 1310
1438 void Logger::CodeMoveEvent(Address from, Address to) { 1311 void Logger::CodeMoveEvent(Address from, Address to) {
1439 PROFILER_LOG(CodeMoveEvent(from, to)); 1312 PROFILER_LOG(CodeMoveEvent(from, to));
1440 1313
1441 if (!is_logging_code_events()) return; 1314 if (!is_logging_code_events()) return;
1442 JIT_LOG(CodeMoveEvent(from, to)); 1315 CALL_LOGGERS(CodeMoveEvent(from, to));
1443 LL_LOG(CodeMoveEvent(from, to));
1444 CODE_ADDRESS_MAP_LOG(CodeMoveEvent(from, to));
1445 MoveEventInternal(CODE_MOVE_EVENT, from, to); 1316 MoveEventInternal(CODE_MOVE_EVENT, from, to);
1446 } 1317 }
1447 1318
1448 1319
1449 void Logger::CodeDeleteEvent(Address from) { 1320 void Logger::CodeDeleteEvent(Address from) {
1450 PROFILER_LOG(CodeDeleteEvent(from)); 1321 PROFILER_LOG(CodeDeleteEvent(from));
1451 1322
1452 if (!is_logging_code_events()) return; 1323 if (!is_logging_code_events()) return;
1453 JIT_LOG(CodeDeleteEvent(from)); 1324 CALL_LOGGERS(CodeDeleteEvent(from));
1454 LL_LOG(CodeDeleteEvent(from));
1455 CODE_ADDRESS_MAP_LOG(CodeDeleteEvent(from));
1456 1325
1457 if (!FLAG_log_code || !log_->IsEnabled()) return; 1326 if (!FLAG_log_code || !log_->IsEnabled()) return;
1458 Log::MessageBuilder msg(log_); 1327 Log::MessageBuilder msg(log_);
1459 msg.Append("%s,", kLogEventsNames[CODE_DELETE_EVENT]); 1328 msg.Append("%s,", kLogEventsNames[CODE_DELETE_EVENT]);
1460 msg.AppendAddress(from); 1329 msg.AppendAddress(from);
1461 msg.Append('\n'); 1330 msg.Append('\n');
1462 msg.WriteToLogFile(); 1331 msg.WriteToLogFile();
1463 } 1332 }
1464 1333
1465 1334
(...skipping 23 matching lines...) Expand all
1489 } 1358 }
1490 } 1359 }
1491 1360
1492 1361
1493 void Logger::CodeEndLinePosInfoRecordEvent(Code* code, 1362 void Logger::CodeEndLinePosInfoRecordEvent(Code* code,
1494 void* jit_handler_data) { 1363 void* jit_handler_data) {
1495 JIT_LOG(EndCodePosInfoEvent(code, jit_handler_data)); 1364 JIT_LOG(EndCodePosInfoEvent(code, jit_handler_data));
1496 } 1365 }
1497 1366
1498 1367
1368 void Logger::CodeNameEvent(Address addr, int pos, const char* code_name) {
1369 if (code_name == NULL) return; // Not a code object.
1370 Log::MessageBuilder msg(log_);
1371 msg.Append("%s,%d,", kLogEventsNames[SNAPSHOT_CODE_NAME_EVENT], pos);
1372 msg.AppendDoubleQuotedString(code_name);
1373 msg.Append("\n");
1374 msg.WriteToLogFile();
1375 }
1376
1377
1499 void Logger::SnapshotPositionEvent(Address addr, int pos) { 1378 void Logger::SnapshotPositionEvent(Address addr, int pos) {
1500 if (!log_->IsEnabled()) return; 1379 if (!log_->IsEnabled()) return;
1501 LL_LOG(SnapshotPositionEvent(addr, pos)); 1380 LL_LOG(SnapshotPositionEvent(addr, pos));
1502 if (Serializer::enabled()) {
1503 const char* code_name = code_address_map_->Lookup(addr);
1504 if (code_name == NULL) return; // Not a code object.
1505 Log::MessageBuilder msg(log_);
1506 msg.Append("%s,%d,", kLogEventsNames[SNAPSHOT_CODE_NAME_EVENT], pos);
1507 msg.AppendDoubleQuotedString(code_name);
1508 msg.Append("\n");
1509 msg.WriteToLogFile();
1510 }
1511 if (!FLAG_log_snapshot_positions) return; 1381 if (!FLAG_log_snapshot_positions) return;
1512 Log::MessageBuilder msg(log_); 1382 Log::MessageBuilder msg(log_);
1513 msg.Append("%s,", kLogEventsNames[SNAPSHOT_POSITION_EVENT]); 1383 msg.Append("%s,", kLogEventsNames[SNAPSHOT_POSITION_EVENT]);
1514 msg.AppendAddress(addr); 1384 msg.AppendAddress(addr);
1515 msg.Append(",%d", pos); 1385 msg.Append(",%d", pos);
1516 msg.Append('\n'); 1386 msg.Append('\n');
1517 msg.WriteToLogFile(); 1387 msg.WriteToLogFile();
1518 } 1388 }
1519 1389
1520 1390
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
2003 FLAG_log_code = false; 1873 FLAG_log_code = false;
2004 FLAG_prof_auto = false; 1874 FLAG_prof_auto = false;
2005 } 1875 }
2006 1876
2007 SmartArrayPointer<const char> log_file_name = 1877 SmartArrayPointer<const char> log_file_name =
2008 PrepareLogFileName(FLAG_logfile); 1878 PrepareLogFileName(FLAG_logfile);
2009 log_->Initialize(*log_file_name); 1879 log_->Initialize(*log_file_name);
2010 1880
2011 if (FLAG_ll_prof) { 1881 if (FLAG_ll_prof) {
2012 ll_logger_ = new LowLevelLogger(*log_file_name); 1882 ll_logger_ = new LowLevelLogger(*log_file_name);
1883 addLogger(ll_logger_);
2013 } 1884 }
2014 1885
2015 ticker_ = new Ticker(isolate, kSamplingIntervalMs); 1886 ticker_ = new Ticker(isolate, kSamplingIntervalMs);
2016 1887
2017 if (Log::InitLogAtStart()) { 1888 if (Log::InitLogAtStart()) {
2018 logging_nesting_ = 1; 1889 logging_nesting_ = 1;
2019 } 1890 }
2020 1891
2021 if (FLAG_prof) { 1892 if (FLAG_prof) {
2022 profiler_ = new Profiler(isolate); 1893 profiler_ = new Profiler(isolate);
2023 if (!FLAG_prof_auto) { 1894 if (!FLAG_prof_auto) {
2024 profiler_->pause(); 1895 profiler_->pause();
2025 } else { 1896 } else {
2026 logging_nesting_ = 1; 1897 logging_nesting_ = 1;
2027 } 1898 }
2028 if (!FLAG_prof_lazy) { 1899 if (!FLAG_prof_lazy) {
2029 profiler_->Engage(); 1900 profiler_->Engage();
2030 } 1901 }
2031 } 1902 }
2032 1903
2033 if (FLAG_log_internal_timer_events || FLAG_prof) epoch_ = OS::Ticks(); 1904 if (FLAG_log_internal_timer_events || FLAG_prof) epoch_ = OS::Ticks();
2034 1905
2035 return true; 1906 return true;
2036 } 1907 }
2037 1908
2038 1909
2039 void Logger::SetCodeEventHandler(uint32_t options, 1910 void Logger::SetCodeEventHandler(uint32_t options,
2040 JitCodeEventHandler event_handler) { 1911 JitCodeEventHandler event_handler) {
2041 if (jit_logger_) { 1912 if (jit_logger_) {
1913 removeLogger(jit_logger_);
2042 delete jit_logger_; 1914 delete jit_logger_;
2043 jit_logger_ = NULL; 1915 jit_logger_ = NULL;
2044 } 1916 }
2045 1917
2046 if (event_handler) { 1918 if (event_handler) {
2047 jit_logger_ = new JitLogger(event_handler); 1919 jit_logger_ = new JitLogger(event_handler);
2048 } 1920 addLogger(jit_logger_);
2049 1921 if (options & kJitCodeEventEnumExisting) {
2050 if (jit_logger_ != NULL && (options & kJitCodeEventEnumExisting)) { 1922 HandleScope scope(isolate_);
2051 HandleScope scope(isolate_); 1923 LogCodeObjects();
2052 LogCodeObjects(); 1924 LogCompiledFunctions();
2053 LogCompiledFunctions(); 1925 }
2054 } 1926 }
2055 } 1927 }
2056 1928
2057 1929
2058 Sampler* Logger::sampler() { 1930 Sampler* Logger::sampler() {
2059 return ticker_; 1931 return ticker_;
2060 } 1932 }
2061 1933
2062 1934
2063 FILE* Logger::TearDown() { 1935 FILE* Logger::TearDown() {
2064 if (!is_initialized_) return NULL; 1936 if (!is_initialized_) return NULL;
2065 is_initialized_ = false; 1937 is_initialized_ = false;
2066 1938
2067 // Stop the profiler before closing the file. 1939 // Stop the profiler before closing the file.
2068 if (profiler_ != NULL) { 1940 if (profiler_ != NULL) {
2069 profiler_->Disengage(); 1941 profiler_->Disengage();
2070 delete profiler_; 1942 delete profiler_;
2071 profiler_ = NULL; 1943 profiler_ = NULL;
2072 } 1944 }
2073 1945
2074 delete ticker_; 1946 delete ticker_;
2075 ticker_ = NULL; 1947 ticker_ = NULL;
2076 1948
2077 if (ll_logger_) { 1949 if (ll_logger_) {
1950 removeLogger(ll_logger_);
2078 delete ll_logger_; 1951 delete ll_logger_;
2079 ll_logger_ = NULL; 1952 ll_logger_ = NULL;
2080 } 1953 }
2081 1954
2082 if (jit_logger_) { 1955 if (jit_logger_) {
1956 removeLogger(jit_logger_);
2083 delete jit_logger_; 1957 delete jit_logger_;
2084 jit_logger_ = NULL; 1958 jit_logger_ = NULL;
2085 } 1959 }
2086 1960
2087 return log_->Close(); 1961 return log_->Close();
2088 } 1962 }
2089 1963
2090 } } // namespace v8::internal 1964 } } // namespace v8::internal
OLDNEW
« src/log.h ('K') | « src/log.h ('k') | src/serialize.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698