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 #ifndef TENSORFLOW_LITE_PROFILING_PROFILE_SUMMARY_FORMATTER_H_ 16 #define TENSORFLOW_LITE_PROFILING_PROFILE_SUMMARY_FORMATTER_H_ 17 18 #include <functional> 19 #include <memory> 20 #include <sstream> 21 #include <string> 22 #include <utility> 23 #include <vector> 24 25 #include "tensorflow/core/util/stats_calculator.h" 26 27 namespace tflite { 28 namespace profiling { 29 30 // Formats the profile summary in a certain way. 31 class ProfileSummaryFormatter { 32 public: ProfileSummaryFormatter()33 ProfileSummaryFormatter() {} ~ProfileSummaryFormatter()34 virtual ~ProfileSummaryFormatter() {} 35 // Returns a string detailing the accumulated runtime stats in StatsCalculator 36 // of ProfileSummarizer. 37 virtual std::string GetOutputString( 38 const std::map<uint32_t, std::unique_ptr<tensorflow::StatsCalculator>>& 39 stats_calculator_map, 40 const tensorflow::StatsCalculator& delegate_stats_calculator) const = 0; 41 // Returns a string detailing the short summary of the accumulated runtime 42 // stats in StatsCalculator of ProfileSummarizer. 43 virtual std::string GetShortSummary( 44 const std::map<uint32_t, std::unique_ptr<tensorflow::StatsCalculator>>& 45 stats_calculator_map, 46 const tensorflow::StatsCalculator& delegate_stats_calculator) const = 0; 47 virtual tensorflow::StatSummarizerOptions GetStatSummarizerOptions() 48 const = 0; 49 }; 50 51 class ProfileSummaryDefaultFormatter : public ProfileSummaryFormatter { 52 public: ProfileSummaryDefaultFormatter()53 ProfileSummaryDefaultFormatter() {} ~ProfileSummaryDefaultFormatter()54 ~ProfileSummaryDefaultFormatter() override {} 55 std::string GetOutputString( 56 const std::map<uint32_t, std::unique_ptr<tensorflow::StatsCalculator>>& 57 stats_calculator_map, 58 const tensorflow::StatsCalculator& delegate_stats_calculator) 59 const override; 60 std::string GetShortSummary( 61 const std::map<uint32_t, std::unique_ptr<tensorflow::StatsCalculator>>& 62 stats_calculator_map, 63 const tensorflow::StatsCalculator& delegate_stats_calculator) 64 const override; 65 tensorflow::StatSummarizerOptions GetStatSummarizerOptions() const override; 66 67 private: 68 std::string GenerateReport( 69 const std::string& tag, bool include_output_string, 70 const std::map<uint32_t, std::unique_ptr<tensorflow::StatsCalculator>>& 71 stats_calculator_map, 72 const tensorflow::StatsCalculator& delegate_stats_calculator) const; 73 }; 74 75 class ProfileSummaryCSVFormatter : public ProfileSummaryDefaultFormatter { 76 public: ProfileSummaryCSVFormatter()77 ProfileSummaryCSVFormatter() {} 78 tensorflow::StatSummarizerOptions GetStatSummarizerOptions() const override; 79 }; 80 81 } // namespace profiling 82 } // namespace tflite 83 84 #endif // TENSORFLOW_LITE_PROFILING_PROFILE_SUMMARY_FORMATTER_H_ 85