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

Side by Side Diff: src/log.cc

Issue 113762: Implement resource-saving mode of Profiler. (Closed)
Patch Set: Patch set 2 was screwed, this is the good one. Created 11 years, 7 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
OLDNEW
1 // Copyright 2009 the V8 project authors. All rights reserved. 1 // Copyright 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
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 ~Ticker() { if (IsActive()) Stop(); } 171 ~Ticker() { if (IsActive()) Stop(); }
172 172
173 void Tick(TickSample* sample) { 173 void Tick(TickSample* sample) {
174 if (IsProfiling()) stack_tracer_.Trace(sample); 174 if (IsProfiling()) stack_tracer_.Trace(sample);
175 if (profiler_) profiler_->Insert(sample); 175 if (profiler_) profiler_->Insert(sample);
176 if (window_) window_->AddState(sample->state); 176 if (window_) window_->AddState(sample->state);
177 } 177 }
178 178
179 void SetWindow(SlidingStateWindow* window) { 179 void SetWindow(SlidingStateWindow* window) {
180 window_ = window; 180 window_ = window;
181 if (!IsActive()) Start(); 181 if (!FLAG_prof_lazy && !IsActive()) Start();
Søren Thygesen Gjesse 2009/05/25 07:09:15 I am not sure about this handling of the prof_lazy
Mikhail Naganov 2009/05/25 08:23:43 That's an important thing to know, thanks for noti
182 } 182 }
183 183
184 void ClearWindow() { 184 void ClearWindow() {
185 window_ = NULL; 185 window_ = NULL;
186 if (!profiler_ && IsActive()) Stop(); 186 if (!profiler_ && IsActive()) Stop();
187 } 187 }
188 188
189 void SetProfiler(Profiler* profiler) { 189 void SetProfiler(Profiler* profiler) {
190 profiler_ = profiler; 190 profiler_ = profiler;
191 if (!IsActive()) Start(); 191 if (!FLAG_prof_lazy && !IsActive()) Start();
192 } 192 }
193 193
194 void ClearProfiler() { 194 void ClearProfiler() {
195 profiler_ = NULL; 195 profiler_ = NULL;
196 if (!window_ && IsActive()) Stop(); 196 if (!window_ && IsActive()) Stop();
197 } 197 }
198 198
199 private: 199 private:
200 SlidingStateWindow* window_; 200 SlidingStateWindow* window_;
201 Profiler* profiler_; 201 Profiler* profiler_;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 260
261 void Profiler::Disengage() { 261 void Profiler::Disengage() {
262 // Stop receiving ticks. 262 // Stop receiving ticks.
263 Logger::ticker_->ClearProfiler(); 263 Logger::ticker_->ClearProfiler();
264 264
265 // Terminate the worker thread by setting running_ to false, 265 // Terminate the worker thread by setting running_ to false,
266 // inserting a fake element in the queue and then wait for 266 // inserting a fake element in the queue and then wait for
267 // the thread to terminate. 267 // the thread to terminate.
268 running_ = false; 268 running_ = false;
269 TickSample sample; 269 TickSample sample;
270 // Reset 'paused_' flag, otherwise semaphore may not be signalled.
271 resume();
270 Insert(&sample); 272 Insert(&sample);
271 Join(); 273 Join();
272 274
273 LOG(UncheckedStringEvent("profiler", "end")); 275 LOG(UncheckedStringEvent("profiler", "end"));
274 } 276 }
275 277
276 278
277 void Profiler::Run() { 279 void Profiler::Run() {
278 TickSample sample; 280 TickSample sample;
279 bool overflow = Logger::profiler_->Remove(&sample); 281 bool overflow = Logger::profiler_->Remove(&sample);
(...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after
1089 } 1091 }
1090 1092
1091 1093
1092 bool Logger::IsProfilerPaused() { 1094 bool Logger::IsProfilerPaused() {
1093 return profiler_->paused(); 1095 return profiler_->paused();
1094 } 1096 }
1095 1097
1096 1098
1097 void Logger::PauseProfiler() { 1099 void Logger::PauseProfiler() {
1098 profiler_->pause(); 1100 profiler_->pause();
1101 if (FLAG_prof_lazy) {
1102 ticker_->Stop();
1103 FLAG_log_code = false;
1104 LOG(UncheckedStringEvent("profiler", "pause"));
1105 }
1099 } 1106 }
1100 1107
1101 1108
1102 void Logger::ResumeProfiler() { 1109 void Logger::ResumeProfiler() {
1110 if (FLAG_prof_lazy) {
1111 LOG(UncheckedStringEvent("profiler", "resume"));
1112 FLAG_log_code = true;
1113 LogCompiledFunctions();
1114 ticker_->Start();
1115 }
1103 profiler_->resume(); 1116 profiler_->resume();
1104 } 1117 }
1105 1118
1106 1119
1120 bool Logger::IsProfilerSamplerActive() {
1121 return ticker_->IsActive();
1122 }
1123
1124
1107 int Logger::GetLogLines(int from_pos, char* dest_buf, int max_size) { 1125 int Logger::GetLogLines(int from_pos, char* dest_buf, int max_size) {
1108 return Log::GetLogLines(from_pos, dest_buf, max_size); 1126 return Log::GetLogLines(from_pos, dest_buf, max_size);
1109 } 1127 }
1110 1128
1111 1129
1112 void Logger::LogCompiledFunctions() { 1130 void Logger::LogCompiledFunctions() {
1113 HandleScope scope; 1131 HandleScope scope;
1114 Handle<SharedFunctionInfo>* sfis = NULL; 1132 Handle<SharedFunctionInfo>* sfis = NULL;
1115 int compiled_funcs_count = 0; 1133 int compiled_funcs_count = 0;
1116 1134
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1183 FLAG_log_code = true; 1201 FLAG_log_code = true;
1184 FLAG_log_gc = true; 1202 FLAG_log_gc = true;
1185 FLAG_log_suspect = true; 1203 FLAG_log_suspect = true;
1186 FLAG_log_handles = true; 1204 FLAG_log_handles = true;
1187 FLAG_log_regexp = true; 1205 FLAG_log_regexp = true;
1188 } 1206 }
1189 1207
1190 // --prof implies --log-code. 1208 // --prof implies --log-code.
1191 if (FLAG_prof) FLAG_log_code = true; 1209 if (FLAG_prof) FLAG_log_code = true;
1192 1210
1211 // --prof_lazy controls --log-code, implies --noprof_auto.
1212 if (FLAG_prof_lazy) {
1213 FLAG_log_code = false;
1214 FLAG_prof_auto = false;
1215 }
1216
1193 bool open_log_file = FLAG_log || FLAG_log_runtime || FLAG_log_api 1217 bool open_log_file = FLAG_log || FLAG_log_runtime || FLAG_log_api
1194 || FLAG_log_code || FLAG_log_gc || FLAG_log_handles || FLAG_log_suspect 1218 || FLAG_log_code || FLAG_log_gc || FLAG_log_handles || FLAG_log_suspect
1195 || FLAG_log_regexp || FLAG_log_state_changes; 1219 || FLAG_log_regexp || FLAG_log_state_changes || FLAG_prof_lazy;
1196 1220
1197 // If we're logging anything, we need to open the log file. 1221 // If we're logging anything, we need to open the log file.
1198 if (open_log_file) { 1222 if (open_log_file) {
1199 if (strcmp(FLAG_logfile, "-") == 0) { 1223 if (strcmp(FLAG_logfile, "-") == 0) {
1200 Log::OpenStdout(); 1224 Log::OpenStdout();
1201 } else if (strcmp(FLAG_logfile, "*") == 0) { 1225 } else if (strcmp(FLAG_logfile, "*") == 0) {
1202 Log::OpenMemoryBuffer(); 1226 Log::OpenMemoryBuffer();
1203 } else if (strchr(FLAG_logfile, '%') != NULL) { 1227 } else if (strchr(FLAG_logfile, '%') != NULL) {
1204 // If there's a '%' in the log file name we have to expand 1228 // If there's a '%' in the log file name we have to expand
1205 // placeholders. 1229 // placeholders.
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1270 void Logger::TearDown() { 1294 void Logger::TearDown() {
1271 #ifdef ENABLE_LOGGING_AND_PROFILING 1295 #ifdef ENABLE_LOGGING_AND_PROFILING
1272 // Stop the profiler before closing the file. 1296 // Stop the profiler before closing the file.
1273 if (profiler_ != NULL) { 1297 if (profiler_ != NULL) {
1274 profiler_->Disengage(); 1298 profiler_->Disengage();
1275 delete profiler_; 1299 delete profiler_;
1276 profiler_ = NULL; 1300 profiler_ = NULL;
1277 } 1301 }
1278 1302
1279 delete sliding_state_window_; 1303 delete sliding_state_window_;
1304 sliding_state_window_ = NULL;
1280 1305
1281 delete ticker_; 1306 delete ticker_;
1307 ticker_ = NULL;
1282 1308
1283 Log::Close(); 1309 Log::Close();
1284 #endif 1310 #endif
1285 } 1311 }
1286 1312
1287 1313
1288 void Logger::EnableSlidingStateWindow() { 1314 void Logger::EnableSlidingStateWindow() {
1289 #ifdef ENABLE_LOGGING_AND_PROFILING 1315 #ifdef ENABLE_LOGGING_AND_PROFILING
1290 // If the ticker is NULL, Logger::Setup has not been called yet. In 1316 // If the ticker is NULL, Logger::Setup has not been called yet. In
1291 // that case, we set the sliding_state_window flag so that the 1317 // that case, we set the sliding_state_window flag so that the
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1379 } else if (previous_->state_ == EXTERNAL) { 1405 } else if (previous_->state_ == EXTERNAL) {
1380 // We are leaving V8. 1406 // We are leaving V8.
1381 Heap::Protect(); 1407 Heap::Protect();
1382 } 1408 }
1383 } 1409 }
1384 #endif 1410 #endif
1385 } 1411 }
1386 #endif 1412 #endif
1387 1413
1388 } } // namespace v8::internal 1414 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698