HAL  v4.5.0-83-g30c8f0afc
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
statistics.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "hal_core/defines.h"
7 #include "nlohmann/json.hpp"
8 
9 #include <map>
10 #include <mutex>
11 #include <set>
12 #include <string>
13 
14 namespace hal
15 {
16  class Gate;
17 
18  namespace module_identification
19  {
23  struct Statistics
24  {
25  std::map<const BaseCandidate*, std::map<std::string, std::map<std::string, std::map<std::string, std::map<std::string, u64>>>>> m_data;
26  std::mutex m_mutex;
27 
28  void add_stat(const BaseCandidate* bc, const FunctionalCandidate& oc)
29  {
30  m_mutex.lock();
31 
32  // Check and insert for the base_candidate key
33  if (m_data.find(bc) == m_data.end())
34  {
35  m_data.insert({bc, std::map<std::string, std::map<std::string, std::map<std::string, std::map<std::string, u64>>>>()});
36  }
37 
38  for (const auto& [processing_step, entries] : oc.m_timings)
39  {
40  for (const auto& [type, entry] : entries)
41  {
42  for (const auto& [category, metrics] : entry)
43  {
44  for (const auto& [name, value] : metrics)
45  {
46  // std::cout << type << " - " << category << " - " << name << std::endl;
47  m_data[bc][processing_step][type][category][name] += value;
48  }
49  }
50  }
51  }
52 
53  m_mutex.unlock();
54  };
55 
56  void add_stat(const BaseCandidate* bc, const std::map<std::string, std::map<std::string, std::map<std::string, std::map<std::string, u64>>>>& stats)
57  {
58  m_mutex.lock();
59 
60  // Check and insert for the base_candidate key
61  if (m_data.find(bc) == m_data.end())
62  {
63  m_data.insert({bc, std::map<std::string, std::map<std::string, std::map<std::string, std::map<std::string, u64>>>>()});
64  }
65 
66  for (const auto& [processing_step, entries] : stats)
67  {
68  for (const auto& [type, entry] : entries)
69  {
70  for (const auto& [category, metrics] : entry)
71  {
72  for (const auto& [name, value] : metrics)
73  {
74  // std::cout << type << " - " << category << " - " << name << std::endl;
75  m_data[bc][processing_step][type][category][name] += value;
76  }
77  }
78  }
79  }
80 
81  m_mutex.unlock();
82  };
83 
84  void print()
85  {
86  std::cout << to_json() << std::endl;
87  };
88 
89  std::string to_json(const u32 indent = 0)
90  {
91  std::map<std::string, std::map<std::string, std::map<std::string, std::map<std::string, std::map<std::string, u64>>>>> m_json_data;
92  for (const auto& [bc, stats] : m_data)
93  {
94  const auto bc_str = bc->m_gates.front()->get_name() + " - " + std::to_string(reinterpret_cast<std::uintptr_t>(bc));
95  for (const auto& [processing_step, entries] : stats)
96  {
97  for (const auto& [type, entry] : entries)
98  {
99  for (const auto& [category, metrics] : entry)
100  {
101  for (const auto& [name, value] : metrics)
102  {
103  m_json_data[bc_str][processing_step][type][category][name] = value;
104  m_json_data[bc_str][processing_step]["TOTAL"][category][name] += value;
105  m_json_data["TOTAL"][processing_step][type][category][name] += value;
106  m_json_data["TOTAL"][processing_step]["TOTAL"][category][name] += value;
107  }
108  }
109  }
110  }
111  }
112 
113  nlohmann::json j = {m_json_data};
114 
115  return j.dump(indent);
116  }
117  };
118 
119  } // namespace module_identification
120 } // namespace hal
This file contains the definition of the BaseCandidate class, which represents a base candidate in th...
This file contains the enumeration and constants for the candidate types used in the module identific...
Represents a base candidate in the module identification process.
Represents a functional candidate derived from structural candidates.
std::map< std::string, std::map< std::string, std::map< std::string, std::map< std::string, u64 > > > > m_timings
uint32_t u32
Definition: defines.h:41
This file contains the class and functions for handling functional candidates within the module ident...
Definition: defines.h:45
PinType type
std::string name
void add_stat(const BaseCandidate *bc, const FunctionalCandidate &oc)
Definition: statistics.h:28
std::string to_json(const u32 indent=0)
Definition: statistics.h:89
std::map< const BaseCandidate *, std::map< std::string, std::map< std::string, std::map< std::string, std::map< std::string, u64 > > > > > m_data
Definition: statistics.h:25
void add_stat(const BaseCandidate *bc, const std::map< std::string, std::map< std::string, std::map< std::string, std::map< std::string, u64 >>>> &stats)
Definition: statistics.h:56