PageRenderTime 48ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/source2/IL2CPU/Cosmos.IL2CPU.Profiler/Program.cs

https://bitbucket.org/mvptracker/cosmos
C# | 99 lines | 73 code | 12 blank | 14 comment | 3 complexity | 41385ffbca9dbdde1e1e7750d43ee4a6 MD5 | raw file
Possible License(s): BSD-2-Clause
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Linq;
  5. using System.Reflection;
  6. using System.Reflection.Emit;
  7. using System.Text;
  8. using Cosmos.System;
  9. using Cosmos.Debug.Common;
  10. using Cosmos.Build.Common;
  11. using System.IO;
  12. using Console = System.Console;
  13. namespace Cosmos.IL2CPU.Profiler {
  14. class Program {
  15. // This program profiles the scanning engine.
  16. // In the future it may profile other aspects as well.
  17. static void Main(string[] args) {
  18. Program.DoScan();
  19. Console.WriteLine("Press any key to continue.");
  20. Console.ReadKey();
  21. }
  22. private static void DoScan()
  23. {
  24. var xSW = new Stopwatch();
  25. xSW.Start();
  26. string MDFFile = AppDomain.CurrentDomain.BaseDirectory + "TestKernel.mdf";
  27. if (File.Exists(MDFFile))
  28. File.Delete(MDFFile);
  29. var outFile = AppDomain.CurrentDomain.BaseDirectory + "TestKernel.out";
  30. if (File.Exists(outFile))
  31. File.Delete(outFile);
  32. var logFile = AppDomain.CurrentDomain.BaseDirectory + "TestKernel.log";
  33. if (File.Exists(logFile))
  34. File.Delete(logFile);
  35. var xAsmblr = new AppAssembler(1);
  36. using (var xScanner = new ILScanner(xAsmblr))
  37. {
  38. using (var xDebugInfo = new DebugInfo(MDFFile, true))
  39. {
  40. xAsmblr.DebugInfo = xDebugInfo;
  41. xAsmblr.DebugEnabled = true;
  42. xAsmblr.DebugMode = DebugMode.Source;
  43. xAsmblr.TraceAssemblies = TraceAssemblies.All;
  44. xAsmblr.IgnoreDebugStubAttribute = false;
  45. xAsmblr.Assembler.Initialize();
  46. //TODO: Add plugs into the scanning equation to profile scanning them too
  47. //System.Reflection.MethodInfo[] name = typeof(SSchockeTest.Kernel).GetMethods();
  48. Type xFoundType = typeof(FakeKernel);
  49. var xCtor = xFoundType.GetConstructor(Type.EmptyTypes);
  50. typeof(Cosmos.System.Plugs.System.System.ConsoleImpl).IsSubclassOf(typeof(object));
  51. var xEntryPoint = typeof(Kernel).GetMethod("Start", BindingFlags.Public | BindingFlags.Instance);
  52. //var xEntryPoint = typeof(Program).GetMethod("ScannerEntryPoint", BindingFlags.NonPublic | BindingFlags.Static);
  53. //EnableLogging(pathToLogFile)
  54. xScanner.EnableLogging(logFile);
  55. //xScanner.TempDebug += new Action<string>(xScanner_TempDebug);
  56. //xScanner.
  57. xScanner.QueueMethod(xEntryPoint);
  58. xScanner.Execute(xCtor);
  59. using (var xOut = new StreamWriter(outFile, false))
  60. {
  61. //if (EmitDebugSymbols) {
  62. xAsmblr.Assembler.FlushText(xOut);
  63. xAsmblr.FinalizeDebugInfo();
  64. }
  65. xSW.Stop();
  66. Console.WriteLine("Total time : {0}", xSW.Elapsed);
  67. Console.WriteLine("Method count: {0}", xScanner.MethodCount);
  68. //Console.WriteLine("Instruction count: {0}", xScanner.InstructionCount);
  69. }
  70. }
  71. }
  72. static void xScanner_TempDebug(string obj)
  73. {
  74. Console.WriteLine(obj);
  75. }
  76. // This is a dummy entry point for the scanner to start at.
  77. // Its not even a Cosmos app, just a standard Windows console app,
  78. // but that fine for the scanner profiling as it does
  79. // not actually compile it.
  80. private static void ScannerEntryPoint() {
  81. Console.WriteLine("Hello, World!");
  82. var xInt = 0;
  83. object xObj = xInt;
  84. xObj.ToString();
  85. }
  86. }
  87. }