1 // Copyright (c) 2017 Google Inc.
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 TOOLS_STATS_STATS_ANALYZER_H_
16 #define TOOLS_STATS_STATS_ANALYZER_H_
17 
18 #include <string>
19 #include <unordered_map>
20 
21 #include "tools/stats/spirv_stats.h"
22 
23 namespace spvtools {
24 namespace stats {
25 
26 class StatsAnalyzer {
27  public:
28   explicit StatsAnalyzer(const SpirvStats& stats);
29 
30   // Writes respective histograms to |out|.
31   void WriteVersion(std::ostream& out);
32   void WriteGenerator(std::ostream& out);
33   void WriteCapability(std::ostream& out);
34   void WriteExtension(std::ostream& out);
35   void WriteOpcode(std::ostream& out);
36   void WriteConstantLiterals(std::ostream& out);
37 
38   // Writes first order Markov analysis to |out|.
39   // stats_.opcode_markov_hist needs to contain raw data for at least one
40   // level.
41   void WriteOpcodeMarkov(std::ostream& out);
42 
43  private:
44   const SpirvStats& stats_;
45 
46   uint32_t num_modules_;
47 
48   std::unordered_map<uint32_t, double> version_freq_;
49   std::unordered_map<uint32_t, double> generator_freq_;
50   std::unordered_map<uint32_t, double> capability_freq_;
51   std::unordered_map<std::string, double> extension_freq_;
52   std::unordered_map<uint32_t, double> opcode_freq_;
53 };
54 
55 }  // namespace stats
56 }  // namespace spvtools
57 
58 #endif  // TOOLS_STATS_STATS_ANALYZER_H_
59