public DiagnosticAssembly Compile(string script, DiagnosticAssemblyMode mode, DiagnosticAssembyPlatform platform) { var syntaxTree = CSharpSyntaxTree.ParseText(script); UpdateLog("Script parsed."); string assemblyName = $"assemblyName_{DateTime.Now.Ticks}"; OptimizationLevel compilationLevel = mode == DiagnosticAssemblyMode.Release //cbMode.SelectedItem.ToString() == "Release" ? OptimizationLevel.Release : OptimizationLevel.Debug; Platform compilationPlatform = platform == DiagnosticAssembyPlatform.x64 ? Platform.X64 : Platform.X86; CSharpCompilation compilation = CSharpCompilation.Create( assemblyName, new[] { syntaxTree }, new[] { MetadataReference.CreateFromFile(typeof(object).Assembly.Location), MetadataReference.CreateFromFile(typeof(Vector).Assembly.Location) }, new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, optimizationLevel: compilationLevel, allowUnsafe: true, platform: compilationPlatform)); var result = new DiagnosticAssembly(this, assemblyName, compilation); return(result); }
private async Task <bool> RunAsync(string script, string argument, DiagnosticAssemblyMode level, DiagnosticAssembyPlatform platform) { try { var assembly = engine.Compile(script, level, platform); string result = assembly.Execute(argument); this.IlText = assembly.DumpIL(); this.AsmText = assembly.DumpASM(); var dataGen0 = assembly.HeapStatsData.Select(x => new DateViewModel() { DateTime = x.TimeStamp, Value = x.GenerationSize0, Tag = x }); var dataGen1 = assembly.HeapStatsData.Select(x => new DateViewModel() { DateTime = x.TimeStamp, Value = x.GenerationSize1, Tag = x }); var dataGen2 = assembly.HeapStatsData.Select(x => new DateViewModel() { DateTime = x.TimeStamp, Value = x.GenerationSize2, Tag = x }); var gcs = assembly.GcData.Select(x => new AxisSection() { SectionOffset = (double)x.TimeStamp.Subtract(TimeSpan.FromMilliseconds(1.0)).Ticks, SectionWidth = (double)TimeSpan.FromMilliseconds(1.0).Ticks }); var gcsLabels = assembly.GcData.Select(x => new VisualElement { X = (double)x.TimeStamp.Ticks, Y = 0.0, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Top, UIElement = new Button() { Content = x.Generation.ToString(), Background = Brushes.White } }); System.Windows.Application.Current.Dispatcher.Invoke(() => { var seriesGen0 = new LineSeries(mapper) { Title = "Gen0", LineSmoothness = 0, PointGeometry = DefaultGeometries.Circle, PointGeometrySize = 6 }; seriesGen0.Values = dataGen0.AsChartValues(); var seriesGen1 = new LineSeries(mapper) { Title = "Gen1", LineSmoothness = 0, PointGeometry = DefaultGeometries.Circle, PointGeometrySize = 6 }; seriesGen1.Values = dataGen1.AsChartValues(); var seriesGen2 = new LineSeries(mapper) { Title = "Gen2", LineSmoothness = 0, PointGeometry = DefaultGeometries.Circle, PointGeometrySize = 6 }; seriesGen2.Values = dataGen2.AsChartValues(); GraphDataGC.Clear(); GraphDataGC.Add(seriesGen0); GraphDataGC.Add(seriesGen1); GraphDataGC.Add(seriesGen2); GCSections.Clear(); GCSections.AddRange(gcs); GCSectionsLabels.Clear(); GCSectionsLabels.AddRange(gcsLabels); } ); this.GCEvents = new ObservableCollection <Core.Collectors.ClrEtwGcData>(assembly.GcData); this.RaisePropertyChanged(nameof(GCEvents)); // UpdateLog("Script processing ended."); return(true); } catch (Exception ex) { UpdateLog(ex.ToString()); return(false); } }