Flow 1.0.2
Flow project: Full implementation reference.
timed_handler.hpp
Go to the documentation of this file.
1/* Flow
2 * Copyright 2023 Akamai Technologies, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the
5 * "License"); you may not use this file except in
6 * compliance with the License. You may obtain a copy
7 * of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in
12 * writing, software distributed under the License is
13 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
14 * CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing
16 * permissions and limitations under the License. */
17
18/// @file
19#pragma once
20
23#include <boost/asio/associated_executor.hpp>
24#include <utility>
25
26namespace flow::perf
27{
28// Free functions: in *_fwd.hpp.
29
30// Template implementations.
31
32template<typename Accumulator, typename Handler>
33auto timed_handler(Clock_type clock_type, Accumulator* accumulator, Handler&& handler)
34{
35 using boost::asio::bind_executor;
36 using boost::asio::get_associated_executor;
37
38 const auto executor = get_associated_executor(handler); // Do this before `handler` is move()d away!
39 return bind_executor(executor,
40 timed_function(clock_type, accumulator, std::move(handler)));
41}
42
43} // namespace flow::perf
Flow module containing tools for profiling and optimization.
auto timed_function(Clock_type clock_type, Accumulator *accumulator, Func &&function)
Constructs a closure that times and executes void-returning function(), adding the elapsed time with ...
auto timed_handler(Clock_type clock_type, Accumulator *accumulator, Handler &&handler)
Identical to timed_function() but suitable for boost.asio-targeted handler functions.
Clock_type
Clock types supported by flow::perf module facilities, perf::Checkpointing_timer in particular.