Skip to content

Commit

Permalink
[ads] Followup to "Profile performance with TRACE events" #21106
Browse files Browse the repository at this point in the history
  • Loading branch information
tmancey committed Jan 16, 2025
1 parent e4fe296 commit 92fdf83
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 48 deletions.
8 changes: 4 additions & 4 deletions components/brave_ads/core/internal/ads_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,8 @@ void AdsImpl::CreateOrOpenDatabaseCallback(mojom::WalletInfoPtr mojom_wallet,
}

void AdsImpl::FailedToInitialize(InitializeCallback callback) {
TRACE_EVENT_NESTABLE_ASYNC_END0(kTraceEventCategory, "AdsImpl::Initialize",
TRACE_ID_LOCAL(this));
TRACE_EVENT_NESTABLE_ASYNC_END1(kTraceEventCategory, "AdsImpl::Initialize",
TRACE_ID_LOCAL(this), "success", false);

BLOG(0, "Failed to initialize ads");

Expand All @@ -419,8 +419,8 @@ void AdsImpl::FailedToInitialize(InitializeCallback callback) {

void AdsImpl::SuccessfullyInitialized(mojom::WalletInfoPtr mojom_wallet,
InitializeCallback callback) {
TRACE_EVENT_NESTABLE_ASYNC_END0(kTraceEventCategory, "AdsImpl::Initialize",
TRACE_ID_LOCAL(this));
TRACE_EVENT_NESTABLE_ASYNC_END1(kTraceEventCategory, "AdsImpl::Initialize",
TRACE_ID_LOCAL(this), "success", true);

BLOG(1, "Successfully initialized ads");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,23 @@ void RunDBTransactionCallback(
uint64_t trace_id,
mojom::DBTransactionResultInfoPtr mojom_db_transaction_result) {
if (mojom_db_transaction_result) {
TRACE_EVENT_NESTABLE_ASYNC_END2(
kTraceEventCategory, "RunDBTransaction",
TRACE_ID_WITH_SCOPE("Database", trace_id), "statusCode",
mojom_db_transaction_result->status_code, "rowCount",
mojom_db_transaction_result->rows_union->get_rows().size());
if (mojom_db_transaction_result->rows_union) {
TRACE_EVENT_NESTABLE_ASYNC_END2(
kTraceEventCategory, "DatabaseTransactionUtil::RunDBTransaction",
TRACE_ID_WITH_SCOPE("DatabaseTransactionUtil", trace_id),
"statusCode", mojom_db_transaction_result->status_code, "rowCount",
mojom_db_transaction_result->rows_union->get_rows().size());
} else {
TRACE_EVENT_NESTABLE_ASYNC_END1(
kTraceEventCategory, "DatabaseTransactionUtil::RunDBTransaction",
TRACE_ID_WITH_SCOPE("DatabaseTransactionUtil", trace_id),
"statusCode", mojom_db_transaction_result->status_code);
}
} else {
TRACE_EVENT_NESTABLE_ASYNC_END1(kTraceEventCategory, "RunDBTransaction",
TRACE_ID_WITH_SCOPE("Database", trace_id),
"mojom_db_transaction_result", "nullptr");
TRACE_EVENT_NESTABLE_ASYNC_END1(
kTraceEventCategory, "DatabaseTransactionUtil::RunDBTransaction",
TRACE_ID_WITH_SCOPE("DatabaseTransactionUtil", trace_id),
"mojom_db_transaction_result", "nullptr");
}

std::move(callback).Run(std::move(mojom_db_transaction_result));
Expand All @@ -46,15 +54,23 @@ void RunDBTransactionForSuccessOrFailureCallback(
uint64_t trace_id,
mojom::DBTransactionResultInfoPtr mojom_db_transaction_result) {
if (mojom_db_transaction_result) {
TRACE_EVENT_NESTABLE_ASYNC_END2(
kTraceEventCategory, "RunDBTransaction",
TRACE_ID_WITH_SCOPE("Database", trace_id), "statusCode",
mojom_db_transaction_result->status_code, "rowCount",
mojom_db_transaction_result->rows_union->get_rows().size());
if (mojom_db_transaction_result->rows_union) {
TRACE_EVENT_NESTABLE_ASYNC_END2(
kTraceEventCategory, "DatabaseTransactionUtil::RunDBTransaction",
TRACE_ID_WITH_SCOPE("DatabaseTransactionUtil", trace_id),
"statusCode", mojom_db_transaction_result->status_code, "rowCount",
mojom_db_transaction_result->rows_union->get_rows().size());
} else {
TRACE_EVENT_NESTABLE_ASYNC_END1(
kTraceEventCategory, "DatabaseTransactionUtil::RunDBTransaction",
TRACE_ID_WITH_SCOPE("DatabaseTransactionUtil", trace_id),
"statusCode", mojom_db_transaction_result->status_code);
}
} else {
TRACE_EVENT_NESTABLE_ASYNC_END1(kTraceEventCategory, "RunDBTransaction",
TRACE_ID_WITH_SCOPE("Database", trace_id),
"mojom_db_transaction_result", "nullptr");
TRACE_EVENT_NESTABLE_ASYNC_END1(
kTraceEventCategory, "DatabaseTransactionUtil::RunDBTransaction",
TRACE_ID_WITH_SCOPE("DatabaseTransactionUtil", trace_id),
"mojom_db_transaction_result", "nullptr");
}

if (IsError(mojom_db_transaction_result)) {
Expand Down Expand Up @@ -84,9 +100,10 @@ void RunDBTransaction(const base::Location& location,
mojom::DBTransactionInfoPtr mojom_db_transaction,
::brave_ads::RunDBTransactionCallback callback) {
const uint64_t trace_id = base::trace_event::GetNextGlobalTraceId();
TRACE_EVENT_NESTABLE_ASYNC_BEGIN1(kTraceEventCategory, "RunDBTransaction",
TRACE_ID_WITH_SCOPE("Database", trace_id),
"location", location.ToString());
TRACE_EVENT_NESTABLE_ASYNC_BEGIN1(
kTraceEventCategory, "DatabaseTransactionUtil::RunDBTransaction",
TRACE_ID_WITH_SCOPE("DatabaseTransactionUtil", trace_id), "location",
location.ToString());

GlobalState::GetInstance()->GetDatabaseManager().RunDBTransaction(
std::move(mojom_db_transaction),
Expand All @@ -98,9 +115,10 @@ void RunDBTransaction(const base::Location& location,
mojom::DBTransactionInfoPtr mojom_db_transaction,
ResultCallback callback) {
const uint64_t trace_id = base::trace_event::GetNextGlobalTraceId();
TRACE_EVENT_NESTABLE_ASYNC_BEGIN1(kTraceEventCategory, "RunDBTransaction",
TRACE_ID_WITH_SCOPE("Database", trace_id),
"location", location.ToString());
TRACE_EVENT_NESTABLE_ASYNC_BEGIN1(
kTraceEventCategory, "DatabaseTransactionUtil::RunDBTransaction",
TRACE_ID_WITH_SCOPE("DatabaseTransactionUtil", trace_id), "location",
location.ToString());

GlobalState::GetInstance()->GetDatabaseManager().RunDBTransaction(
std::move(mojom_db_transaction),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void EligibleInlineContentAdsV2::GetSiteHistory(
EligibleAdsCallback<CreativeInlineContentAdList> callback) {
const uint64_t trace_id = base::trace_event::GetNextGlobalTraceId();
TRACE_EVENT_NESTABLE_ASYNC_BEGIN0(
kTraceEventCategory, "GetSiteHistory",
kTraceEventCategory, "EligibleInlineContentAds::GetSiteHistory",
TRACE_ID_WITH_SCOPE("EligibleInlineContentAds", trace_id));

GetAdsClient().GetSiteHistory(
Expand All @@ -91,7 +91,7 @@ void EligibleInlineContentAdsV2::GetSiteHistoryCallback(
uint64_t trace_id,
const SiteHistoryList& site_history) {
TRACE_EVENT_NESTABLE_ASYNC_END1(
kTraceEventCategory, "GetSiteHistory",
kTraceEventCategory, "EligibleInlineContentAds::GetSiteHistory",
TRACE_ID_WITH_SCOPE("EligibleInlineContentAds", trace_id), "site_history",
site_history.size());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void EligibleNewTabPageAdsV2::GetSiteHistory(
EligibleAdsCallback<CreativeNewTabPageAdList> callback) {
const uint64_t trace_id = base::trace_event::GetNextGlobalTraceId();
TRACE_EVENT_NESTABLE_ASYNC_BEGIN0(
kTraceEventCategory, "GetSiteHistory",
kTraceEventCategory, "EligibleNewTabPageAds::GetSiteHistory",
TRACE_ID_WITH_SCOPE("EligibleNewTabPageAds", trace_id));

GetAdsClient().GetSiteHistory(
Expand All @@ -86,7 +86,7 @@ void EligibleNewTabPageAdsV2::GetSiteHistoryCallback(
uint64_t trace_id,
const SiteHistoryList& site_history) {
TRACE_EVENT_NESTABLE_ASYNC_END1(
kTraceEventCategory, "GetSiteHistory",
kTraceEventCategory, "EligibleNewTabPageAds::GetSiteHistory",
TRACE_ID_WITH_SCOPE("EligibleNewTabPageAds", trace_id), "site_history",
site_history.size());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void EligibleNotificationAdsV2::GetSiteHistory(
EligibleAdsCallback<CreativeNotificationAdList> callback) {
const uint64_t trace_id = base::trace_event::GetNextGlobalTraceId();
TRACE_EVENT_NESTABLE_ASYNC_BEGIN0(
kTraceEventCategory, "GetSiteHistory",
kTraceEventCategory, "EligibleNotificationAds::GetSiteHistory",
TRACE_ID_WITH_SCOPE("EligibleNotificationAds", trace_id));

GetAdsClient().GetSiteHistory(
Expand All @@ -86,9 +86,8 @@ void EligibleNotificationAdsV2::GetSiteHistoryCallback(
uint64_t trace_id,
const SiteHistoryList& site_history) {
TRACE_EVENT_NESTABLE_ASYNC_END1(
kTraceEventCategory, "GetSiteHistory",
TRACE_ID_WITH_SCOPE("EligibleNotificationAds", trace_id), "site_history",
site_history.size());
kTraceEventCategory, "EligibleNotificationAds::GetSiteHistory",
TRACE_ID_WITH_SCOPE("", trace_id), "site_history", site_history.size());

GetEligibleAds(std::move(user_model), ad_events, site_history,
std::move(callback));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ void InlineContentAdServing::GetUserModel(
MaybeServeInlineContentAdCallback callback) {
const uint64_t trace_id = base::trace_event::GetNextGlobalTraceId();
TRACE_EVENT_NESTABLE_ASYNC_BEGIN0(
kTraceEventCategory, "GetUserModel",
kTraceEventCategory, "InlineContentAdServing::GetUserModel",
TRACE_ID_WITH_SCOPE("InlineContentAdServing", trace_id));

BuildUserModel(base::BindOnce(&InlineContentAdServing::GetUserModelCallback,
Expand All @@ -132,7 +132,7 @@ void InlineContentAdServing::GetUserModelCallback(
uint64_t trace_id,
UserModelInfo user_model) const {
TRACE_EVENT_NESTABLE_ASYNC_END0(
kTraceEventCategory, "GetUserModel",
kTraceEventCategory, "InlineContentAdServing::GetUserModel",
TRACE_ID_WITH_SCOPE("InlineContentAdServing", trace_id));

NotifyOpportunityAroseToServeInlineContentAd();
Expand All @@ -148,7 +148,7 @@ void InlineContentAdServing::GetEligibleAds(
UserModelInfo user_model) const {
const uint64_t trace_id = base::trace_event::GetNextGlobalTraceId();
TRACE_EVENT_NESTABLE_ASYNC_BEGIN0(
kTraceEventCategory, "GetEligibleAds",
kTraceEventCategory, "InlineContentAdServing::GetEligibleAds",
TRACE_ID_WITH_SCOPE("InlineContentAdServing", trace_id));

eligible_ads_->GetForUserModel(
Expand All @@ -165,7 +165,7 @@ void InlineContentAdServing::GetEligibleAdsCallback(
uint64_t trace_id,
const CreativeInlineContentAdList& creative_ads) const {
TRACE_EVENT_NESTABLE_ASYNC_END1(
kTraceEventCategory, "GetEligibleAds",
kTraceEventCategory, "InlineContentAdServing::GetEligibleAds",
TRACE_ID_WITH_SCOPE("InlineContentAdServing", trace_id), "creative_ads",
creative_ads.size());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void NewTabPageAdServing::GetUserModel(
MaybeServeNewTabPageAdCallback callback) {
const uint64_t trace_id = base::trace_event::GetNextGlobalTraceId();
TRACE_EVENT_NESTABLE_ASYNC_BEGIN0(
kTraceEventCategory, "GetUserModel",
kTraceEventCategory, "NewTabPageAdServing::GetUserModel",
TRACE_ID_WITH_SCOPE("NewTabPageAdServing", trace_id));

BuildUserModel(base::BindOnce(&NewTabPageAdServing::GetUserModelCallback,
Expand All @@ -109,7 +109,7 @@ void NewTabPageAdServing::GetUserModelCallback(
uint64_t trace_id,
UserModelInfo user_model) const {
TRACE_EVENT_NESTABLE_ASYNC_END0(
kTraceEventCategory, "GetUserModel",
kTraceEventCategory, "NewTabPageAdServing::GetUserModel",
TRACE_ID_WITH_SCOPE("NewTabPageAdServing", trace_id));

NotifyOpportunityAroseToServeNewTabPageAd();
Expand All @@ -122,7 +122,7 @@ void NewTabPageAdServing::GetEligibleAds(
UserModelInfo user_model) const {
const uint64_t trace_id = base::trace_event::GetNextGlobalTraceId();
TRACE_EVENT_NESTABLE_ASYNC_BEGIN0(
kTraceEventCategory, "GetEligibleAds",
kTraceEventCategory, "NewTabPageAdServing::GetEligibleAds",
TRACE_ID_WITH_SCOPE("NewTabPageAdServing", trace_id));

eligible_ads_->GetForUserModel(
Expand All @@ -137,7 +137,7 @@ void NewTabPageAdServing::GetEligibleAdsCallback(
uint64_t trace_id,
const CreativeNewTabPageAdList& creative_ads) const {
TRACE_EVENT_NESTABLE_ASYNC_END1(
kTraceEventCategory, "GetEligibleAds",
kTraceEventCategory, "NewTabPageAdServing::GetEligibleAds",
TRACE_ID_WITH_SCOPE("NewTabPageAdServing", trace_id), "creative_ads",
creative_ads.size());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ void NotificationAdServing::GetAdEventsCallback(bool success,
void NotificationAdServing::GetUserModel() {
const uint64_t trace_id = base::trace_event::GetNextGlobalTraceId();
TRACE_EVENT_NESTABLE_ASYNC_BEGIN0(
kTraceEventCategory, "GetUserModel",
kTraceEventCategory, "NotificationAdServing::GetUserModel",
TRACE_ID_WITH_SCOPE("NotificationAdServing", trace_id));

BuildUserModel(base::BindOnce(&NotificationAdServing::GetUserModelCallback,
Expand All @@ -141,7 +141,7 @@ void NotificationAdServing::GetUserModel() {
void NotificationAdServing::GetUserModelCallback(uint64_t trace_id,
UserModelInfo user_model) {
TRACE_EVENT_NESTABLE_ASYNC_END0(
kTraceEventCategory, "GetUserModel",
kTraceEventCategory, "NotificationAdServing::GetUserModel",
TRACE_ID_WITH_SCOPE("NotificationAdServing", trace_id));

NotifyOpportunityAroseToServeNotificationAd(user_model.interest.segments);
Expand All @@ -152,7 +152,7 @@ void NotificationAdServing::GetUserModelCallback(uint64_t trace_id,
void NotificationAdServing::GetEligibleAds(UserModelInfo user_model) {
const uint64_t trace_id = base::trace_event::GetNextGlobalTraceId();
TRACE_EVENT_NESTABLE_ASYNC_BEGIN0(
kTraceEventCategory, "GetEligibleAds",
kTraceEventCategory, "NotificationAdServing::GetEligibleAds",
TRACE_ID_WITH_SCOPE("NotificationAdServing", trace_id));

eligible_ads_->GetForUserModel(
Expand All @@ -165,7 +165,7 @@ void NotificationAdServing::GetEligibleAdsCallback(
uint64_t trace_id,
const CreativeNotificationAdList& creative_ads) {
TRACE_EVENT_NESTABLE_ASYNC_END1(
kTraceEventCategory, "GetEligibleAds",
kTraceEventCategory, "NotificationAdServing::GetEligibleAds",
TRACE_ID_WITH_SCOPE("NotificationAdServing", trace_id), "creative_ads",
creative_ads.size());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void TextClassificationProcessor::Process(const std::string& text) {
if (resource_->IsLoaded()) {
const uint64_t trace_id = base::trace_event::GetNextGlobalTraceId();
TRACE_EVENT_NESTABLE_ASYNC_BEGIN0(
kTraceEventCategory, "Process",
kTraceEventCategory, "TextClassificationProcessor::Process",
TRACE_ID_WITH_SCOPE("TextClassificationProcessor", trace_id));

resource_->ClassifyPage(
Expand All @@ -64,7 +64,7 @@ void TextClassificationProcessor::ClassifyPageCallback(
uint64_t trace_id,
base::optional_ref<const TextClassificationProbabilityMap> probabilities) {
TRACE_EVENT_NESTABLE_ASYNC_END0(
kTraceEventCategory, "Process",
kTraceEventCategory, "TextClassificationProcessor::Process",
TRACE_ID_WITH_SCOPE("TextClassificationProcessor", trace_id));

if (!probabilities) {
Expand Down

0 comments on commit 92fdf83

Please sign in to comment.