Added code to Track DB Usage. Uses the StackTrace to find which object and method are being used when the database is being used.

Added Profile debug
This commit is contained in:
Rich 2015-01-19 20:50:15 +00:00
parent 29ffd0329c
commit 25719bf869
2 changed files with 41 additions and 1 deletions

View File

@ -19,6 +19,7 @@ using System.ComponentModel;
using System.Diagnostics; using System.Diagnostics;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Volian.Base.Library;
namespace VEPROMS.CSLA.Library namespace VEPROMS.CSLA.Library
{ {
@ -71,13 +72,41 @@ namespace VEPROMS.CSLA.Library
get { return Database._ConnectionName; } get { return Database._ConnectionName; }
set { Database._ConnectionName = value; _VEPROMS_Connection = null; /* Reset Connection */ } set { Database._ConnectionName = value; _VEPROMS_Connection = null; /* Reset Connection */ }
} }
private static bool _TrackDBUsage = false;
public static bool TrackDBUsage
{
get { return _TrackDBUsage; }
set { _TrackDBUsage = value; }
}
private static Dictionary<string, int> _Methods = new Dictionary<string, int>();
public static void ShowDBTracking(string fileName)
{
DebugDBTrack.Open(VlnSettings.TemporaryFolder + "\\" + fileName);
ShowDictionary();
DebugDBTrack.Show();
}
private static string _VEPROMS_Connection; private static string _VEPROMS_Connection;
public static string VEPROMS_Connection public static string VEPROMS_Connection
{ {
get get
{ {
if (TrackDBUsage)
{
string str = Volian.Base.Library.vlnStackTrace.CalledFromCSLA;
//if (str.Contains("ItemAndChildren"))
//{
// ShowDictionary(Methods);
// Methods = new Dictionary<string, int>();
//}
if (!_Methods.ContainsKey(str))
_Methods.Add(str, 1);
else
_Methods[str]++;
}
if (_VEPROMS_Connection != null ) // Use Lazy Load if (_VEPROMS_Connection != null ) // Use Lazy Load
{
return _VEPROMS_Connection; return _VEPROMS_Connection;
}
DateTime.Today.ToLongDateString(); DateTime.Today.ToLongDateString();
// If DBConnection.XML exists, use the connection string from DBConnection.XML // If DBConnection.XML exists, use the connection string from DBConnection.XML
string cnOverride = System.Windows.Forms.Application.StartupPath + @"\DBConnection.XML"; string cnOverride = System.Windows.Forms.Application.StartupPath + @"\DBConnection.XML";
@ -118,6 +147,14 @@ namespace VEPROMS.CSLA.Library
} }
set { _VEPROMS_Connection = value; } set { _VEPROMS_Connection = value; }
} }
private static void ShowDictionary()
{
DebugDBTrack.WriteLine("\"Module\"\t\"Count\"");
foreach (string key in _Methods.Keys)
{
DebugDBTrack.WriteLine("\"{0}\"\t{1}", key, _Methods[key]);
}
}
private static string FixServer(string connectionString) private static string FixServer(string connectionString)
{ {
string serverName = Volian.Base.Library.VlnSettings.GetCommand("Server",null); string serverName = Volian.Base.Library.VlnSettings.GetCommand("Server",null);

View File

@ -17,6 +17,7 @@ using System.Configuration;
using System.IO; using System.IO;
using System.ComponentModel; using System.ComponentModel;
using System.Collections.Generic; using System.Collections.Generic;
using Volian.Base.Library;
namespace VEPROMS.CSLA.Library namespace VEPROMS.CSLA.Library
{ {
public delegate void ItemInfoEvent(object sender); public delegate void ItemInfoEvent(object sender);
@ -313,11 +314,13 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get get
{ {
//int profileDepth = ProfileTimer.Push(">>>> ItemParts");
CanReadProperty("ItemParts", true); CanReadProperty("ItemParts", true);
if (_ItemPartCount < 0 || (_ItemPartCount > 0 && _ItemParts == null)) if (_ItemPartCount < 0 || (_ItemPartCount > 0 && _ItemParts == null))
_ItemParts = PartInfoList.GetByItemID(_ItemID); _ItemParts = PartInfoList.GetByItemID(_ItemID);
if (_ItemPartCount < 0) if (_ItemPartCount < 0)
_ItemPartCount = _ItemParts.Count; _ItemPartCount = _ItemParts.Count;
//ProfileTimer.Pop(profileDepth);
return _ItemParts; return _ItemParts;
} }
} }