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

Side by Side Diff: test/cctest/test-log.cc

Issue 23478010: Remove deprecated profiler API (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 3 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
« no previous file with comments | « src/log-utils.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. 1 // Copyright 2006-2009 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
11 // with the distribution. 11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its 12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived 13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission. 14 // from this software without specific prior written permission.
15 // 15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 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. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 // 27 //
28 // Tests of logging functions from log.h 28 // Tests of logging functions from log.h
29 29
30 #define V8_DISABLE_DEPRECATIONS 1
31 #ifdef __linux__ 30 #ifdef __linux__
32 #include <pthread.h> 31 #include <pthread.h>
33 #include <signal.h> 32 #include <signal.h>
34 #include <unistd.h> 33 #include <unistd.h>
35 #include <cmath> 34 #include <cmath>
36 #endif // __linux__ 35 #endif // __linux__
37 36
38 #include "v8.h" 37 #include "v8.h"
39 #include "log.h" 38 #include "log.h"
40 #include "log-utils.h" 39 #include "log-utils.h"
41 #include "cpu-profiler.h" 40 #include "cpu-profiler.h"
42 #include "natives.h" 41 #include "natives.h"
43 #include "v8threads.h" 42 #include "v8threads.h"
44 #include "v8utils.h" 43 #include "v8utils.h"
45 #include "cctest.h" 44 #include "cctest.h"
46 #include "vm-state-inl.h" 45 #include "vm-state-inl.h"
47 #undef V8_DISABLE_DEPRECATIONS
48 46
49 using v8::internal::Address; 47 using v8::internal::Address;
50 using v8::internal::EmbeddedVector; 48 using v8::internal::EmbeddedVector;
51 using v8::internal::Logger; 49 using v8::internal::Logger;
52 using v8::internal::StrLength; 50 using v8::internal::StrLength;
53 51
54 namespace { 52 namespace {
55 53
56 54
57 class ScopedLoggerInitializer { 55 class ScopedLoggerInitializer {
58 public: 56 public:
59 explicit ScopedLoggerInitializer(bool prof_lazy) 57 ScopedLoggerInitializer()
60 : saved_log_(i::FLAG_log), 58 : saved_log_(i::FLAG_log),
61 saved_prof_lazy_(i::FLAG_prof_lazy),
62 saved_prof_(i::FLAG_prof), 59 saved_prof_(i::FLAG_prof),
63 temp_file_(NULL), 60 temp_file_(NULL),
64 // Need to run this prior to creating the scope. 61 // Need to run this prior to creating the scope.
65 trick_to_run_init_flags_(init_flags_(prof_lazy)), 62 trick_to_run_init_flags_(init_flags_()),
66 scope_(v8::Isolate::GetCurrent()), 63 scope_(v8::Isolate::GetCurrent()),
67 env_(v8::Context::New(v8::Isolate::GetCurrent())), 64 env_(v8::Context::New(v8::Isolate::GetCurrent())),
68 logger_(i::Isolate::Current()->logger()) { 65 logger_(i::Isolate::Current()->logger()) {
69 env_->Enter(); 66 env_->Enter();
70 } 67 }
71 68
72 ~ScopedLoggerInitializer() { 69 ~ScopedLoggerInitializer() {
73 env_->Exit(); 70 env_->Exit();
74 logger_->TearDown(); 71 logger_->TearDown();
75 if (temp_file_ != NULL) fclose(temp_file_); 72 if (temp_file_ != NULL) fclose(temp_file_);
76 i::FLAG_prof_lazy = saved_prof_lazy_;
77 i::FLAG_prof = saved_prof_; 73 i::FLAG_prof = saved_prof_;
78 i::FLAG_log = saved_log_; 74 i::FLAG_log = saved_log_;
79 } 75 }
80 76
81 v8::Handle<v8::Context>& env() { return env_; } 77 v8::Handle<v8::Context>& env() { return env_; }
82 78
83 Logger* logger() { return logger_; } 79 Logger* logger() { return logger_; }
84 80
85 FILE* StopLoggingGetTempFile() { 81 FILE* StopLoggingGetTempFile() {
86 temp_file_ = logger_->TearDown(); 82 temp_file_ = logger_->TearDown();
87 CHECK_NE(NULL, temp_file_); 83 CHECK_NE(NULL, temp_file_);
88 fflush(temp_file_); 84 fflush(temp_file_);
89 rewind(temp_file_); 85 rewind(temp_file_);
90 return temp_file_; 86 return temp_file_;
91 } 87 }
92 88
93 private: 89 private:
94 static bool init_flags_(bool prof_lazy) { 90 static bool init_flags_() {
95 i::FLAG_log = true; 91 i::FLAG_log = true;
96 i::FLAG_prof = true; 92 i::FLAG_prof = true;
97 i::FLAG_prof_lazy = prof_lazy;
98 i::FLAG_logfile = i::Log::kLogToTemporaryFile; 93 i::FLAG_logfile = i::Log::kLogToTemporaryFile;
99 return prof_lazy; 94 return false;
100 } 95 }
101 96
102 const bool saved_log_; 97 const bool saved_log_;
103 const bool saved_prof_lazy_;
104 const bool saved_prof_; 98 const bool saved_prof_;
105 FILE* temp_file_; 99 FILE* temp_file_;
106 const bool trick_to_run_init_flags_; 100 const bool trick_to_run_init_flags_;
107 v8::HandleScope scope_; 101 v8::HandleScope scope_;
108 v8::Handle<v8::Context> env_; 102 v8::Handle<v8::Context> env_;
109 Logger* logger_; 103 Logger* logger_;
110 104
111 DISALLOW_COPY_AND_ASSIGN(ScopedLoggerInitializer); 105 DISALLOW_COPY_AND_ASSIGN(ScopedLoggerInitializer);
112 }; 106 };
113 107
114 } // namespace 108 } // namespace
115 109
116 110
117 static const char* StrNStr(const char* s1, const char* s2, int n) { 111 static const char* StrNStr(const char* s1, const char* s2, int n) {
118 if (s1[n] == '\0') return strstr(s1, s2); 112 if (s1[n] == '\0') return strstr(s1, s2);
119 i::ScopedVector<char> str(n + 1); 113 i::ScopedVector<char> str(n + 1);
120 i::OS::StrNCpy(str, s1, static_cast<size_t>(n)); 114 i::OS::StrNCpy(str, s1, static_cast<size_t>(n));
121 str[n] = '\0'; 115 str[n] = '\0';
122 char* found = strstr(str.start(), s2); 116 char* found = strstr(str.start(), s2);
123 return found != NULL ? s1 + (found - str.start()) : NULL; 117 return found != NULL ? s1 + (found - str.start()) : NULL;
124 } 118 }
125 119
126 120
127 TEST(ProfLazyMode) {
128 ScopedLoggerInitializer initialize_logger(true);
129 Logger* logger = initialize_logger.logger();
130
131 if (!i::V8::UseCrankshaft()) return;
132
133 logger->StringEvent("test-start", "");
134 CompileRun("var a = (function(x) { return x + 1; })(10);");
135 logger->StringEvent("test-profiler-start", "");
136 v8::V8::ResumeProfiler();
137 CompileRun(
138 "var b = (function(x) { return x + 2; })(10);\n"
139 "var c = (function(x) { return x + 3; })(10);\n"
140 "var d = (function(x) { return x + 4; })(10);\n"
141 "var e = (function(x) { return x + 5; })(10);");
142 v8::V8::PauseProfiler();
143 logger->StringEvent("test-profiler-stop", "");
144 CompileRun("var f = (function(x) { return x + 6; })(10);");
145 // Check that profiling can be resumed again.
146 logger->StringEvent("test-profiler-start-2", "");
147 v8::V8::ResumeProfiler();
148 CompileRun(
149 "var g = (function(x) { return x + 7; })(10);\n"
150 "var h = (function(x) { return x + 8; })(10);\n"
151 "var i = (function(x) { return x + 9; })(10);\n"
152 "var j = (function(x) { return x + 10; })(10);");
153 v8::V8::PauseProfiler();
154 logger->StringEvent("test-profiler-stop-2", "");
155 logger->StringEvent("test-stop", "");
156
157 bool exists = false;
158 i::Vector<const char> log(
159 i::ReadFile(initialize_logger.StopLoggingGetTempFile(), &exists, true));
160 CHECK(exists);
161
162 const char* test_start_position =
163 StrNStr(log.start(), "test-start,", log.length());
164 CHECK_NE(NULL, test_start_position);
165 const char* test_profiler_start_position =
166 StrNStr(log.start(), "test-profiler-start,", log.length());
167 CHECK_NE(NULL, test_profiler_start_position);
168 CHECK_GT(test_profiler_start_position, test_start_position);
169 const char* test_profiler_stop_position =
170 StrNStr(log.start(), "test-profiler-stop,", log.length());
171 CHECK_NE(NULL, test_profiler_stop_position);
172 CHECK_GT(test_profiler_stop_position, test_profiler_start_position);
173 const char* test_profiler_start_2_position =
174 StrNStr(log.start(), "test-profiler-start-2,", log.length());
175 CHECK_NE(NULL, test_profiler_start_2_position);
176 CHECK_GT(test_profiler_start_2_position, test_profiler_stop_position);
177
178 // Nothing must be logged until profiling is resumed.
179 CHECK_EQ(NULL, StrNStr(test_start_position,
180 "code-creation,",
181 static_cast<int>(test_profiler_start_position -
182 test_start_position)));
183 // Nothing must be logged while profiling is suspended.
184 CHECK_EQ(NULL, StrNStr(test_profiler_stop_position,
185 "code-creation,",
186 static_cast<int>(test_profiler_start_2_position -
187 test_profiler_stop_position)));
188 }
189
190
191 // BUG(913). Need to implement support for profiling multiple VM threads. 121 // BUG(913). Need to implement support for profiling multiple VM threads.
192 #if 0 122 #if 0
193 123
194 namespace { 124 namespace {
195 125
196 class LoopingThread : public v8::internal::Thread { 126 class LoopingThread : public v8::internal::Thread {
197 public: 127 public:
198 explicit LoopingThread(v8::internal::Isolate* isolate) 128 explicit LoopingThread(v8::internal::Isolate* isolate)
199 : v8::internal::Thread(isolate), 129 : v8::internal::Thread(isolate),
200 semaphore_(v8::internal::OS::CreateSemaphore(0)), 130 semaphore_(v8::internal::OS::CreateSemaphore(0)),
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 // Must not crash. 319 // Must not crash.
390 i::Isolate::Current()->logger()->LogCompiledFunctions(); 320 i::Isolate::Current()->logger()->LogCompiledFunctions();
391 } 321 }
392 322
393 323
394 static void ObjMethod1(const v8::FunctionCallbackInfo<v8::Value>& args) { 324 static void ObjMethod1(const v8::FunctionCallbackInfo<v8::Value>& args) {
395 } 325 }
396 326
397 327
398 TEST(LogCallbacks) { 328 TEST(LogCallbacks) {
399 ScopedLoggerInitializer initialize_logger(false); 329 ScopedLoggerInitializer initialize_logger;
400 Logger* logger = initialize_logger.logger(); 330 Logger* logger = initialize_logger.logger();
401 331
402 v8::Local<v8::FunctionTemplate> obj = 332 v8::Local<v8::FunctionTemplate> obj =
403 v8::Local<v8::FunctionTemplate>::New(v8::Isolate::GetCurrent(), 333 v8::Local<v8::FunctionTemplate>::New(v8::Isolate::GetCurrent(),
404 v8::FunctionTemplate::New()); 334 v8::FunctionTemplate::New());
405 obj->SetClassName(v8_str("Obj")); 335 obj->SetClassName(v8_str("Obj"));
406 v8::Handle<v8::ObjectTemplate> proto = obj->PrototypeTemplate(); 336 v8::Handle<v8::ObjectTemplate> proto = obj->PrototypeTemplate();
407 v8::Local<v8::Signature> signature = v8::Signature::New(obj); 337 v8::Local<v8::Signature> signature = v8::Signature::New(obj);
408 proto->Set(v8_str("method1"), 338 proto->Set(v8_str("method1"),
409 v8::FunctionTemplate::New(ObjMethod1, 339 v8::FunctionTemplate::New(ObjMethod1,
(...skipping 28 matching lines...) Expand all
438 v8::Local<v8::Value> value, 368 v8::Local<v8::Value> value,
439 const v8::PropertyCallbackInfo<void>& info) { 369 const v8::PropertyCallbackInfo<void>& info) {
440 } 370 }
441 371
442 static void Prop2Getter(v8::Local<v8::String> property, 372 static void Prop2Getter(v8::Local<v8::String> property,
443 const v8::PropertyCallbackInfo<v8::Value>& info) { 373 const v8::PropertyCallbackInfo<v8::Value>& info) {
444 } 374 }
445 375
446 376
447 TEST(LogAccessorCallbacks) { 377 TEST(LogAccessorCallbacks) {
448 ScopedLoggerInitializer initialize_logger(false); 378 ScopedLoggerInitializer initialize_logger;
449 Logger* logger = initialize_logger.logger(); 379 Logger* logger = initialize_logger.logger();
450 380
451 v8::Local<v8::FunctionTemplate> obj = 381 v8::Local<v8::FunctionTemplate> obj =
452 v8::Local<v8::FunctionTemplate>::New(v8::Isolate::GetCurrent(), 382 v8::Local<v8::FunctionTemplate>::New(v8::Isolate::GetCurrent(),
453 v8::FunctionTemplate::New()); 383 v8::FunctionTemplate::New());
454 obj->SetClassName(v8_str("Obj")); 384 obj->SetClassName(v8_str("Obj"));
455 v8::Handle<v8::ObjectTemplate> inst = obj->InstanceTemplate(); 385 v8::Handle<v8::ObjectTemplate> inst = obj->InstanceTemplate();
456 inst->SetAccessor(v8_str("prop1"), Prop1Getter, Prop1Setter); 386 inst->SetAccessor(v8_str("prop1"), Prop1Getter, Prop1Setter);
457 inst->SetAccessor(v8_str("prop2"), Prop2Getter); 387 inst->SetAccessor(v8_str("prop2"), Prop2Getter);
458 388
(...skipping 20 matching lines...) Expand all
479 409
480 EmbeddedVector<char, 100> prop2_getter_record; 410 EmbeddedVector<char, 100> prop2_getter_record;
481 i::OS::SNPrintF(prop2_getter_record, 411 i::OS::SNPrintF(prop2_getter_record,
482 "code-creation,Callback,-2,0x%" V8PRIxPTR ",1,\"get prop2\"", 412 "code-creation,Callback,-2,0x%" V8PRIxPTR ",1,\"get prop2\"",
483 Prop2Getter); 413 Prop2Getter);
484 CHECK_NE(NULL, 414 CHECK_NE(NULL,
485 StrNStr(log.start(), prop2_getter_record.start(), log.length())); 415 StrNStr(log.start(), prop2_getter_record.start(), log.length()));
486 } 416 }
487 417
488 418
489 TEST(IsLoggingPreserved) {
490 ScopedLoggerInitializer initialize_logger(false);
491 Logger* logger = initialize_logger.logger();
492
493 CHECK(logger->is_logging());
494 logger->ResumeProfiler();
495 CHECK(logger->is_logging());
496 logger->PauseProfiler();
497 CHECK(logger->is_logging());
498 }
499
500
501 typedef i::NativesCollection<i::TEST> TestSources; 419 typedef i::NativesCollection<i::TEST> TestSources;
502 420
503 421
504 // Test that logging of code create / move events is equivalent to traversal of 422 // Test that logging of code create / move events is equivalent to traversal of
505 // a resulting heap. 423 // a resulting heap.
506 TEST(EquivalenceOfLoggingAndTraversal) { 424 TEST(EquivalenceOfLoggingAndTraversal) {
507 // This test needs to be run on a "clean" V8 to ensure that snapshot log 425 // This test needs to be run on a "clean" V8 to ensure that snapshot log
508 // is loaded. This is always true when running using tools/test.py because 426 // is loaded. This is always true when running using tools/test.py because
509 // it launches a new cctest instance for every test. To be sure that launching 427 // it launches a new cctest instance for every test. To be sure that launching
510 // cctest manually also works, please be sure that no tests below 428 // cctest manually also works, please be sure that no tests below
511 // are using V8. 429 // are using V8.
512 // 430 //
513 // P.S. No, V8 can't be re-initialized after disposal, see include/v8.h. 431 // P.S. No, V8 can't be re-initialized after disposal, see include/v8.h.
514 CHECK(!i::V8::IsRunning()); 432 CHECK(!i::V8::IsRunning());
515 433
516 // Start with profiling to capture all code events from the beginning. 434 // Start with profiling to capture all code events from the beginning.
517 ScopedLoggerInitializer initialize_logger(false); 435 ScopedLoggerInitializer initialize_logger;
518 Logger* logger = initialize_logger.logger(); 436 Logger* logger = initialize_logger.logger();
519 437
520 // Compile and run a function that creates other functions. 438 // Compile and run a function that creates other functions.
521 CompileRun( 439 CompileRun(
522 "(function f(obj) {\n" 440 "(function f(obj) {\n"
523 " obj.test =\n" 441 " obj.test =\n"
524 " (function a(j) { return function b() { return j; } })(100);\n" 442 " (function a(j) { return function b() { return j; } })(100);\n"
525 "})(this);"); 443 "})(this);");
526 v8::V8::PauseProfiler(); 444 logger->StopProfiler();
527 HEAP->CollectAllGarbage(i::Heap::kMakeHeapIterableMask); 445 HEAP->CollectAllGarbage(i::Heap::kMakeHeapIterableMask);
528 logger->StringEvent("test-logging-done", ""); 446 logger->StringEvent("test-logging-done", "");
529 447
530 // Iterate heap to find compiled functions, will write to log. 448 // Iterate heap to find compiled functions, will write to log.
531 logger->LogCompiledFunctions(); 449 logger->LogCompiledFunctions();
532 logger->StringEvent("test-traversal-done", ""); 450 logger->StringEvent("test-traversal-done", "");
533 451
534 bool exists = false; 452 bool exists = false;
535 i::Vector<const char> log( 453 i::Vector<const char> log(
536 i::ReadFile(initialize_logger.StopLoggingGetTempFile(), &exists, true)); 454 i::ReadFile(initialize_logger.StopLoggingGetTempFile(), &exists, true));
(...skipping 22 matching lines...) Expand all
559 v8::Local<v8::String> s = result->ToString(); 477 v8::Local<v8::String> s = result->ToString();
560 i::ScopedVector<char> data(s->Utf8Length() + 1); 478 i::ScopedVector<char> data(s->Utf8Length() + 1);
561 CHECK_NE(NULL, data.start()); 479 CHECK_NE(NULL, data.start());
562 s->WriteUtf8(data.start()); 480 s->WriteUtf8(data.start());
563 printf("%s\n", data.start()); 481 printf("%s\n", data.start());
564 // Make sure that our output is written prior crash due to CHECK failure. 482 // Make sure that our output is written prior crash due to CHECK failure.
565 fflush(stdout); 483 fflush(stdout);
566 CHECK(false); 484 CHECK(false);
567 } 485 }
568 } 486 }
OLDNEW
« no previous file with comments | « src/log-utils.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698