internal void ResolveMethodNames(SnapshotEntity sf)
        {
            Tracer.Verbose("SnapshotService.ResolveMethodNames START", sf.FileName);

            try
            {
                List <MethodMapInfo> mapinfo;
                _Maps.TryGetValue(sf.MethodMapFile, out mapinfo);

                foreach (CallStackInfoExtended item in sf.CallstackEx)
                {
                    MethodMapInfo tmp = mapinfo.Single(p => p.Handle == item.MethodHandle);
                    item.Namespace  = tmp.Namespace;
                    item.MethodName = tmp.Method;

                    tmp           = mapinfo.Single(p => p.Handle == item.CalledByHandle);
                    item.CalledBy = tmp.Method;

                    Tracer.Info("SnapshotService.ResolveMethodNames METHOD", "Handle {0}==> Method{1} + Handle {2}==> Method {3}",
                                item.MethodHandle, item.MethodName, item.CalledByHandle, item.CalledBy);
                }
            }
            catch (Exception error)
            {
                Tracer.Error("SnapshotService.ResolveMethodNames", error);
            }
            finally
            {
                Tracer.Verbose("SnapshotService.ResolveMethodNames END", sf.FileName);
            }
        }
Example #2
0
        private void WatcherEvent(object sender, FileSystemEventArgs e)
        {
            Tracer.Verbose("InjectionProfiler.WatcherEvent START", e.Name);

            try
            {
                if (e.ChangeType == WatcherChangeTypes.Created)
                {
                    FileInfo       fi     = new FileInfo(e.FullPath);
                    SnapshotEntity entity = new SnapshotEntity()
                    {
                        DirectoryName = fi.DirectoryName,
                        FileName      = fi.Name,
                        Length        = fi.Length,
                        LastWriteTime = fi.LastWriteTime
                    };

                    base.Dispatcher.Invoke(DispatcherPriority.Normal, (ThreadStart) delegate
                    {
                        SnapshotService.Instance.Snapshots.Add(entity);
                    });
                }

                if (e.ChangeType == WatcherChangeTypes.Deleted)
                {
                    base.Dispatcher.Invoke(DispatcherPriority.Normal, (ThreadStart) delegate
                    {
                        SnapshotService.Instance.Snapshots.Remove(SnapshotService.Instance.Snapshots.Single(p => p.FullFileName == e.FullPath));
                    });
                }

                if (e.ChangeType == WatcherChangeTypes.Changed)
                {
                    SnapshotEntity se = SnapshotService.Instance.Snapshots.Single(p => p.FullFileName == e.FullPath);

                    if (se.Loaded)
                    {
                        base.Dispatcher.Invoke(DispatcherPriority.Normal, (ThreadStart) delegate
                        {
                            EventDispatcher.Instance.RaiseProject(null, ProjectEventType.SnapshotChange);
                            // TODO !
                            //if (MessageBoxDlg.Show(string.Format("Snapshot {0} has changed! Do you want to reload it ?", se.FileName),
                            //    "Warning", System.Windows.MessageBoxButton.YesNo, System.Windows.MessageBoxImage.Question) == System.Windows.MessageBoxResult.Yes)
                            //{
                            //    se.Loaded = false;
                            //    LoadSnapshot(se);
                            //}
                        });
                    }
                }
            }
            catch (Exception error)
            {
                Tracer.Error("InjectionProfiler.WatcherEvent", error);
            }
            finally
            {
                Tracer.Verbose("InjectionProfiler.WatcherEvent END", e.Name);
            }
        }
        internal bool LoadMap(SnapshotEntity sf)
        {
            Tracer.Verbose("SnapshotService.LoadMap started", sf.FileName);

            try
            {
                if (!_Maps.ContainsKey(sf.MethodMapFile))
                {
                    Tracer.Info("SnapshotService.LoadMap", Resources.CORE_SNAPSHOT_LOAD_MAP);

                    List <MethodMapInfo> mapinfo = (List <MethodMapInfo>)SerializeHelper.Deserialize(GetMethodMapFile(sf.MethodMapFile),
                                                                                                     typeof(List <MethodMapInfo>));
                    if (mapinfo != null)
                    {
                        this._Maps.Add(sf.MethodMapFile, mapinfo);
                    }
                }
                return(true);
            }
            catch (Exception error)
            {
                Tracer.Error("SnapshotService.LoadMap", error);
                return(false);
            }
            finally
            {
                Tracer.Verbose("SnapshotService.LoadMap finished", sf.FileName);
            }
        }
        internal bool CalculateXml(SnapshotInfo si, SnapshotEntity sf)
        {
            Tracer.Verbose("SnapshotService.CalculateXml started", sf.FileName);

            try
            {
                //calculate the data : resolve methods name, calculate times, agregate
                Tracer.Info("SnapshotService.CalculateXml", Resources.CORE_SNAPSHOT_CALCULATE);
                sf.CallstackEx = CalculateSnapshot(si.CallStack);

                Tracer.Info("SnapshotService.CalculateXml", Resources.CORE_SNAPSHOT_RESOLVE_MAP);
                ResolveMethodNames(sf);

                return(true);
            }
            catch (Exception error)
            {
                Tracer.Error("SnapshotService.CalculateXml", error);
                return(false);
            }
            finally
            {
                Tracer.Verbose("SnapshotService.CalculateXml finished", sf.FileName);
            }
        }
        internal bool TransformToAgregated(SnapshotEntity sf)
        {
            Tracer.Verbose("SnapshotService.TransformToAgregated started", sf.FileName);

            try
            {
                List <CallStackInfoAgregated> result = new List <CallStackInfoAgregated>();

                foreach (CallStackInfoExtended item in sf.CallstackEx)
                {
                    CallStackInfoAgregated agre = result.Find(p => p.MethodHandle == item.MethodHandle);
                    if (agre != null)
                    {
                        agre.CallCount++;
                        agre.InternalTick += item.InternalTick;
                        agre.AverageTick   = agre.InternalTick / agre.CallCount;
                    }
                    else
                    {
                        CallStackInfoAgregated ex = new CallStackInfoAgregated(item);
                        ex.CallCount    = 1;
                        ex.InternalTick = item.InternalTick;
                        ex.AverageTick  = ex.InternalTick;
                        result.Add(ex);
                    }
                }

                sf.CallstackAg  = result;
                sf.CurrentAgreg = result;

                return(true);
            }
            catch (Exception error)
            {
                Tracer.Error("SnapshotService.TransformToAgregated", error);
                EventDispatcher.Instance.RaiseStatus(Resources.CORE_LOADING_ERROR, StatusEventType.StopProgress);

                return(false);
            }
            finally
            {
                Tracer.Verbose("SnapshotService.TransformToAgregated finished", sf.FileName);
                EventDispatcher.Instance.RaiseStatus(Resources.CORE_SNAPSHOT_LOADED, StatusEventType.StopProgress);
            }
        }
        public bool LoadSnapshot(SnapshotEntity sf)
        {
            if (sf.Loaded)
            {
                Tracer.Verbose("InjectionProfiler.LoadSnapshot allready loaded", sf.FileName);
                return(true);
            }

            EventDispatcher.Instance.RaiseStatus(Resources.CORE_LOADING, StatusEventType.StartProgress);

            try
            {
                if (File.Exists(sf.BinaryFullFileName))
                {
                    //everything is pre-calculated in binary format, just load it
                    LoadBinary(sf);
                }
                else
                {
                    LoadXml(sf);

                    TransformToAgregated(sf);

                    //save as binary format all the agregated data
                    SaveBinary(sf);

                    sf.Loaded = true;
                }
            }
            catch (Exception error)
            {
                Tracer.Error("SnapshotService.LoadSnapshot", error);
                EventDispatcher.Instance.RaiseStatus(Resources.CORE_LOADING_ERROR, StatusEventType.StopProgress);
            }
            finally
            {
                Tracer.Verbose("InjectionProfiler.LoadSnapshot finished", sf.FileName);
                EventDispatcher.Instance.RaiseStatus(Resources.CORE_SNAPSHOT_LOADED, StatusEventType.StopProgress);
            }

            return(sf != null);
        }
        internal bool LoadXml(SnapshotEntity sf)
        {
            Tracer.Verbose("SnapshotService.LoadXml started", sf.FileName);

            try
            {
                SnapshotInfo si = new SnapshotDAC().LoadSnapshot(sf.FullFileName);

                sf.Project       = si.Project;
                sf.Version       = si.Version;
                sf.MethodMapFile = si.Map;

                //the maps for methods name
                if (!LoadMap(sf))
                {
                    return(false);
                }

                //calculate the data : resolve methods name, calculate times, agregate
                if (!CalculateXml(si, sf))
                {
                    return(false);
                }

                sf.Loaded = true;

                return(true);
            }
            catch (Exception error)
            {
                Tracer.Error("SnapshotService.LoadXml", error);
                return(false);
            }
            finally
            {
                Tracer.Verbose("SnapshotService.LoadXml finished", sf.FileName);
            }
        }
 private void LoadBinary(SnapshotEntity sf)
 {
     sf.CallstackAg = new SnapshotDAC().LoadBinarySnapshot(sf.BinaryFullFileName);
 }
 private void SaveBinary(SnapshotEntity sf)
 {
     new SnapshotDAC().SaveBinarySnapshot(sf.BinaryFullFileName, sf.CallstackAg);
 }