Skip to content

Commit

Permalink
Remove unused core dump handler code (#2192)
Browse files Browse the repository at this point in the history
b/289214111

Change-Id: If822f5879010dd4235c49c01f01a43b287652d68
  • Loading branch information
hlwarriner authored Jan 22, 2024
1 parent a341dc9 commit 61c20a2
Show file tree
Hide file tree
Showing 9 changed files with 4 additions and 299 deletions.
5 changes: 2 additions & 3 deletions cobalt/browser/application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -613,9 +613,8 @@ void AddCrashLogApplicationState(base::ApplicationState state) {
return;
}

// Crash handler is not supported, fallback to crash log dictionary.
h5vcc::CrashLogDictionary::GetInstance()->SetString("application_state",
application_state);
LOG(ERROR) << "Crash handler extension not implemented, at least not at the "
<< "required version, so not sending application state.";
}

} // namespace
Expand Down
43 changes: 0 additions & 43 deletions cobalt/browser/browser_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,6 @@
#include "starboard/system.h"
#include "third_party/icu/source/i18n/unicode/timezone.h"

#if SB_HAS(CORE_DUMP_HANDLER_SUPPORT)
#include "base/memory/ptr_util.h"
#include STARBOARD_CORE_DUMP_HANDLER_INCLUDE
#endif // SB_HAS(CORE_DUMP_HANDLER_SUPPORT)

using cobalt::cssom::ViewportSize;

namespace cobalt {
Expand Down Expand Up @@ -306,15 +301,6 @@ BrowserModule::BrowserModule(const GURL& url,
service_worker_registry_.reset(new ServiceWorkerRegistry(
&web_settings_, network_module, platform_info_.get()));

#if SB_HAS(CORE_DUMP_HANDLER_SUPPORT)
SbCoreDumpRegisterHandler(BrowserModule::CoreDumpHandler, this);
on_error_triggered_count_ = 0;
#if defined(COBALT_CHECK_RENDER_TIMEOUT)
recovery_mechanism_triggered_count_ = 0;
timeout_response_trigger_count_ = 0;
#endif // defined(COBALT_CHECK_RENDER_TIMEOUT)
#endif // SB_HAS(CORE_DUMP_HANDLER_SUPPORT)

#if defined(COBALT_CHECK_RENDER_TIMEOUT)
timeout_polling_thread_.Start();
timeout_polling_thread_.message_loop()->task_runner()->PostDelayedTask(
Expand Down Expand Up @@ -467,9 +453,6 @@ BrowserModule::~BrowserModule() {
}

on_error_retry_timer_.Stop();
#if SB_HAS(CORE_DUMP_HANDLER_SUPPORT)
SbCoreDumpUnregisterHandler(BrowserModule::CoreDumpHandler, this);
#endif

#if defined(ENABLE_DEBUGGER)
if (debug_console_) {
Expand Down Expand Up @@ -755,22 +738,6 @@ void BrowserModule::Reload() {
base::SourceLocation("[object BrowserModule]", 1, 1));
}

#if SB_HAS(CORE_DUMP_HANDLER_SUPPORT)
// static
void BrowserModule::CoreDumpHandler(void* browser_module_as_void) {
BrowserModule* browser_module =
static_cast<BrowserModule*>(browser_module_as_void);
SbCoreDumpLogInteger("BrowserModule.on_error_triggered_count_",
browser_module->on_error_triggered_count_);
#if defined(COBALT_CHECK_RENDER_TIMEOUT)
SbCoreDumpLogInteger("BrowserModule.recovery_mechanism_triggered_count_",
browser_module->recovery_mechanism_triggered_count_);
SbCoreDumpLogInteger("BrowserModule.timeout_response_trigger_count_",
browser_module->timeout_response_trigger_count_);
#endif // defined(COBALT_CHECK_RENDER_TIMEOUT)
}
#endif // SB_HAS(CORE_DUMP_HANDLER_SUPPORT)

void BrowserModule::OnLoad() {
TRACE_EVENT0("cobalt::browser", "BrowserModule::OnLoad()");
// Repost to our own message loop if necessary. This also prevents
Expand Down Expand Up @@ -1343,10 +1310,6 @@ void BrowserModule::OnError(const GURL& url, const std::string& error) {
return;
}

#if SB_HAS(CORE_DUMP_HANDLER_SUPPORT)
on_error_triggered_count_++;
#endif

// Set |pending_navigate_url_| to the url where the error occurred. This will
// cause the OnError callback to Navigate() to this URL if it receives a
// positive response; otherwise, if Cobalt is currently preloaded or
Expand Down Expand Up @@ -1718,18 +1681,12 @@ void BrowserModule::OnPollForRenderTimeout(const GURL& url) {
}

if (timeout_response_trigger) {
#if SB_HAS(CORE_DUMP_HANDLER_SUPPORT)
timeout_response_trigger_count_++;
#endif
SbAtomicNoBarrier_Exchange64(
non_trivial_global_variables.Get().last_render_timestamp,
static_cast<SbAtomic64>(kSbInt64Max));
if (SbSystemGetRandomUInt64() <
kRenderTimeoutErrorPercentage * (UINT64_MAX / 100)) {
OnError(url, std::string("Rendering Timeout"));
#if SB_HAS(CORE_DUMP_HANDLER_SUPPORT)
recovery_mechanism_triggered_count_++;
#endif
} else {
SB_DLOG(INFO) << "Received OnRenderTimeout, ignoring by random chance.";
}
Expand Down
9 changes: 0 additions & 9 deletions cobalt/browser/browser_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,15 +244,6 @@ class BrowserModule {
void SetDeepLinkTimestamp(int64_t timestamp);

private:
#if SB_HAS(CORE_DUMP_HANDLER_SUPPORT)
static void CoreDumpHandler(void* browser_module_as_void);
int on_error_triggered_count_;
#if defined(COBALT_CHECK_RENDER_TIMEOUT)
int recovery_mechanism_triggered_count_;
int timeout_response_trigger_count_;
#endif // defined(COBALT_CHECK_RENDER_TIMEOUT)
#endif // SB_HAS(CORE_DUMP_HANDLER_SUPPORT)

// Called when the WebModule's Window.onload event is fired.
void OnLoad();

Expand Down
4 changes: 0 additions & 4 deletions cobalt/dom/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@
#include "cobalt/web/dom_exception.h"
#if defined(STARBOARD)
#include "starboard/configuration.h"
#if SB_HAS(CORE_DUMP_HANDLER_SUPPORT)
#define HANDLE_CORE_DUMP
#include STARBOARD_CORE_DUMP_HANDLER_INCLUDE
#endif // SB_HAS(CORE_DUMP_HANDLER_SUPPORT)
#endif // defined(STARBOARD)

namespace cobalt {
Expand Down
75 changes: 0 additions & 75 deletions cobalt/dom_parser/libxml_parser_wrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,80 +26,13 @@
#include "cobalt/dom/text.h"
#if defined(STARBOARD)
#include "starboard/configuration.h"
#if SB_HAS(CORE_DUMP_HANDLER_SUPPORT)
#define HANDLE_CORE_DUMP
#include "base/lazy_instance.h"
#include STARBOARD_CORE_DUMP_HANDLER_INCLUDE
#endif // SB_HAS(CORE_DUMP_HANDLER_SUPPORT)
#endif // defined(STARBOARD)
#include "third_party/libxml/src/include/libxml/xmlerror.h"

namespace cobalt {
namespace dom_parser {
namespace {

#if defined(HANDLE_CORE_DUMP)

class LibxmlParserWrapperLog {
public:
LibxmlParserWrapperLog()
: total_parsed_bytes_(0),
total_warning_count_(0),
total_error_count_(0),
total_fatal_count_(0) {
SbCoreDumpRegisterHandler(CoreDumpHandler, this);
}
~LibxmlParserWrapperLog() {
SbCoreDumpUnregisterHandler(CoreDumpHandler, this);
}

static void CoreDumpHandler(void* context) {
SbCoreDumpLogInteger(
"LibxmlParserWrapper total parsed bytes",
static_cast<LibxmlParserWrapperLog*>(context)->total_parsed_bytes_);
SbCoreDumpLogInteger(
"LibxmlParserWrapper total warning count",
static_cast<LibxmlParserWrapperLog*>(context)->total_warning_count_);
SbCoreDumpLogInteger(
"LibxmlParserWrapper total error count",
static_cast<LibxmlParserWrapperLog*>(context)->total_error_count_);
SbCoreDumpLogInteger(
"LibxmlParserWrapper total fatal error count",
static_cast<LibxmlParserWrapperLog*>(context)->total_fatal_count_);
SbCoreDumpLogString("LibxmlParserWrapper last fatal error",
static_cast<LibxmlParserWrapperLog*>(context)
->last_fatal_message_.c_str());
}

void IncrementParsedBytes(int length) { total_parsed_bytes_ += length; }
void LogParsingIssue(LibxmlParserWrapper::IssueSeverity severity,
const std::string& message) {
if (severity == LibxmlParserWrapper::kWarning) {
total_warning_count_++;
} else if (severity == LibxmlParserWrapper::kError) {
total_error_count_++;
} else if (severity == LibxmlParserWrapper::kFatal) {
total_fatal_count_++;
last_fatal_message_ = message;
} else {
NOTREACHED();
}
}

private:
int total_parsed_bytes_;
int total_warning_count_;
int total_error_count_;
int total_fatal_count_;
std::string last_fatal_message_;
DISALLOW_COPY_AND_ASSIGN(LibxmlParserWrapperLog);
};

base::LazyInstance<LibxmlParserWrapperLog>::DestructorAtExit
libxml_parser_wrapper_log = LAZY_INSTANCE_INITIALIZER;

#endif // defined(HANDLE_CORE_DUMP)

/////////////////////////////////////////////////////////////////////////////
// Helpers
/////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -320,10 +253,6 @@ void LibxmlParserWrapper::OnParsingIssue(IssueSeverity severity,
} else {
NOTREACHED();
}

#if defined(HANDLE_CORE_DUMP)
libxml_parser_wrapper_log.Get().LogParsingIssue(severity, message);
#endif
}

void LibxmlParserWrapper::OnCDATABlock(const std::string& value) {
Expand Down Expand Up @@ -352,10 +281,6 @@ void LibxmlParserWrapper::PreprocessChunk(const char* data, size_t size,
OnParsingIssue(kFatal, kMessageInputNotUTF8);
return;
}

#if defined(HANDLE_CORE_DUMP)
libxml_parser_wrapper_log.Get().IncrementParsedBytes(static_cast<int>(size));
#endif
}

} // namespace dom_parser
Expand Down
57 changes: 2 additions & 55 deletions cobalt/h5vcc/h5vcc_crash_log.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,60 +23,11 @@
#include "base/memory/singleton.h"
#include "base/synchronization/lock.h"
#include "starboard/extension/crash_handler.h"

#if SB_HAS(CORE_DUMP_HANDLER_SUPPORT)
#include STARBOARD_CORE_DUMP_HANDLER_INCLUDE
#endif // SB_HAS(CORE_DUMP_HANDLER_SUPPORT)

#include "starboard/system.h"

namespace cobalt {
namespace h5vcc {

CrashLogDictionary* CrashLogDictionary::GetInstance() {
return base::Singleton<CrashLogDictionary, base::DefaultSingletonTraits<
CrashLogDictionary>>::get();
}

void CrashLogDictionary::SetString(const std::string& key,
const std::string& value) {
base::AutoLock lock(mutex_);
// While the lock prevents contention between other calls to SetString(),
// the atomics guard against OnCrash(), which doesn't acquire |mutex_|, from
// accessing the data at the same time. In the case that OnCrash() is
// being called, we give up and skip adding the data.
if (base::subtle::Acquire_CompareAndSwap(&accessing_log_data_, 0, 1) == 0) {
string_log_map_[key] = value;
base::subtle::Release_Store(&accessing_log_data_, 0);
}
}

CrashLogDictionary::CrashLogDictionary() : accessing_log_data_(0) {
#if SB_HAS(CORE_DUMP_HANDLER_SUPPORT)
SbCoreDumpRegisterHandler(&CoreDumpHandler, this);
#endif
}

void CrashLogDictionary::CoreDumpHandler(void* context) {
CrashLogDictionary* crash_log_dictionary =
static_cast<CrashLogDictionary*>(context);
crash_log_dictionary->OnCrash();
}

void CrashLogDictionary::OnCrash() {
#if SB_HAS(CORE_DUMP_HANDLER_SUPPORT)
// Check that we're not already updating log data. If we are, we just
// give up and skip recording any crash data, but hopefully this is rare.
if (base::subtle::Acquire_CompareAndSwap(&accessing_log_data_, 0, 1) == 0) {
for (StringMap::const_iterator iter = string_log_map_.begin();
iter != string_log_map_.end(); ++iter) {
SbCoreDumpLogString(iter->first.c_str(), iter->second.c_str());
}
base::subtle::Release_Store(&accessing_log_data_, 0);
}
#endif
}

bool H5vccCrashLog::SetString(const std::string& key,
const std::string& value) {
auto crash_handler_extension =
Expand All @@ -85,14 +36,10 @@ bool H5vccCrashLog::SetString(const std::string& key,
if (crash_handler_extension && crash_handler_extension->version >= 2) {
return crash_handler_extension->SetString(key.c_str(), value.c_str());
}

// The platform has not implemented a version of the CrashHandler Cobalt
// Extension appropriate for this use case.

// Forward the call to a global singleton so that we keep a consistent crash
// log globally.
CrashLogDictionary::GetInstance()->SetString(key, value);

return true;
return false;
}

void H5vccCrashLog::TriggerCrash(H5vccCrashType intent) {
Expand Down
32 changes: 0 additions & 32 deletions cobalt/h5vcc/h5vcc_crash_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,38 +28,6 @@
namespace cobalt {
namespace h5vcc {

// We keep a global mapping of all registered logs. When a crash occurs, we
// will iterate through the mapping in this dictionary to extract all
// logged entries and write them to the system's crash logger via Starboard.
class CrashLogDictionary {
public:
static CrashLogDictionary* GetInstance();

void SetString(const std::string& key, const std::string& value);

private:
CrashLogDictionary();

static void CoreDumpHandler(void* context);

void OnCrash();

friend struct base::DefaultSingletonTraits<CrashLogDictionary>;

base::subtle::Atomic32 accessing_log_data_;

// It is possible for multiple threads to call the H5VCC interface at the
// same time, and they will all forward to this global singleton, so we
// use this mutex to protect against concurrent access.
base::Lock mutex_;

typedef std::map<std::string, std::string> StringMap;
// Keeps track of all string values to be logged when a crash occurs.
StringMap string_log_map_;

DISALLOW_COPY_AND_ASSIGN(CrashLogDictionary);
};

class H5vccCrashLog : public script::Wrappable {
public:
H5vccCrashLog() {}
Expand Down
Loading

0 comments on commit 61c20a2

Please sign in to comment.