| 347 | } |
| 348 | |
| 349 | int cmInstrumentation::CollectTimingData(cmInstrumentationQuery::Hook hook) |
| 350 | { |
| 351 | // Don't run collection if hook is disabled |
| 352 | if (hook != cmInstrumentationQuery::Hook::Manual && !this->HasHook(hook)) { |
| 353 | return 0; |
| 354 | } |
| 355 | |
| 356 | this->LockIndexing(); |
| 357 | |
| 358 | // Touch index file immediately to claim snippets |
| 359 | std::string suffix_time = ComputeSuffixTime(); |
| 360 | std::string const& index_name = cmStrCat("index-", suffix_time, ".json"); |
| 361 | std::string index_path = cmStrCat(this->dataDir, "/index/", index_name); |
| 362 | cmSystemTools::Touch(index_path, true); |
| 363 | |
| 364 | // Gather Snippets |
| 365 | using snippet = std::pair<std::string, std::string>; |
| 366 | std::vector<snippet> files; |
| 367 | cmsys::Directory d; |
| 368 | std::string last_index_name = |
| 369 | this->GetFileByTimestamp(LatestOrOldest::Latest, "index", index_name); |
| 370 | std::string last_index_path = |
| 371 | cmStrCat(this->dataDir, "/index/", last_index_name); |
| 372 | if (d.Load(this->dataDir)) { |
| 373 | for (unsigned int i = 0; i < d.GetNumberOfFiles(); i++) { |
| 374 | std::string fpath = d.GetFilePath(i); |
| 375 | std::string fname = d.GetFile(i); |
| 376 | if (fname.rfind('.', 0) == 0 || d.FileIsDirectory(i)) { |
| 377 | continue; |
| 378 | } |
| 379 | files.push_back(snippet(std::move(fname), std::move(fpath))); |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | // Build Json Object |
| 384 | Json::Value index(Json::objectValue); |
| 385 | index["snippets"] = Json::arrayValue; |
| 386 | index["hook"] = cmInstrumentationQuery::HookString[hook]; |
| 387 | index["dataDir"] = this->dataDir; |
| 388 | index["buildDir"] = this->binaryDir; |
| 389 | if (this->HasOption( |
| 390 | cmInstrumentationQuery::Option::StaticSystemInformation)) { |
| 391 | this->InsertStaticSystemInformation(index); |
| 392 | } |
| 393 | |
| 394 | for (auto const& file : files) { |
| 395 | if (last_index_name.empty()) { |
| 396 | index["snippets"].append(file.first); |
| 397 | } else { |
| 398 | int compare; |
| 399 | cmSystemTools::FileTimeCompare(file.second, last_index_path, &compare); |
| 400 | if (compare == 1) { |
| 401 | index["snippets"].append(file.first); |
| 402 | } |
| 403 | } |
| 404 | } |
| 405 | |
| 406 | // Parse snippets into the Google trace file |