MCPcopy Create free account
hub / github.com/aras-p/ClangBuildAnalyzer / LoadBuildEvents

Function LoadBuildEvents

src/BuildEvents.cpp:631–696  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

629}
630
631bool LoadBuildEvents(const std::string& fileName, BuildEvents& outEvents, BuildNames& outNames)
632{
633 FILE* f = fopen(fileName.c_str(), "rb");
634 if (f == nullptr)
635 {
636 printf("%sERROR: failed to open file '%s'%s\n", col::kRed, fileName.c_str(), col::kReset);
637 return false;
638 }
639
640 BufferedReader r(f);
641 if (r.bufferSize < 12) // 4 bytes magic header, 8 bytes hash at end
642 {
643 printf("%sERROR: corrupt input file '%s' (size too small)%s\n", col::kRed, fileName.c_str(), col::kReset);
644 return false;
645 }
646 // check header magic
647 int32_t magic = 0;
648 r.Read(magic);
649 if (magic != kFileMagic)
650 {
651 printf("%sERROR: unknown format of input file '%s'%s\n", col::kRed, fileName.c_str(), col::kReset);
652 return false;
653 }
654 // chech hash checksum
655 XXH64_hash_t hash = XXH64(r.buffer, r.bufferSize-sizeof(XXH64_hash_t), 0);
656 if (memcmp(&hash, r.buffer+r.bufferSize-sizeof(XXH64_hash_t), sizeof(XXH64_hash_t)) != 0)
657 {
658 printf("%sERROR: corrupt input file '%s' (checksum mismatch)%s\n", col::kRed, fileName.c_str(), col::kReset);
659 return false;
660 }
661
662 int64_t eventsCount = 0;
663 r.Read(eventsCount);
664 outEvents.resize(eventsCount);
665 for(auto& e : outEvents)
666 {
667 int32_t eType;
668 r.Read(eType);
669 e.type = (BuildEventType)eType;
670 r.Read(e.ts);
671 r.Read(e.dur);
672 r.Read(e.detailIndex.idx);
673 r.Read(e.parent.idx);
674 int64_t childCount = 0;
675 r.Read(childCount);
676 e.children.resize(childCount);
677 if (childCount != 0)
678 r.Read(&e.children[0], childCount * sizeof(e.children[0]));
679 }
680
681 int64_t namesCount = 0;
682 r.Read(namesCount);
683 outNames.resize(namesCount);
684 for(auto& n : outNames)
685 {
686 uint32_t nSize = 0;
687 r.Read(nSize);
688 char* ptr = (char*)ArenaAllocate(nSize+1);

Callers 1

RunAnalyzeFunction · 0.85

Calls 2

ArenaAllocateFunction · 0.85
ReadMethod · 0.80

Tested by

no test coverage detected