OLD | NEW |
---|---|
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 the V8 project authors. All rights reserved. |
2 // | 2 // |
3 // Tests of logging functions from log.h | 3 // Tests of logging functions from log.h |
4 | 4 |
5 #ifdef ENABLE_LOGGING_AND_PROFILING | 5 #ifdef ENABLE_LOGGING_AND_PROFILING |
6 | 6 |
7 #include "v8.h" | 7 #include "v8.h" |
8 | 8 |
9 #include "log.h" | 9 #include "log.h" |
10 #include "cctest.h" | 10 #include "cctest.h" |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
137 public: | 137 public: |
138 static bool IsSamplerActive() { return Logger::IsProfilerSamplerActive(); } | 138 static bool IsSamplerActive() { return Logger::IsProfilerSamplerActive(); } |
139 }; | 139 }; |
140 | 140 |
141 } // namespace v8::internal | 141 } // namespace v8::internal |
142 } // namespace v8 | 142 } // namespace v8 |
143 | 143 |
144 using v8::internal::LoggerTestHelper; | 144 using v8::internal::LoggerTestHelper; |
145 | 145 |
146 | 146 |
147 // Under Linux, we need to check if signals were delivered to avoid false | |
148 // positives. Under other platforms profiling is done via a high-priority | |
149 // thread, so this case never happen. | |
150 static bool was_sigprof_received = true; | |
Søren Thygesen Gjesse
2009/07/28 08:12:37
Maybe move this down to 'struct sigaction old_sigp
Mikhail Naganov
2009/07/28 08:34:15
This will add another 'ifdef' branch around lines
| |
151 #ifdef __linux__ | |
152 | |
153 #include <signal.h> | |
154 #include <unistd.h> | |
155 | |
156 struct sigaction old_sigprof_handler; | |
157 | |
158 static void SigProfSignalHandler(int signal, siginfo_t* info, void* context) { | |
159 if (signal != SIGPROF) return; | |
160 was_sigprof_received = true; | |
161 old_sigprof_handler.sa_sigaction(signal, info, context); | |
162 } | |
163 | |
164 #endif // __linux__ | |
165 | |
166 | |
147 static int CheckThatProfilerWorks(int log_pos) { | 167 static int CheckThatProfilerWorks(int log_pos) { |
148 Logger::ResumeProfiler(); | 168 Logger::ResumeProfiler(); |
149 CHECK(LoggerTestHelper::IsSamplerActive()); | 169 CHECK(LoggerTestHelper::IsSamplerActive()); |
150 | 170 |
151 // Verify that the current map of compiled functions has been logged. | 171 // Verify that the current map of compiled functions has been logged. |
152 EmbeddedVector<char, 102400> buffer; | 172 EmbeddedVector<char, 102400> buffer; |
153 int map_log_size = GetLogLines(log_pos, &buffer); | 173 int map_log_size = GetLogLines(log_pos, &buffer); |
154 printf("map_log_size: %d\n", map_log_size); | 174 printf("map_log_size: %d\n", map_log_size); |
155 CHECK_GT(map_log_size, 0); | 175 CHECK_GT(map_log_size, 0); |
156 CHECK_GT(buffer.length(), map_log_size); | 176 CHECK_GT(buffer.length(), map_log_size); |
157 log_pos += map_log_size; | 177 log_pos += map_log_size; |
158 // Check buffer contents. | 178 // Check buffer contents. |
159 buffer[map_log_size] = '\0'; | 179 buffer[map_log_size] = '\0'; |
160 const char* code_creation = "\ncode-creation,"; // eq. to /^code-creation,/ | 180 const char* code_creation = "\ncode-creation,"; // eq. to /^code-creation,/ |
161 CHECK_NE(NULL, strstr(buffer.start(), code_creation)); | 181 CHECK_NE(NULL, strstr(buffer.start(), code_creation)); |
162 | 182 |
183 #ifdef __linux__ | |
184 // Intercept SIGPROF handler to make sure that the test process | |
185 // had received it. Under load, system can defer it causing test failure. | |
186 // It is important to execute this after 'ResumeProfiler'. | |
187 was_sigprof_received = false; | |
188 struct sigaction sa; | |
189 sa.sa_sigaction = SigProfSignalHandler; | |
190 sigemptyset(&sa.sa_mask); | |
191 sa.sa_flags = SA_SIGINFO; | |
192 CHECK_EQ(0, sigaction(SIGPROF, &sa, &old_sigprof_handler)); | |
193 #endif // __linux__ | |
194 | |
163 // Force compiler to generate new code by parametrizing source. | 195 // Force compiler to generate new code by parametrizing source. |
164 EmbeddedVector<char, 100> script_src; | 196 EmbeddedVector<char, 100> script_src; |
165 i::OS::SNPrintF(script_src, | 197 i::OS::SNPrintF(script_src, |
166 "for (var i = 0; i < 1000; ++i) { " | 198 "for (var i = 0; i < 1000; ++i) { " |
167 "(function(x) { return %d * x; })(i); }", | 199 "(function(x) { return %d * x; })(i); }", |
168 log_pos); | 200 log_pos); |
169 // Run code for 200 msecs to get some ticks. | 201 // Run code for 200 msecs to get some ticks. |
170 const double end_time = i::OS::TimeCurrentMillis() + 200; | 202 const double end_time = i::OS::TimeCurrentMillis() + 200; |
171 while (i::OS::TimeCurrentMillis() < end_time) { | 203 while (i::OS::TimeCurrentMillis() < end_time) { |
172 CompileAndRunScript(script_src.start()); | 204 CompileAndRunScript(script_src.start()); |
205 // Yield CPU to give Profiler thread a chance to process ticks. | |
206 i::OS::Sleep(1); | |
173 } | 207 } |
174 | 208 |
175 Logger::PauseProfiler(); | 209 Logger::PauseProfiler(); |
176 CHECK(!LoggerTestHelper::IsSamplerActive()); | 210 CHECK(!LoggerTestHelper::IsSamplerActive()); |
177 | 211 |
178 // Wait 50 msecs to allow Profiler thread to process the last | 212 // Wait 50 msecs to allow Profiler thread to process the last |
179 // tick sample it has got. | 213 // tick sample it has got. |
180 i::OS::Sleep(50); | 214 i::OS::Sleep(50); |
181 | 215 |
182 // Now we must have compiler and tick records. | 216 // Now we must have compiler and tick records. |
183 int log_size = GetLogLines(log_pos, &buffer); | 217 int log_size = GetLogLines(log_pos, &buffer); |
184 printf("log_size: %d\n", log_size); | 218 printf("log_size: %d\n", log_size); |
185 CHECK_GT(log_size, 0); | 219 CHECK_GT(log_size, 0); |
186 CHECK_GT(buffer.length(), log_size); | 220 CHECK_GT(buffer.length(), log_size); |
187 log_pos += log_size; | 221 log_pos += log_size; |
188 // Check buffer contents. | 222 // Check buffer contents. |
189 buffer[log_size] = '\0'; | 223 buffer[log_size] = '\0'; |
190 const char* tick = "\ntick,"; | 224 const char* tick = "\ntick,"; |
191 CHECK_NE(NULL, strstr(buffer.start(), code_creation)); | 225 CHECK_NE(NULL, strstr(buffer.start(), code_creation)); |
192 CHECK_NE(NULL, strstr(buffer.start(), tick)); | 226 const bool ticks_found = strstr(buffer.start(), tick) != NULL; |
227 CHECK_EQ(was_sigprof_received, ticks_found); | |
193 | 228 |
194 return log_pos; | 229 return log_pos; |
195 } | 230 } |
196 | 231 |
197 | 232 |
198 TEST(ProfLazyMode) { | 233 TEST(ProfLazyMode) { |
199 const bool saved_prof_lazy = i::FLAG_prof_lazy; | 234 const bool saved_prof_lazy = i::FLAG_prof_lazy; |
200 const bool saved_prof = i::FLAG_prof; | 235 const bool saved_prof = i::FLAG_prof; |
201 const bool saved_prof_auto = i::FLAG_prof_auto; | 236 const bool saved_prof_auto = i::FLAG_prof_auto; |
202 i::FLAG_prof = true; | 237 i::FLAG_prof = true; |
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
703 // Make sure that all log data is written prior crash due to CHECK failure. | 738 // Make sure that all log data is written prior crash due to CHECK failure. |
704 fflush(stdout); | 739 fflush(stdout); |
705 CHECK(results_equal); | 740 CHECK(results_equal); |
706 | 741 |
707 env->Exit(); | 742 env->Exit(); |
708 Logger::TearDown(); | 743 Logger::TearDown(); |
709 i::FLAG_always_compact = saved_always_compact; | 744 i::FLAG_always_compact = saved_always_compact; |
710 } | 745 } |
711 | 746 |
712 #endif // ENABLE_LOGGING_AND_PROFILING | 747 #endif // ENABLE_LOGGING_AND_PROFILING |
OLD | NEW |