1 /* Copyright 2020 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 #include "tensorflow/lite/profiling/platform_profiler.h" 16 17 #include <memory> 18 19 #include "tensorflow/lite/core/api/profiler.h" 20 21 #if defined(__ANDROID__) 22 #include "tensorflow/lite/profiling/atrace_profiler.h" 23 #elif defined(__APPLE__) 24 #include "TargetConditionals.h" 25 #if TARGET_OS_IOS 26 #define SIGNPOST_PLATFORM_PROFILER 27 #include "tensorflow/lite/profiling/signpost_profiler.h" 28 #endif 29 #elif defined(ENABLE_TFLITE_PERFETTO_PROFILER) 30 #include "tensorflow/lite/experimental/perfetto_profiling/perfetto_profiler.h" 31 #endif 32 33 namespace tflite { 34 namespace profiling { 35 MaybeCreatePlatformProfiler()36std::unique_ptr<tflite::Profiler> MaybeCreatePlatformProfiler() { 37 #if defined(__ANDROID__) 38 return MaybeCreateATraceProfiler(); 39 #elif defined(SIGNPOST_PLATFORM_PROFILER) 40 return MaybeCreateSignpostProfiler(); 41 #elif defined(ENABLE_TFLITE_PERFETTO_PROFILER) 42 return std::make_unique<tflite::profiling::PerfettoProfiler>(); 43 #else 44 return nullptr; 45 #endif 46 } 47 48 } // namespace profiling 49 } // namespace tflite 50