1 /* Copyright 2018 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 
16 #ifndef TENSORFLOW_LITE_PROFILING_PROFILE_SUMMARIZER_H_
17 #define TENSORFLOW_LITE_PROFILING_PROFILE_SUMMARIZER_H_
18 
19 #include <vector>
20 
21 #include "tensorflow/lite/interpreter.h"
22 #include "tensorflow/lite/profiling/profiler.h"
23 #include "tensorflow/core/util/stats_calculator.h"
24 
25 namespace tflite {
26 namespace profiling {
27 
28 // Creates a summary of operator invocations in the interpreter.
29 class ProfileSummarizer {
30  public:
31   ProfileSummarizer();
~ProfileSummarizer()32   virtual ~ProfileSummarizer() {}
33 
34   // Process profile events to update statistics for operator invocations.
35   void ProcessProfiles(const std::vector<const ProfileEvent*>& profile_stats,
36                        const tflite::Interpreter& interpreter);
37 
38   // Returns a string detailing the accumulated runtime stats in a tab-separated
39   // format which can be pasted into a spreadsheet for further analysis.
GetOutputString()40   std::string GetOutputString() const {
41     return stats_calculator_->GetOutputString();
42   }
43 
GetShortSummary()44   std::string GetShortSummary() const {
45     return stats_calculator_->GetShortSummary();
46   }
47 
48  private:
49   std::unique_ptr<tensorflow::StatsCalculator> stats_calculator_;
50 };
51 
52 }  // namespace profiling
53 }  // namespace tflite
54 
55 #endif  // TENSORFLOW_LITE_PROFILING_PROFILE_SUMMARIZER_H_
56