MCPcopy Create free account
hub / github.com/Compaile/ctrack / EventHandler

Class EventHandler

include/ctrack.hpp:1091–1151  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1089 }
1090
1091 class EventHandler
1092 {
1093 public:
1094 EventHandler(int line = __builtin_LINE(), const char *filename = __builtin_FILE(), const char *function = __builtin_FUNCTION(), std::chrono::high_resolution_clock::time_point start_time = std::chrono::high_resolution_clock::now()) : line(line)
1095
1096 {
1097
1098 previous_store_clear_cnt = store::store_clear_cnt;
1099 this->filename = filename;
1100 this->function = function;
1101 while (store::write_events_locked)
1102 {
1103 }
1104
1105 register_event();
1106 this->start_time = start_time;
1107 }
1108 ~EventHandler()
1109 {
1110 auto end_time = std::chrono::high_resolution_clock::now();
1111 while (store::write_events_locked)
1112 {
1113 }
1114
1115 if (store::store_clear_cnt != previous_store_clear_cnt)
1116 {
1117 register_event();
1118 }
1119
1120 if (event_ptr->capacity() - event_ptr->size() < 1)
1121 event_ptr->reserve(event_ptr->capacity() * 4);
1122
1123 event_ptr->emplace_back(Event{start_time, end_time, filename, line, function, t_id, event_id});
1124
1125 *current_event_id = previous_event_id;
1126 if (previous_event_id > 0)
1127 {
1128 if ((*sub_events_ptr)[previous_event_id].capacity() - (*sub_events_ptr)[previous_event_id].size() < 1)
1129 (*sub_events_ptr)[previous_event_id].reserve((*sub_events_ptr)[previous_event_id].capacity() * 4);
1130 (*sub_events_ptr)[previous_event_id].push_back(event_id);
1131 }
1132 }
1133
1134 private:
1135 void register_event()
1136 {
1137 t_id = fetch_event_t_id();
1138 previous_event_id = *current_event_id;
1139 event_id = ++(*current_event_cnt);
1140 *current_event_id = event_id;
1141 }
1142 std::chrono::high_resolution_clock::time_point start_time;
1143 int line;
1144 unsigned int previous_store_clear_cnt;
1145
1146 std::string_view filename, function;
1147
1148 int t_id;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected