Browse Source

- fixed bugs with profiling read-only projects and Unit Tests

- fixed bug in UnitTesting-AddIn, if unit testing was canceled before the execution had started

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@4089 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Siegfried Pammer 16 years ago
parent
commit
354a00107b
  1. 32
      src/AddIns/Misc/Profiler/Frontend/AddIn/Src/Commands/ProfileProject.cs
  2. 13
      src/AddIns/Misc/UnitTesting/Src/RunTestCommands.cs
  3. 29
      src/AddIns/Misc/UnitTesting/Src/TestResultsMonitor.cs
  4. 27
      src/Main/Base/Project/Src/Services/Profiler/ProfilerService.cs

32
src/AddIns/Misc/Profiler/Frontend/AddIn/Src/Commands/ProfileProject.cs

@ -6,17 +6,10 @@ @@ -6,17 +6,10 @@
// </file>
using System;
using System.Globalization;
using System.IO;
using System.Windows.Forms;
using ICSharpCode.Core;
using ICSharpCode.Profiler.AddIn.Views;
using ICSharpCode.Profiler.Controller.Data;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Profiling;
using ICSharpCode.SharpDevelop.Project;
using Microsoft.Build.BuildEngine;
namespace ICSharpCode.Profiler.AddIn.Commands
{
@ -32,32 +25,15 @@ namespace ICSharpCode.Profiler.AddIn.Commands @@ -32,32 +25,15 @@ namespace ICSharpCode.Profiler.AddIn.Commands
/// </summary>
public override void Run()
{
AbstractProject currentProj = ProjectService.CurrentProject as AbstractProject;
string filePart = @"ProfilingSessions\Session" +
DateTime.Now.ToString("yyyyMMdd_HHmmss", CultureInfo.InvariantCulture) +
".sdps";
string path = Path.Combine(currentProj.Directory, filePart);
IProject currentProj = ProjectService.CurrentProject;
string path = ProfilerService.GetSessionFileName(currentProj);
Directory.CreateDirectory(Path.GetDirectoryName(path));
IProfilingDataWriter writer = new ProfilingDataSQLiteWriter(path);
ProfilerRunner runner = WindowsProfiler.CreateRunner(writer);
if (runner != null) {
runner.RunFinished += delegate {
Action updater = () => {
FileService.OpenFile(path);
FileProjectItem file = new FileProjectItem(currentProj, ItemType.Content, "ProfilingSessions\\" + Path.GetFileName(path));
ProjectService.AddProjectItem(currentProj, file);
ProjectBrowserPad.Instance.ProjectBrowserControl.RefreshView();
currentProj.Save();
};
WorkbenchSingleton.SafeThreadCall(updater);
};
runner.RunFinished += delegate { ProfilerService.AddSessionToProject(currentProj, path); };
runner.Run();
}
}

13
src/AddIns/Misc/UnitTesting/Src/RunTestCommands.cs

@ -5,17 +5,18 @@ @@ -5,17 +5,18 @@
// <version>$Revision$</version>
// </file>
using ICSharpCode.SharpDevelop.Profiling;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Commands;
using ICSharpCode.SharpDevelop.Debugging;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Profiling;
using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.SharpDevelop.Project.Commands;
using ICSharpCode.SharpDevelop.Util;
@ -532,15 +533,7 @@ namespace ICSharpCode.UnitTesting @@ -532,15 +533,7 @@ namespace ICSharpCode.UnitTesting
void AfterFinish(UnitTestApplicationStartHelper helper, string path)
{
Action updater = delegate {
FileService.OpenFile(path);
FileProjectItem file = new FileProjectItem(helper.Project, ItemType.Content, "ProfilingSessions\\" + Path.GetFileName(path));
ProjectService.AddProjectItem(helper.Project, file);
ProjectBrowserPad.Instance.ProjectBrowserControl.RefreshView();
helper.Project.Save();
};
WorkbenchSingleton.SafeThreadCall(updater);
ProfilerService.AddSessionToProject(helper.Project, path);
WorkbenchSingleton.SafeThreadAsyncCall(TestsFinished);
}

29
src/AddIns/Misc/UnitTesting/Src/TestResultsMonitor.cs

@ -138,19 +138,24 @@ namespace ICSharpCode.UnitTesting @@ -138,19 +138,24 @@ namespace ICSharpCode.UnitTesting
string ReadTextAdded()
{
StringBuilder text = null;
using (FileStream fs = new FileStream(fileInfo.FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) {
if (fs.Length > 0) {
text = new StringBuilder();
int bytesRead = 0;
fs.Seek(filePosition, SeekOrigin.Begin);
do {
bytesRead = fs.Read(bytes, 0, BytesBufferLength);
if (bytesRead > 0) {
filePosition += bytesRead;
text.Append(UTF8Encoding.UTF8.GetString(bytes, 0, bytesRead));
}
} while (bytesRead > 0 && filePosition < fs.Length);
try {
using (FileStream fs = new FileStream(fileInfo.FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) {
if (fs.Length > 0) {
text = new StringBuilder();
int bytesRead = 0;
fs.Seek(filePosition, SeekOrigin.Begin);
do {
bytesRead = fs.Read(bytes, 0, BytesBufferLength);
if (bytesRead > 0) {
filePosition += bytesRead;
text.Append(UTF8Encoding.UTF8.GetString(bytes, 0, bytesRead));
}
} while (bytesRead > 0 && filePosition < fs.Length);
}
}
} catch (FileNotFoundException) {
// Test was aborted before it even started execution
return null;
}
if (text != null) {
return text.ToString();

27
src/Main/Base/Project/Src/Services/Profiler/ProfilerService.cs

@ -10,6 +10,7 @@ using System.Globalization; @@ -10,6 +10,7 @@ using System.Globalization;
using System.IO;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Project;
namespace ICSharpCode.SharpDevelop.Profiling
@ -54,21 +55,31 @@ namespace ICSharpCode.SharpDevelop.Profiling @@ -54,21 +55,31 @@ namespace ICSharpCode.SharpDevelop.Profiling
}
public static string GetSessionFileName(IProject project)
{
AbstractProject currentProj = ProjectService.CurrentProject as AbstractProject;
if (currentProj == null)
throw new InvalidOperationException("Can not profile project");
string filePart = @"ProfilingSessions\Session" +
{
string filename = @"ProfilingSessions\Session" +
DateTime.Now.ToString("yyyyMMdd_HHmmss", CultureInfo.InvariantCulture) +
".sdps";
string path = Path.Combine(currentProj.Directory, filePart);
string path = Path.Combine(project.Directory, filename);
Directory.CreateDirectory(Path.GetDirectoryName(path));
return path;
}
public static void AddSessionToProject(IProject project, string path)
{
Action updater = () => {
FileService.OpenFile(path);
if (!project.ReadOnly) {
FileProjectItem file = new FileProjectItem(project, ItemType.Content, "ProfilingSessions\\" + Path.GetFileName(path));
ProjectService.AddProjectItem(project, file);
ProjectBrowserPad.Instance.ProjectBrowserControl.RefreshView();
project.Save();
}
};
WorkbenchSingleton.SafeThreadCall(updater);
}
}
}

Loading…
Cancel
Save