Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add adblock loading traces & UMAs #20463

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion components/brave_component_updater/browser/dat_file_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
#include <memory>
#include <string>

#include "base/logging.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/logging.h"
#include "base/trace_event/trace_event.h"

namespace {

Expand Down Expand Up @@ -40,8 +41,11 @@ void GetDATFileData(const base::FilePath& file_path,
namespace brave_component_updater {

DATFileDataBuffer ReadDATFileData(const base::FilePath& dat_file_path) {
TRACE_EVENT_BEGIN1("brave.adblock", "ReadDATFileData", "path",
dat_file_path.MaybeAsASCII());
DATFileDataBuffer buffer;
GetDATFileData(dat_file_path, &buffer);
TRACE_EVENT_END1("brave.adblock", "ReadDATFileData", "size", buffer.size());
return buffer;
}

Expand Down
35 changes: 34 additions & 1 deletion components/brave_shields/browser/ad_block_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@

#include "base/containers/contains.h"
#include "base/json/json_reader.h"
#include "base/metrics/histogram_functions.h"
#include "base/strings/string_number_conversions.h"
#include "base/timer/elapsed_timer.h"
#include "base/trace_event/trace_event.h"
#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
#include "url/origin.h"

Expand Down Expand Up @@ -243,6 +246,7 @@ base::Value::List AdBlockEngine::HiddenClassIdSelectors(
void AdBlockEngine::Load(bool deserialize,
const DATFileDataBuffer& dat_buf,
const std::string& resources_json) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (deserialize) {
OnDATLoaded(dat_buf, resources_json);
} else {
Expand Down Expand Up @@ -275,7 +279,21 @@ void AdBlockEngine::AddKnownTagsToAdBlockInstance() {

void AdBlockEngine::OnListSourceLoaded(const DATFileDataBuffer& filters,
const std::string& resources_json) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);

base::ElapsedTimer timer;
TRACE_EVENT_BEGIN1("brave.adblock", "MakeEngineWithRules", "size",
filters.size());

auto result = adblock::engine_with_rules(filters);

TRACE_EVENT_END0("brave.adblock", "MakeEngineWithRules");
base::UmaHistogramTimes("Brave.Adblock.MakeEngineWithRules", timer.Elapsed());
if (filters.size() > 10'000) {
base::UmaHistogramTimes("Brave.Adblock.MakeEngineWithRules.Large",
timer.Elapsed());
}

if (result.result_kind != adblock::ResultKind::Success) {
LOG(ERROR) << "AdBlockEngine::OnListSourceLoaded failed: "
<< result.error_message.c_str();
Expand All @@ -286,13 +304,28 @@ void AdBlockEngine::OnListSourceLoaded(const DATFileDataBuffer& filters,

void AdBlockEngine::OnDATLoaded(const DATFileDataBuffer& dat_buf,
const std::string& resources_json) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);

// An empty buffer will not load successfully.
if (dat_buf.empty()) {
return;
}

base::ElapsedTimer timer;
TRACE_EVENT_BEGIN1("brave.adblock", "EngineDeserialize", "size",
dat_buf.size());

auto client = adblock::new_engine();
if (!client->deserialize(dat_buf)) {
const auto result = client->deserialize(dat_buf);

TRACE_EVENT_END0("brave.adblock", "EngineDeserialize");
base::UmaHistogramTimes("Brave.Adblock.EngineDeserialize", timer.Elapsed());
if (dat_buf.size() > 10'000) {
base::UmaHistogramTimes("Brave.Adblock.EngineDeserialize.Large",
timer.Elapsed());
}

if (!result) {
LOG(ERROR) << "AdBlockEngine::OnDATLoaded deserialize failed";
return;
}
Expand Down