From 69746948305b89a36a328b3a41ab8ce41d2ccf69 Mon Sep 17 00:00:00 2001 From: Clark Coleman <clc@zephyr-software.com> Date: Wed, 17 Apr 2019 17:56:30 -0400 Subject: [PATCH] Add virtual memory tracking output. --- include/interfaces/abstract/STARSInterface.h | 19 ++++++++++++++++++- src/base/SMPProgram.cpp | 11 +++++++++++ src/drivers/idapro/SMPStaticAnalyzer.cpp | 8 ++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/include/interfaces/abstract/STARSInterface.h b/include/interfaces/abstract/STARSInterface.h index a3bb9802..2cd28cf4 100644 --- a/include/interfaces/abstract/STARSInterface.h +++ b/include/interfaces/abstract/STARSInterface.h @@ -3,6 +3,11 @@ #include <cstdio> +#if __unix__ +#include <sys/time.h> +#include <sys/resource.h> +#endif + class STARS_Program_t; class STARS_Function_t; @@ -79,7 +84,19 @@ class STARS_Interface_t virtual bool InstHasNoCodeXrefs(STARS_InstructionID_t InstID) const = 0; virtual bool IsInstJumpTarget(STARS_InstructionID_t InstID) const = 0; virtual STARS_InstructionID_t FindFirstCallTarget(STARS_InstructionID_t CallInstID) const = 0; // Find call target; first one, if any, for indirect call - +#if __unix__ + virtual long GetMemoryInUse(void) const { // return max resident size in MB + struct rusage *usage = (struct rusage *) malloc(sizeof(struct rusage) + 8); + getrusage(RUSAGE_SELF, usage); + long MBUsed = (usage->ru_maxrss / 1024L); + (void) free(usage); + return MBUsed; + } +#else + virtual long GetMemoryInUse(void) const { + return 0L; + } +#endif /* IDA-only auditing */ virtual void AuditTailChunkOwnership(void) = 0; virtual void AuditCodeTargets(void) = 0; diff --git a/src/base/SMPProgram.cpp b/src/base/SMPProgram.cpp index 6af9ae55..3d4d6a20 100644 --- a/src/base/SMPProgram.cpp +++ b/src/base/SMPProgram.cpp @@ -477,6 +477,7 @@ void SMPProgram::Analyze(ProfilerInformation *pi, FILE *AnnotFile, FILE *InfoAnn EndTime = time(NULL); double TimeDiff = difftime(EndTime, StartTime); SMP_msg("INFO: TIME: Phase 1: AnalyzeFunc: %7.2f\n", TimeDiff); + SMP_msg("INFO: VMEM: Phase 1: Maximum resident memory usage in MB: %ld \n", global_stars_interface->GetMemoryInUse()); StartTime = time(NULL); if (global_STARS_program->ShouldSTARSPerformReducedAnalysis()) { @@ -527,6 +528,7 @@ void SMPProgram::Analyze(ProfilerInformation *pi, FILE *AnnotFile, FILE *InfoAnn EndTime = time(NULL); TimeDiff = difftime(EndTime, StartTime); SMP_msg("INFO: TIME: Phase 2: AdvancedAnalysis: %7.2f\n", TimeDiff); + SMP_msg("INFO: VMEM: Phase 2: Maximum resident memory usage in MB: %ld \n", global_stars_interface->GetMemoryInUse()); StartTime = time(NULL); // In order to reduce memory consumption, emit the global data annotations now, @@ -541,6 +543,7 @@ void SMPProgram::Analyze(ProfilerInformation *pi, FILE *AnnotFile, FILE *InfoAnn EndTime = time(NULL); TimeDiff = difftime(EndTime, StartTime); SMP_msg("INFO: TIME: Phase 3: EmitDataAnnotations: %7.2f\n", TimeDiff); + SMP_msg("INFO: VMEM: Phase 3: Maximum resident memory usage in MB: %ld \n", global_stars_interface->GetMemoryInUse()); StartTime = time(NULL); #ifndef SMP_REDUCED_ANALYSIS @@ -625,6 +628,7 @@ void SMPProgram::Analyze(ProfilerInformation *pi, FILE *AnnotFile, FILE *InfoAnn TimeDiff = difftime(EndTime, StartTime); SMP_msg("INFO: TIME: Phase 4: SSA+SCCP+FuncSafe+AliasAnalysis: %7.2f SSA: %7.2f SCCP: %7.2f AliasAnalysis: %7.2f FuncSafe: %7.2f\n", TimeDiff, Analysis1, Analysis2, Analysis3, Analysis5); + SMP_msg("INFO: VMEM: Phase 4: Maximum resident memory usage in MB: %ld \n", global_stars_interface->GetMemoryInUse()); #if 0 // need to debug // Remove any basic blocks that had a direct indication of being unreachable, e.g. "call 0" instruction. @@ -668,6 +672,7 @@ void SMPProgram::Analyze(ProfilerInformation *pi, FILE *AnnotFile, FILE *InfoAnn EndTime = time(NULL); TimeDiff = difftime(EndTime, StartTime); SMP_msg("INFO: TIME: Phase 5: RetAddrStatus: %7.2f\n", TimeDiff); + SMP_msg("INFO: VMEM: Phase 5: Maximum resident memory usage in MB: %ld \n", global_stars_interface->GetMemoryInUse()); StartTime = time(NULL); Analysis1 = Analysis2 = Analysis3 = Analysis4 = Analysis5 = 0.0; @@ -802,6 +807,7 @@ void SMPProgram::Analyze(ProfilerInformation *pi, FILE *AnnotFile, FILE *InfoAnn TimeDiff = difftime(EndTime, StartTime); SMP_msg("INFO: TIME: Phase 6: MetaData+InferTypes+InferFG: %7.2f InOutRegs: %7.2f UnsafeCallees: %7.2f Metadata: %7.2f InferTypes: %7.2f InferFG: %7.2f\n", TimeDiff, Analysis1, Analysis2, Analysis3, Analysis4, Analysis5); + SMP_msg("INFO: VMEM: Phase 6: Maximum resident memory usage in MB: %ld \n", global_stars_interface->GetMemoryInUse()); // STEP 4A: Interprocedural CFG return target analysis. StartTime = time(NULL); @@ -878,6 +884,8 @@ void SMPProgram::Analyze(ProfilerInformation *pi, FILE *AnnotFile, FILE *InfoAnn EndTime = time(NULL); TimeDiff = difftime(EndTime, StartTime); SMP_msg("INFO: TIME: Phase 7: ReturnTargets + InterproceduralTypes + InArgTypes + TraceInArgs: %7.2f\n", TimeDiff); + SMP_msg("INFO: VMEM: Phase 7: Maximum resident memory usage in MB: %ld \n", global_stars_interface->GetMemoryInUse()); + // Loop 7B: Loop iteration and memory access analysis. Time4 = time(NULL); @@ -897,6 +905,7 @@ void SMPProgram::Analyze(ProfilerInformation *pi, FILE *AnnotFile, FILE *InfoAnn Time5 = time(NULL); TimeDiff = difftime(Time5, Time4); SMP_msg("INFO: TIME: Phase 7B: LoopIter: %7.2f \n", TimeDiff); + SMP_msg("INFO: VMEM: Phase 7B: Maximum resident memory usage in MB: %ld \n", global_stars_interface->GetMemoryInUse()); StartTime = time(NULL); if (global_STARS_program->ShouldSTARSPerformConstantPropagation()) { @@ -913,6 +922,7 @@ void SMPProgram::Analyze(ProfilerInformation *pi, FILE *AnnotFile, FILE *InfoAnn EndTime = time(NULL); TimeDiff = difftime(EndTime, StartTime); SMP_msg("INFO: TIME: Phase 7C: AnalyzeBufferUses: %7.2f\n", TimeDiff); + SMP_msg("INFO: VMEM: Phase 7C: Maximum resident memory usage in MB: %ld \n", global_stars_interface->GetMemoryInUse()); } // Free memory not needed to emit annotations, now that type inference is done. @@ -1181,6 +1191,7 @@ void SMPProgram::EmitAnnotations(FILE *AnnotFile, FILE *InfoAnnotFile) { EndTime = time(NULL); double TimeDiff = difftime(EndTime, StartTime); SMP_msg("INFO: TIME: Phase 8: EmitAnnotations: %7.2f\n", TimeDiff); + SMP_msg("INFO: VMEM: Phase 8: Maximum resident memory usage in MB: %ld \n", global_stars_interface->GetMemoryInUse()); if (global_STARS_program->ShouldSTARSTranslateToSPARKAda()) { SMP_msg("SPARK: Total subword registers translated: %lu\n", SubwordRegCount); diff --git a/src/drivers/idapro/SMPStaticAnalyzer.cpp b/src/drivers/idapro/SMPStaticAnalyzer.cpp index d6fd2f26..6b9911f8 100644 --- a/src/drivers/idapro/SMPStaticAnalyzer.cpp +++ b/src/drivers/idapro/SMPStaticAnalyzer.cpp @@ -369,6 +369,14 @@ bool IDAP_run(size_t arg) { SMP_msg("IDA SDK version: %d \n", IDA_SDK_VERSION); +#if __unix__ + SMP_msg("INFO: Compiled in Unix environment.\n"); +#elif __win32 + SMP_msg("INFO: Compiled in Windows 32 or 64 environment.\n"); +#else + SMP_msg("INFO: Compiled in unknown environment.\n"); +#endif + DefOrUse DummyRef; STARSOpndType DummyOperand; std::size_t RefObjectSize = sizeof(DummyRef), OpndSize = sizeof(DummyOperand); -- GitLab