blob: aacbd210da0e8402de161d7671c470f08ed6caf5 [file] [log] [blame]
Avi Drissman05dfbc822022-09-13 21:25:341// Copyright 2013 The Chromium Authors
kloveless@chromium.org1d82e822013-04-10 21:32:322// 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.orgf4390962013-06-11 07:29:229#include "base/strings/string_number_conversions.h"
kloveless@chromium.org1d82e822013-04-10 21:32:3210#include "gpu/command_buffer/common/debug_marker_manager.h"
11#include "gpu/command_buffer/service/gpu_switches.h"
12
13namespace gpu {
14namespace gles2 {
15
Antoine Labourf679fa42017-06-07 00:32:4316Logger::Logger(const DebugMarkerManager* debug_marker_manager,
James Darpinian104af6f2018-12-06 03:24:5517 const LogMessageCallback& callback,
18 bool disable_gl_error_limit)
kloveless@chromium.org1d82e822013-04-10 21:32:3219 : debug_marker_manager_(debug_marker_manager),
Peng Huang61eccfe42018-11-15 22:10:1320 log_message_callback_(callback),
kloveless@chromium.org1d82e822013-04-10 21:32:3221 log_message_count_(0),
James Darpinian104af6f2018-12-06 03:24:5522 log_synthesized_gl_errors_(true),
23 disable_gl_error_limit_(disable_gl_error_limit) {
kloveless@chromium.org1d82e822013-04-10 21:32:3224 Logger* this_temp = this;
gman@chromium.org40de8512013-05-28 20:15:0025 this_in_hex_ = std::string("GroupMarkerNotSet(crbug.com/242999)!:") +
26 base::HexEncode(&this_temp, sizeof(this_temp));
Saifuddin Hitawalae608efe62024-11-14 00:17:4927 suppress_performance_logs_ =
28 base::CommandLine::ForCurrentProcess()->HasSwitch(
29 switches::kSuppressPerformanceLogs);
kloveless@chromium.org1d82e822013-04-10 21:32:3230}
31
Chris Watkins81030772017-12-07 01:20:5632Logger::~Logger() = default;
kloveless@chromium.org1d82e822013-04-10 21:32:3233
34void Logger::LogMessage(
35 const char* filename, int line, const std::string& msg) {
James Darpinian104af6f2018-12-06 03:24:5536 if (log_message_count_ < kMaxLogMessages || disable_gl_error_limit_) {
gman@chromium.org40de8512013-05-28 20:15:0037 std::string prefixed_msg(std::string("[") + GetLogPrefix() + "]" + msg);
kloveless@chromium.org1d82e822013-04-10 21:32:3238 ++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ΓΆm9c202bb2024-01-05 05:33:0642 ::logging::LogMessage(filename, line, ::logging::LOGGING_ERROR).stream()
43 << prefixed_msg;
kloveless@chromium.org1d82e822013-04-10 21:32:3244 }
Peng Huang61eccfe42018-11-15 22:10:1345 log_message_callback_.Run(prefixed_msg);
kloveless@chromium.org1d82e822013-04-10 21:32:3246 } 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
56const 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 Hitawalae608efe62024-11-14 00:17:4961bool Logger::SuppressPerformanceLogs() const {
62 return suppress_performance_logs_;
63}
64
kloveless@chromium.org1d82e822013-04-10 21:32:3265} // namespace gles2
66} // namespace gpu