Skip to content

Truly independent web browser

LibWebView: Read each crash report once for about:crashes

Andreas Kling8c4d07893c80
diff --git a/Libraries/LibWebView/WebUI/CrashReportsUI.cpp b/Libraries/LibWebView/WebUI/CrashReportsUI.cpp
index fa89569f65a..7e477a5f358 100644
--- a/Libraries/LibWebView/WebUI/CrashReportsUI.cpp
+++ b/Libraries/LibWebView/WebUI/CrashReportsUI.cpp
@@ -69,6 +69,26 @@ void CrashReportsUI::crash_reports_changed()
load_reports();
}
+static CrashReportsUI::ReportSummary read_report_summary(CrashReportStore const& store, ByteString const& name)
+{
+ // Only a stack can show that two reports are the same crash, so every other report gets a row of its own.
+ CrashReportsUI::ReportSummary summary { name, "Unreadable report"_string, {} };
+
+ // A report that cannot be read still counts as waiting, so it gets a row to delete it from.
+ auto report = store.saved_report(name);
+ if (report.is_error()) {
+ warnln("Could not read crash report {}: {}", name, report.error());
+ return summary;
+ }
+
+ auto diagnostics = CrashReportDiagnostics::parse(report.value().text);
+ if (diagnostics.has_native_stack())
+ summary.signature = diagnostics.signature();
+ summary.process = MUST(String::from_utf8(plain_process_name(diagnostics.header("Process"sv))));
+ summary.crashed_at = diagnostics.crashed_at;
+ return summary;
+}
+
void CrashReportsUI::load_reports()
{
struct Group {
@@ -93,22 +113,13 @@ void CrashReportsUI::load_reports()
// The names come newest first, so a group's first report is its last crash.
Vector<Group> groups;
HashMap<ByteString, size_t> group_indices;
+ HashMap<ByteString, ReportSummary> report_summaries;
for (auto const& name : names) {
- // Only a stack can show that two reports are the same crash, so every other report gets a row of its own.
- auto signature = name;
- String process = "Unreadable report"_string;
- Optional<UnixDateTime> crashed_at;
-
- // A report that cannot be read still counts as waiting, so it gets a row to delete it from.
- if (auto report = store.saved_report(name); report.is_error()) {
- warnln("Could not read crash report {}: {}", name, report.error());
- } else {
- auto diagnostics = CrashReportDiagnostics::parse(report.value().text);
- if (diagnostics.has_native_stack())
- signature = diagnostics.signature();
- process = MUST(String::from_utf8(plain_process_name(diagnostics.header("Process"sv))));
- crashed_at = diagnostics.crashed_at;
- }
+ // A saved report does not change, and this runs each time any report does.
+ auto cached_summary = m_report_summaries.get(name);
+ auto summary = cached_summary.has_value() ? cached_summary.value() : read_report_summary(store, name);
+ report_summaries.set(name, summary);
+ auto const& [signature, process, crashed_at] = summary;
auto index = group_indices.ensure(signature, [&] {
groups.append({
@@ -135,6 +146,8 @@ void CrashReportsUI::load_reports()
}
}
+ m_report_summaries = move(report_summaries);
+
JsonArray serialized_groups;
serialized_groups.ensure_capacity(groups.size());
for (auto const& group : groups) {
diff --git a/Libraries/LibWebView/WebUI/CrashReportsUI.h b/Libraries/LibWebView/WebUI/CrashReportsUI.h
index 941b855e381..e1fa36f814e 100644
--- a/Libraries/LibWebView/WebUI/CrashReportsUI.h
+++ b/Libraries/LibWebView/WebUI/CrashReportsUI.h
@@ -6,6 +6,11 @@
#pragma once
+#include <AK/ByteString.h>
+#include <AK/HashMap.h>
+#include <AK/Optional.h>
+#include <AK/String.h>
+#include <AK/Time.h>
#include <LibWebView/CrashReportOutbox.h>
#include <LibWebView/WebUI.h>
@@ -16,6 +21,14 @@ class CrashReportsUI final
, public CrashReportOutboxObserver {
WEB_UI(CrashReportsUI);
+public:
+ // What the list needs to know about a report, which takes reading all of it to find out.
+ struct ReportSummary {
+ ByteString signature;
+ String process;
+ Optional<UnixDateTime> crashed_at;
+ };
+
private:
virtual void register_interfaces() override;
@@ -25,6 +38,8 @@ private:
void send_reports(JsonValue const&);
void delete_reports(JsonValue const&);
void show_report(JsonValue const&);
+
+ HashMap<ByteString, ReportSummary> m_report_summaries;
};
}