Avi Drissman | 05dfbc82 | 2022-09-13 21:25:34 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors |
kloveless@chromium.org | 1d82e82 | 2013-04-10 21:32:32 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "gpu/command_buffer/service/logger.h" |
| 6 | |
| 7 | #include "base/command_line.h" |
| 8 | #include "base/logging.h" |
avi@chromium.org | f439096 | 2013-06-11 07:29:22 | [diff] [blame] | 9 | #include "base/strings/string_number_conversions.h" |
kloveless@chromium.org | 1d82e82 | 2013-04-10 21:32:32 | [diff] [blame] | 10 | #include "gpu/command_buffer/common/debug_marker_manager.h" |
| 11 | #include "gpu/command_buffer/service/gpu_switches.h" |
| 12 | |
| 13 | namespace gpu { |
| 14 | namespace gles2 { |
| 15 | |
Antoine Labour | f679fa4 | 2017-06-07 00:32:43 | [diff] [blame] | 16 | Logger::Logger(const DebugMarkerManager* debug_marker_manager, |
James Darpinian | 104af6f | 2018-12-06 03:24:55 | [diff] [blame] | 17 | const LogMessageCallback& callback, |
| 18 | bool disable_gl_error_limit) |
kloveless@chromium.org | 1d82e82 | 2013-04-10 21:32:32 | [diff] [blame] | 19 | : debug_marker_manager_(debug_marker_manager), |
Peng Huang | 61eccfe4 | 2018-11-15 22:10:13 | [diff] [blame] | 20 | log_message_callback_(callback), |
kloveless@chromium.org | 1d82e82 | 2013-04-10 21:32:32 | [diff] [blame] | 21 | log_message_count_(0), |
James Darpinian | 104af6f | 2018-12-06 03:24:55 | [diff] [blame] | 22 | log_synthesized_gl_errors_(true), |
| 23 | disable_gl_error_limit_(disable_gl_error_limit) { |
kloveless@chromium.org | 1d82e82 | 2013-04-10 21:32:32 | [diff] [blame] | 24 | Logger* this_temp = this; |
gman@chromium.org | 40de851 | 2013-05-28 20:15:00 | [diff] [blame] | 25 | this_in_hex_ = std::string("GroupMarkerNotSet(crbug.com/242999)!:") + |
| 26 | base::HexEncode(&this_temp, sizeof(this_temp)); |
Saifuddin Hitawala | e608efe6 | 2024-11-14 00:17:49 | [diff] [blame] | 27 | suppress_performance_logs_ = |
| 28 | base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 29 | switches::kSuppressPerformanceLogs); |
kloveless@chromium.org | 1d82e82 | 2013-04-10 21:32:32 | [diff] [blame] | 30 | } |
| 31 | |
Chris Watkins | 8103077 | 2017-12-07 01:20:56 | [diff] [blame] | 32 | Logger::~Logger() = default; |
kloveless@chromium.org | 1d82e82 | 2013-04-10 21:32:32 | [diff] [blame] | 33 | |
| 34 | void Logger::LogMessage( |
| 35 | const char* filename, int line, const std::string& msg) { |
James Darpinian | 104af6f | 2018-12-06 03:24:55 | [diff] [blame] | 36 | if (log_message_count_ < kMaxLogMessages || disable_gl_error_limit_) { |
gman@chromium.org | 40de851 | 2013-05-28 20:15:00 | [diff] [blame] | 37 | std::string prefixed_msg(std::string("[") + GetLogPrefix() + "]" + msg); |
kloveless@chromium.org | 1d82e82 | 2013-04-10 21:32:32 | [diff] [blame] | 38 | ++log_message_count_; |
| 39 | // LOG this unless logging is turned off as any chromium code that |
| 40 | // generates these errors probably has a bug. |
| 41 | if (log_synthesized_gl_errors_) { |
Peter BostrΓΆm | 9c202bb | 2024-01-05 05:33:06 | [diff] [blame] | 42 | ::logging::LogMessage(filename, line, ::logging::LOGGING_ERROR).stream() |
| 43 | << prefixed_msg; |
kloveless@chromium.org | 1d82e82 | 2013-04-10 21:32:32 | [diff] [blame] | 44 | } |
Peng Huang | 61eccfe4 | 2018-11-15 22:10:13 | [diff] [blame] | 45 | log_message_callback_.Run(prefixed_msg); |
kloveless@chromium.org | 1d82e82 | 2013-04-10 21:32:32 | [diff] [blame] | 46 | } else { |
| 47 | if (log_message_count_ == kMaxLogMessages) { |
| 48 | ++log_message_count_; |
| 49 | LOG(ERROR) |
| 50 | << "Too many GL errors, not reporting any more for this context." |
| 51 | << " use --disable-gl-error-limit to see all errors."; |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | const std::string& Logger::GetLogPrefix() const { |
| 57 | const std::string& prefix(debug_marker_manager_->GetMarker()); |
| 58 | return prefix.empty() ? this_in_hex_ : prefix; |
| 59 | } |
| 60 | |
Saifuddin Hitawala | e608efe6 | 2024-11-14 00:17:49 | [diff] [blame] | 61 | bool Logger::SuppressPerformanceLogs() const { |
| 62 | return suppress_performance_logs_; |
| 63 | } |
| 64 | |
kloveless@chromium.org | 1d82e82 | 2013-04-10 21:32:32 | [diff] [blame] | 65 | } // namespace gles2 |
| 66 | } // namespace gpu |