From a37bad12c3b730eeb8a6dc40a0a78019f28a607e Mon Sep 17 00:00:00 2001 From: Prabir Pradhan Date: Fri, 18 Aug 2023 15:55:32 +0000 Subject: Improve existing InputDispatcher traces Previously, we traced using ATRACE_NAME inside an if condition after checking if atrace was enabled. This was so that we could avoid the addtional overhead of formatting the trace string when there's no ongoing trace. Since ATRACE_NAME is expected to be scoped trace of the call, doing it inside an if condition means the scope of the trace ends immediately once we leave the inner scope of the conditional. This essentially makes all of our scoped traces point traces. We get around this by adding a new helper macro ATRACE_NAME_IF that takes a lambda that formats the message. This way, we can avoid the formatting overhead and ensure the entire scope of the method is traced. Bug: 210460522 Test: manual: take a trace with Perfetto Change-Id: Ibee1e7dc5021296bdb5871dec59d8d4978fcf0c9 --- include/input/TraceTools.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 include/input/TraceTools.h (limited to 'include') diff --git a/include/input/TraceTools.h b/include/input/TraceTools.h new file mode 100644 index 0000000000..70b23c5875 --- /dev/null +++ b/include/input/TraceTools.h @@ -0,0 +1,25 @@ +/* + * Copyright 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include + +#define ATRACE_NAME_IF(condition, messageProvider) \ + const auto _trace_token = condition \ + ? std::make_optional(ATRACE_TAG, messageProvider().c_str()) \ + : std::nullopt -- cgit v1.2.3-59-g8ed1b