From 25719bf86964c0b65959e0bd3f08ffe756c64720 Mon Sep 17 00:00:00 2001 From: Rich Date: Mon, 19 Jan 2015 20:50:15 +0000 Subject: [PATCH] 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 --- .../Generated/Database.cs | 39 ++++++++++++++++++- .../Generated/ItemInfo.cs | 3 ++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Database.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Database.cs index 96a6766e..9429e79a 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/Database.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Database.cs @@ -19,6 +19,7 @@ using System.ComponentModel; using System.Diagnostics; using System.Collections.Generic; using System.Text.RegularExpressions; +using Volian.Base.Library; namespace VEPROMS.CSLA.Library { @@ -71,13 +72,41 @@ namespace VEPROMS.CSLA.Library get { return Database._ConnectionName; } 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 _Methods = new Dictionary(); + public static void ShowDBTracking(string fileName) + { + DebugDBTrack.Open(VlnSettings.TemporaryFolder + "\\" + fileName); + ShowDictionary(); + DebugDBTrack.Show(); + } private static string _VEPROMS_Connection; public static string VEPROMS_Connection { get { - if (_VEPROMS_Connection != null) // Use Lazy Load + if (TrackDBUsage) + { + string str = Volian.Base.Library.vlnStackTrace.CalledFromCSLA; + //if (str.Contains("ItemAndChildren")) + //{ + // ShowDictionary(Methods); + // Methods = new Dictionary(); + //} + if (!_Methods.ContainsKey(str)) + _Methods.Add(str, 1); + else + _Methods[str]++; + } + if (_VEPROMS_Connection != null ) // Use Lazy Load + { return _VEPROMS_Connection; + } DateTime.Today.ToLongDateString(); // If DBConnection.XML exists, use the connection string from DBConnection.XML string cnOverride = System.Windows.Forms.Application.StartupPath + @"\DBConnection.XML"; @@ -118,6 +147,14 @@ namespace VEPROMS.CSLA.Library } 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) { string serverName = Volian.Base.Library.VlnSettings.GetCommand("Server",null); diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ItemInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ItemInfo.cs index 4d2ccd39..120b261e 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/ItemInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ItemInfo.cs @@ -17,6 +17,7 @@ using System.Configuration; using System.IO; using System.ComponentModel; using System.Collections.Generic; +using Volian.Base.Library; namespace VEPROMS.CSLA.Library { public delegate void ItemInfoEvent(object sender); @@ -313,11 +314,13 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { + //int profileDepth = ProfileTimer.Push(">>>> ItemParts"); CanReadProperty("ItemParts", true); if (_ItemPartCount < 0 || (_ItemPartCount > 0 && _ItemParts == null)) _ItemParts = PartInfoList.GetByItemID(_ItemID); if (_ItemPartCount < 0) _ItemPartCount = _ItemParts.Count; + //ProfileTimer.Pop(profileDepth); return _ItemParts; } }