| 224 | } |
| 225 | |
| 226 | bool writeJSON(const std::string& filePath) |
| 227 | { |
| 228 | std::scoped_lock lock(Detail::getRegistryMutex()); |
| 229 | const auto& registry = Detail::getRegistry(); |
| 230 | |
| 231 | json_t functions = json_t::array(); |
| 232 | |
| 233 | for (size_t i = 0; i < registry.size(); ++i) |
| 234 | { |
| 235 | const auto* func = registry[i]; |
| 236 | |
| 237 | json_t parentIndices = json_t::array(); |
| 238 | for (const auto* parent : func->getParents()) |
| 239 | { |
| 240 | auto it = std::find(registry.begin(), registry.end(), parent); |
| 241 | if (it != registry.end()) |
| 242 | parentIndices.push_back(std::distance(registry.begin(), it)); |
| 243 | } |
| 244 | |
| 245 | json_t childIndices = json_t::array(); |
| 246 | for (const auto* child : func->getChildren()) |
| 247 | { |
| 248 | auto it = std::find(registry.begin(), registry.end(), child); |
| 249 | if (it != registry.end()) |
| 250 | childIndices.push_back(std::distance(registry.begin(), it)); |
| 251 | } |
| 252 | |
| 253 | functions.push_back( |
| 254 | { |
| 255 | { "name", func->getName() }, |
| 256 | { "callCount", func->getCallCount() }, |
| 257 | { "minTime", func->getMinTime() }, |
| 258 | { "maxTime", func->getMaxTime() }, |
| 259 | { "avgTime", func->getAverageTime() }, |
| 260 | { "totalTime", func->getTotalTime() }, |
| 261 | { "parents", parentIndices }, |
| 262 | { "children", childIndices }, |
| 263 | }); |
| 264 | } |
| 265 | |
| 266 | json_t root = { { "functions", functions } }; |
| 267 | |
| 268 | try |
| 269 | { |
| 270 | Json::WriteToFile(filePath, root); |
| 271 | return true; |
| 272 | } |
| 273 | catch (...) |
| 274 | { |
| 275 | return false; |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | bool hasExtension(const std::string& path, const std::string& ext) |
| 280 | { |
no test coverage detected