1 : // Copyright 2016 Google Inc. All Rights Reserved.
2 : //
3 : // Licensed under the Apache License, Version 2.0 (the "License");
4 : // you may not use this file except in compliance with the License.
5 : // You may obtain a copy of the License at
6 : //
7 : // http://www.apache.org/licenses/LICENSE-2.0
8 : //
9 : // Unless required by applicable law or agreed to in writing, software
10 : // distributed under the License is distributed on an "AS IS" BASIS,
11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : // See the License for the specific language governing permissions and
13 : // limitations under the License.
14 : //
15 : // Utility functions for invoking a function with a unique stack. This is
16 : // used during playback of memory profiler traces to ensure that the number
17 : // of unique stack traces is roughly the same.
18 :
19 : #ifndef SYZYGY_BARD_EVENTS_PLAY_UTIL_H_
20 : #define SYZYGY_BARD_EVENTS_PLAY_UTIL_H_
21 :
22 : #include "syzygy/bard/events/play_util_impl.h"
23 :
24 : namespace bard {
25 :
26 : // Function for invoking a function with a given set of parameters, ensuring
27 : // that the stack-trace leading to the call is unique for a given stack_id.
28 : // @tparam FunctionType The type of the function to be called.
29 : // @tparam ParamTypes The types of the function parameters.
30 : // @param stack_id The ID of the stack trace to generate.
31 : // @param function A reference to the function to be invoked.
32 : // @param param The parameters to be passed to the function.
33 : template <typename FunctionType, typename... ParamTypes>
34 : typename detail::GetReturnType<FunctionType, ParamTypes...>::type
35 : InvokeFunctionWithStackId(uint32_t stack_id,
36 : const FunctionType& function,
37 E : ParamTypes... params) {
38 : // Delegate to InvokeFunctionWithStackIdHelper with a depth of 8. This
39 : // function will take a different path based on each nibble of the stack ID
40 : // before calling the wrapped function.
41 : using ReturnType = detail::GetReturnType<FunctionType, ParamTypes...>::type;
42 E : return detail::InvokeFunctionWithStackIdHelper<
43 : 0, FunctionType, ReturnType, ParamTypes...>().Do(
44 : 8, stack_id, function, params...);
45 E : }
46 :
47 : // Wrapper around InvokeOnFunctionWithStackId which invokes a member function
48 : // on the provided backdrop and provides timing information, collected at the
49 : // leaf.
50 : // @tparam BackdropType The type of the backdrop.
51 : // @tparam ReturnType The return type of the member function.
52 : // @tparam ParamTypes The types of the member function parameters.
53 : // @param stack_id The ID of the stack trace to generate.
54 : // @param timing A pointer to the variable to be populated with the timing
55 : // results.
56 : // @param backdrop The backdrop on which the member function will be invoked.
57 : // @param function A pointer to the member function to be invoked.
58 : // @param param The parameters to be passed to the function.
59 : template <typename BackdropType, typename ReturnType, typename... ParamTypes>
60 : ReturnType InvokeOnBackdrop(
61 : uint32_t stack_id,
62 : uint64_t* timing,
63 : BackdropType* backdrop,
64 : ReturnType (BackdropType::*function)(ParamTypes...),
65 E : ParamTypes... params) {
66 E : return detail::InvokeOnBackdropHelper<
67 : BackdropType, ReturnType, ParamTypes...>::Do(
68 : stack_id, timing, backdrop, function, params...);
69 E : }
70 :
71 : } // namespace bard
72 :
73 : #endif // SYZYGY_BARD_EVENTS_PLAY_UTIL_H_
|