Esempio n. 1
0
        void PrintRoots(ObjectMapReader omap, int type, int maxlevels)
        {
            List <int> path = new List <int> ();
            Dictionary <int, List <int> > roots   = new Dictionary <int, List <int> > ();
            Dictionary <int, int>         visited = new Dictionary <int, int> ();

            foreach (int obj in omap.GetObjectsByType(type))
            {
                FindRoot(omap, visited, path, roots, obj);
                visited.Clear();
            }

            foreach (List <int> ep in roots.Values)
            {
                for (int n = 0; n < ep.Count && n < maxlevels; n++)
                {
                    int ob = ep [n];
                    Console.WriteLine(n + ". " + omap.GetObjectTypeName(ob));
                }
                if (maxlevels < ep.Count)
                {
                    Console.WriteLine("...");
                }
                Console.WriteLine();
                Console.WriteLine("-");
                Console.WriteLine();
            }
        }
Esempio n. 2
0
		public ReferenceNode (ObjectMapReader map, int type, bool inverse)
		{
			this.map = map;
			this.type = type;
			TypeName = map.GetTypeName (type);
			this.inverse = inverse;
		}
Esempio n. 3
0
        public void AddFile(string fileName)
        {
            ObjectMapReader map = new ObjectMapReader(fileName);

            foreach (HeapSnapshot s in map.HeapShots)
            {
                AddSnapshot(s);
            }
        }
Esempio n. 4
0
    void OpenFile(string file)
    {
        statusBarFileName.Text = file;
        mapReader = new ObjectMapReader(file);
        mapReader.HeapSnapshotAdded += delegate(object o, HeapShotEventArgs args) {
            Application.Invoke(delegate {
                viewer.AddSnapshot(args.HeapSnapshot);
            });
        };
        viewer.Sensitive = true;

        Reload(true);
    }
Esempio n. 5
0
 void ResetFile()
 {
     if (mapReader != null)
     {
         mapReader.Dispose();
         mapReader = null;
     }
     if (outfile != null)
     {
         try {
             System.IO.File.Delete(outfile);
         } catch {}
         outfile = null;
     }
     viewer.Clear();
     viewer.Sensitive = false;
 }
Esempio n. 6
0
        void FindRoot(ObjectMapReader omap, Dictionary <int, int> visited, List <int> path, Dictionary <int, List <int> > roots, int obj)
        {
            if (visited.ContainsKey(obj))
            {
                return;
            }
            visited [obj] = obj;
            path.Add(obj);

            bool hasrefs = false;

            foreach (int oref in omap.GetReferencers(obj))
            {
                hasrefs = true;
                FindRoot(omap, visited, path, roots, oref);
            }

            if (!hasrefs)
            {
                // A root
                List <int> ep = roots [obj];
                if (ep == null)
                {
                    roots [obj] = new List <int> (path);
                }
                else
                {
                    if (ep.Count > path.Count)
                    {
                        roots [obj] = new List <int> (path);
                    }
                }
                Console.WriteLine("found root" + roots.Count + " " + path.Count + " " + omap.GetObjectTypeName(obj));
                foreach (int o in path)
                {
                    Console.Write(omap.GetObjectTypeName(o) + " / ");
                }
                Console.WriteLine();
            }
            path.RemoveAt(path.Count - 1);
        }
Esempio n. 7
0
		TreeIter InternalFillType (ObjectMapReader file, int type)
		{
			ReferenceNode node = file.GetReferenceTree (type, checkInverse.Active);
			return AddNode (TreeIter.Zero, node);
		}
Esempio n. 8
0
		public void FillType (ObjectMapReader file, string typeName)
		{
			this.typeName = typeName;
			this.file = file;
			store.Clear ();
			boxFilter.Visible = false;
			treeview.Columns [TreeColRefs].Visible = InverseReferences;
			treeview.Columns [TreeColRefs+1].Visible = InverseReferences;
			treeview.Columns [TreeColRefs+2].Visible = InverseReferences;
			TreeIter iter = InternalFillType (file, file.GetTypeFromName (typeName));
			treeview.ExpandRow (store.GetPath (iter), false);
		}
Esempio n. 9
0
		public void FillAllTypes (ObjectMapReader file)
		{
			this.file = file;
			this.typeName = null;
			boxFilter.Visible = true;
			treeview.Columns [TreeColRefs].Visible = InverseReferences;
			treeview.Columns [TreeColRefs+1].Visible = InverseReferences;
			treeview.Columns [TreeColRefs+2].Visible = InverseReferences;
			
			if (loading) {
				// If the tree is already being loaded, notify that loading
				// has to start again, since the file has changed.
				reloadRequested = true;
				return;
			}

			loading = true;
			store.Clear ();
			int n=0;
			foreach (int t in file.GetTypes ()) {
				if (++n == 20) {
					if (ProgressEvent != null) {
						ProgressEvent (n, file.GetTypeCount (), null);
					}
					while (Gtk.Application.EventsPending ())
						Gtk.Application.RunIteration ();
					if (reloadRequested) {
						loading = false;
						reloadRequested = false;
						FillAllTypes (this.file);
						return;
					}
					n = 0;
				}
				if (file.GetObjectCountForType (t) > 0)
					InternalFillType (file, t);
			}
			loading = false;
		}
Esempio n. 10
0
        public void Run(string [] args)
        {
            // Parameters are: [-s map-file-to-compare] [-i] [-r] object map file, type to check, tree deepness

            int    maxlevels = 5;
            string type      = null;
            bool   inverse   = false;
            bool   roots     = false;

            if (args.Length == 0)
            {
                Console.Error.WriteLine("Usage is: heap-shot MAP_FILE [-s map-file-to-compare] -i -r [Type [MaxLevels]].");
                Console.Error.WriteLine("    -s MAP_FILE    The source map file to compare against");
                Console.Error.WriteLine("    -i             Invert references");
                Console.Error.WriteLine("    -r             Print roots");

                return;
            }

            ObjectMapReader omap = new ObjectMapReader(args [0]);

            int p = 1;

            while (p < args.Length)
            {
                if (args[p].Length > 0 && args[p][0] == '-')
                {
                    switch (args [p])
                    {
                    case "-s":
                        p++;
                        if (p >= args.Length)
                        {
                            Console.WriteLine("Map file name missing.");
                            return;
                        }
                        ObjectMapReader oldmap = new ObjectMapReader(args[p]);
                        omap.RemoveData(oldmap);
                        break;

                    case "-i":
                        inverse = true;
                        break;

                    case "-r":
                        roots = true;
                        break;
                    }
                    p++;
                }
                else
                {
                    break;
                }
            }

            if (p < args.Length)
            {
                type = args [p];
            }

            p++;
            if (p < args.Length)
            {
                maxlevels = int.Parse(args [p]);
            }

            if (type != null)
            {
                int ntype = omap.GetTypeFromName(type);
                if (ntype == -1)
                {
                    Console.WriteLine("Type not found: " + type);
                    return;
                }
                if (roots)
                {
                    PrintRoots(omap, ntype, maxlevels);
                }
                else
                {
                    // Show the tree for a type
                    ReferenceNode nod = new ReferenceNode(omap, ntype, inverse);
                    foreach (int obj in omap.GetObjectsByType(ntype))
                    {
                        nod.AddReference(obj, 0);
                    }
                    nod.Print(maxlevels);
                }
            }
            else
            {
                // Show a summary
                long tot = 0;
                foreach (int t in omap.GetTypes())
                {
                    long no = omap.GetObjectCountForType(t);
                    Console.WriteLine("{0} {1} {2}", no, omap.GetObjectSizeForType(t), omap.GetTypeName(t));
                    tot += no;
                }
                Console.WriteLine();
                Console.WriteLine("Total: " + tot);
            }
        }