1 /* Copyright 2019 The TensorFlow Authors 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 #ifndef TENSORFLOW_CORE_PROFILER_LIB_PROFILER_FACTORY_H_ 16 #define TENSORFLOW_CORE_PROFILER_LIB_PROFILER_FACTORY_H_ 17 18 #include <functional> 19 #include <memory> 20 #include <vector> 21 22 #include "tensorflow/core/profiler/lib/profiler_interface.h" 23 #include "tensorflow/core/profiler/profiler_options.pb.h" 24 25 namespace tensorflow { 26 namespace profiler { 27 28 // A ProfilerFactory returns an instance of ProfilerInterface if ProfileOptions 29 // require it. Otherwise, it might return nullptr. 30 using ProfilerFactory = 31 std::function<std::unique_ptr<ProfilerInterface>(const ProfileOptions&)>; 32 33 // Registers a profiler factory. Should be invoked at most once per factory. 34 void RegisterProfilerFactory(ProfilerFactory factory); 35 36 // Invokes all registered profiler factories with the given options, and 37 // returns the instantiated (non-null) profiler interfaces. 38 std::vector<std::unique_ptr<ProfilerInterface>> CreateProfilers( 39 const ProfileOptions& options); 40 41 // For testing only. 42 void ClearRegisteredProfilersForTest(); 43 44 } // namespace profiler 45 } // namespace tensorflow 46 47 #endif // TENSORFLOW_CORE_PROFILER_LIB_PROFILER_FACTORY_H_ 48