diff --git a/kram-profile/CBA/CBA.h b/kram-profile/CBA/CBA.h index 753bdd7..8fa184b 100644 --- a/kram-profile/CBA/CBA.h +++ b/kram-profile/CBA/CBA.h @@ -2,5 +2,13 @@ // TODO: move to header @interface CBA : NSObject -+ (NSString* _Nonnull)RunCBA:(NSArray * _Nonnull)files filenames:(NSArray * _Nonnull)filenames; + +- (_Nonnull instancetype)init; +- (void)deinit; + +- (void)parse:(NSData* _Nonnull)file filename:(NSString* _Nonnull)filename; +- (void)parseAll:(NSArray * _Nonnull)files filenames:(NSArray * _Nonnull)filenames; + +- (NSString* _Nonnull)analyze; + @end diff --git a/kram-profile/CBA/CBA.mm b/kram-profile/CBA/CBA.mm index 6a22c06..5bafaec 100644 --- a/kram-profile/CBA/CBA.mm +++ b/kram-profile/CBA/CBA.mm @@ -26,30 +26,51 @@ @implementation CBA { + BuildEventsParser* parser; } -+ (NSString* _Nonnull)RunCBA:(NSArray * _Nonnull)files filenames:(NSArray * _Nonnull)filenames -{ +- (_Nonnull instancetype)init { ArenaInitialize(); - BuildEventsParser* parser = CreateBuildEventsParser(); - - for (uint32_t i = 0; i < files.count; ++i) - { - NSData* data = files[i]; - ParseBuildEvents(parser, (const uint8_t*)data.bytes, data.length, [filenames[i] UTF8String]); + parser = CreateBuildEventsParser(); + + return self; +} + +- (void)deinit { + // Shutdown the parser + DeleteBuildEventsParser(parser); + parser = nullptr; + + ArenaDelete(); +} + +// This is bad because it runs single-threaded, and doesn't cache anything across builds. +// TODO: restructure, so parser is built once +// feed files to it individually, and then request analysis on a few of the events/names +// TODO: reformat output to Perfetto json, can then display it visually. +- (void)parseAll:(NSArray * _Nonnull)files filenames:(NSArray * _Nonnull)filenames +{ + for (uint32_t i = 0; i < files.count; ++i) { + [self parse:files[i] filename:filenames[i]]; } +} + +- (void)parse:(NSData* _Nonnull)file filename:(NSString* _Nonnull)filename { + const char* filename_ = [filename UTF8String]; + ParseBuildEvents(parser, (const uint8_t*)file.bytes, file.length, filename_); +} + +- (NSString* _Nonnull)analyze { // Run the analysis on data from the parser. std::string out; DoAnalysis(GetBuildEvents(*parser), GetBuildNames(*parser), out); - // Shutdown the parser - DeleteBuildEventsParser(parser); - ArenaDelete(); - return [NSString stringWithUTF8String:out.c_str()]; } + + @end diff --git a/kram-profile/CBA/Utils.cpp b/kram-profile/CBA/Utils.cpp index 31e37a9..851a0e2 100755 --- a/kram-profile/CBA/Utils.cpp +++ b/kram-profile/CBA/Utils.cpp @@ -30,7 +30,8 @@ bool utils::BeginsWith(const std::string& str, const std::string& prefix) } return true; } - +*/ + bool utils::EndsWith(const std::string_view& str, const std::string& suffix) { if (str.size() < suffix.size()) @@ -45,8 +46,6 @@ bool utils::EndsWith(const std::string_view& str, const std::string& suffix) } return true; } -*/ - bool utils::IsHeader(std::string_view path) { diff --git a/kram-profile/CBA/Utils.h b/kram-profile/CBA/Utils.h index 55395e5..52f5e5f 100755 --- a/kram-profile/CBA/Utils.h +++ b/kram-profile/CBA/Utils.h @@ -15,6 +15,7 @@ namespace utils void Lowercase(std::string& path); [[nodiscard]] bool BeginsWith(const std::string& str, const std::string& prefix); + */ [[nodiscard]] bool EndsWith(const std::string_view& str, const std::string& suffix); - */ + } diff --git a/kram-profile/kram-profile.xcodeproj/project.pbxproj b/kram-profile/kram-profile.xcodeproj/project.pbxproj index 362b8ab..85b57c0 100644 --- a/kram-profile/kram-profile.xcodeproj/project.pbxproj +++ b/kram-profile/kram-profile.xcodeproj/project.pbxproj @@ -317,6 +317,7 @@ MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = YES; + OTHER_CFLAGS = "-ftime-trace"; SDKROOT = macosx; SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)"; SWIFT_OBJC_INTEROP_MODE = objc; @@ -365,6 +366,7 @@ CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = NO; + DEAD_CODE_STRIPPING = YES; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; @@ -381,6 +383,7 @@ MACOSX_DEPLOYMENT_TARGET = 13.0; MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; + OTHER_CFLAGS = "-ftime-trace"; SDKROOT = macosx; SWIFT_ACTIVE_COMPILATION_CONDITIONS = ""; SWIFT_COMPILATION_MODE = wholemodule; diff --git a/kram-profile/kram-profile/kram_profileApp.swift b/kram-profile/kram-profile/kram_profileApp.swift index 694bb18..fdbdba7 100644 --- a/kram-profile/kram-profile/kram_profileApp.swift +++ b/kram-profile/kram-profile/kram_profileApp.swift @@ -2407,8 +2407,10 @@ A tool to help profile mem, perf, and builds. } // Extract the fileContent and names. This avoids CBA needing to do IO. // But CBA is reparsing all of the json in C++ to build up its tables. - // Also demangling names again.. - let cbaReport = CBA.run(fileDatas, filenames: filenames) + // Also demangling names again. + let cba = CBA() + cba.parseAll(fileDatas, filenames: filenames) + let cbaReport = cba.analyze() // Can't use log here, since it's not setup to chop up long // strings by newlines yet. Print doesn't go to console