public void RecordInstructionCall(InstInstruction instruction) { AssertRecordingMode(); var instructionDescriptor = new InstructionDescriptor(instruction.Eip, instruction.Instruction); RegisterInstructionDescriptor(instructionDescriptor); var newInstructionCall = new InstructionCall(instructionDescriptor, instruction.CpuTime); InstructionCalls.Add(newInstructionCall); }
public CallGraph GenerateCallGraph() { var callGraph = new CallGraph(); callGraph.BeginRecording(); Console.WriteLine("Recording " + Elements.Count + " instructions in the call graph!"); if (Elements.Count == 0) { Console.WriteLine("No elements in this trace!"); callGraph.RecordFunctionCall(0, 0); callGraph.RecordFunctionReturn(1); callGraph.EndRecording(1); return(callGraph); } var firstCall = Elements.First(); var lastCall = Elements.Last(); callGraph.Annotations = Annotations; foreach (var instruction in Elements.Where(i => i is IDisasmElement)) { //if (instruction.Eip!=0) // Console.WriteLine("Found an instruction that's not at zero! It's at " + instruction.Eip); var instVersion = new InstInstruction(); instVersion.CpuTime = GetCallTime(instruction); instVersion.Eip = instruction.Eip; var disAsm = (instruction as IDisasmElement); if (disAsm != null) { instVersion.Instruction = disAsm.Disassembly; } else { instVersion.Instruction = "N/A"; } //if (instVersion != null) callGraph.RecordInstructionCall(instVersion); if (GetCallTime(instruction) > GetCallTime(lastCall)) { lastCall = instruction; } if (GetCallTime(instruction) < GetCallTime(firstCall)) { firstCall = instruction; } //Console.WriteLine("Recording instruction timing " + GetCallTime(instruction)); } //Console.WriteLine("Greatest instruction timing is " + GetCallTime(lastCall)); callGraph.RecordFunctionCall(0, GetCallTime(firstCall)); foreach (var instruction in Elements.Where(i => i is BranchElement).Cast <BranchElement>()) { if (instruction.BranchTypeName == BranchElement.BranchTypes.Call) { callGraph.RecordFunctionCall(instruction.ToEip, GetCallTime(instruction)); } else if (instruction.BranchTypeName == BranchElement.BranchTypes.Return) { callGraph.RecordFunctionReturn(GetCallTime(instruction)); } } callGraph.RecordFunctionReturn(GetCallTime(lastCall)); callGraph.EndRecording(GetCallTime(lastCall)); return(callGraph); }