Author: dsnell Date: 2006-07-15 02:06:01 -0400 (Sat, 15 Jul 2006) New Revision: 62634
Added: trunk/heap-buddy/analyzer/Makefile trunk/heap-buddy/analyzer/MemZone.cs trunk/heap-buddy/analyzer/MemlogReport.cs trunk/heap-buddy/analyzer/MethodLog.cs trunk/heap-buddy/analyzer/TypeLog.cs Log: These are for the Memlog Added: trunk/heap-buddy/analyzer/Makefile =================================================================== --- trunk/heap-buddy/analyzer/Makefile 2006-07-15 06:04:13 UTC (rev 62633) +++ trunk/heap-buddy/analyzer/Makefile 2006-07-15 06:06:01 UTC (rev 62634) @@ -0,0 +1,399 @@ +# Makefile.in generated by automake 1.8.5 from Makefile.am. +# analyzer/Makefile. Generated from Makefile.in by configure. + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004 Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + + + +srcdir = . +top_srcdir = .. + +pkgdatadir = $(datadir)/heap-buddy +pkglibdir = $(libdir)/heap-buddy +pkgincludedir = $(includedir)/heap-buddy +top_builddir = .. +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +INSTALL = /usr/bin/install -c +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +host_triplet = i686-pc-linux-gnu +subdir = analyzer +DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/configure.in +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(mkdir_p) +CONFIG_CLEAN_FILES = +am__installdirs = "$(DESTDIR)$(bindir)" +binSCRIPT_INSTALL = $(INSTALL_SCRIPT) +SCRIPTS = $(bin_SCRIPTS) +SOURCES = +DIST_SOURCES = +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = ${SHELL} /shared/prog/SoC/heap-buddy/missing --run aclocal-1.8 +AMDEP_FALSE = # +AMDEP_TRUE = +AMTAR = ${SHELL} /shared/prog/SoC/heap-buddy/missing --run tar +AR = ar +AUTOCONF = ${SHELL} /shared/prog/SoC/heap-buddy/missing --run autoconf +AUTOHEADER = ${SHELL} /shared/prog/SoC/heap-buddy/missing --run autoheader +AUTOMAKE = ${SHELL} /shared/prog/SoC/heap-buddy/missing --run automake-1.8 +AWK = gawk +CC = gcc +CCDEPMODE = depmode=gcc3 +CFLAGS = -g -O2 +CPP = gcc -E +CPPFLAGS = +CXX = g++ +CXXCPP = g++ -E +CXXDEPMODE = depmode=gcc3 +CXXFLAGS = -g -O2 +CYGPATH_W = echo +DEFS = -DPACKAGE_NAME=\"\" -DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\" -DPACKAGE_STRING=\"\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE=\"heap-buddy\" -DVERSION=\"0.2\" -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_DLFCN_H=1 +DEPDIR = .deps +ECHO = echo +ECHO_C = +ECHO_N = -n +ECHO_T = +EGREP = /bin/grep -E +EXEEXT = +F77 = g77 +FFLAGS = -g -O2 +GREP = /bin/grep +INSTALL_DATA = ${INSTALL} -m 644 +INSTALL_PROGRAM = ${INSTALL} +INSTALL_SCRIPT = ${INSTALL} +INSTALL_STRIP_PROGRAM = ${SHELL} $(install_sh) -c -s +LDFLAGS = +LIBOBJS = +LIBS = +LIBTOOL = $(SHELL) $(top_builddir)/libtool +LN_S = ln -s +LTLIBOBJS = +MAKEINFO = ${SHELL} /shared/prog/SoC/heap-buddy/missing --run makeinfo +MCS = /usr/bin/mcs +MONO = /usr/bin/mono +OBJEXT = o +PACKAGE = heap-buddy +PACKAGE_BUGREPORT = +PACKAGE_NAME = +PACKAGE_STRING = +PACKAGE_TARNAME = +PACKAGE_VERSION = +PATH_SEPARATOR = : +PKG_CONFIG = /usr/bin/pkg-config +PROFILER_CFLAGS = -D_REENTRANT -pthread -I/usr/lib/pkgconfig/../../include -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include +PROFILER_LIBS = -Wl,--export-dynamic -pthread -L/usr/lib/pkgconfig/../../lib -lmono -lpthread -lm -lgmodule-2.0 -ldl -lgthread-2.0 -lglib-2.0 +RANLIB = ranlib +SET_MAKE = +SHELL = /bin/sh +STRIP = strip +VERSION = 0.2 +ac_ct_CC = gcc +ac_ct_CXX = g++ +ac_ct_F77 = g77 +am__fastdepCC_FALSE = # +am__fastdepCC_TRUE = +am__fastdepCXX_FALSE = # +am__fastdepCXX_TRUE = +am__include = include +am__leading_dot = . +am__quote = +bindir = ${exec_prefix}/bin +build = i686-pc-linux-gnu +build_alias = +build_cpu = i686 +build_os = linux-gnu +build_vendor = pc +datadir = ${datarootdir} +datarootdir = ${prefix}/share +docdir = ${datarootdir}/doc/${PACKAGE} +dvidir = ${docdir} +exec_prefix = ${prefix} +host = i686-pc-linux-gnu +host_alias = +host_cpu = i686 +host_os = linux-gnu +host_vendor = pc +htmldir = ${docdir} +includedir = ${prefix}/include +infodir = ${datarootdir}/info +install_sh = /shared/prog/SoC/heap-buddy/install-sh +libdir = ${exec_prefix}/lib +libexecdir = ${exec_prefix}/libexec +localedir = ${datarootdir}/locale +localstatedir = ${prefix}/var +mandir = ${datarootdir}/man +mkdir_p = mkdir -p -- . +oldincludedir = /usr/include +pdfdir = ${docdir} +prefix = /usr/local +program_transform_name = s,x,x, +psdir = ${docdir} +sbindir = ${exec_prefix}/sbin +sharedstatedir = ${prefix}/com +sysconfdir = ${prefix}/etc +target_alias = +CSC = mcs -debug +CSFLAGS = -target:exe +TARGET = HeapBuddy.exe +WRAPPER = heap-buddy +REPORT_CSFILES = \ + BacktracesReport.cs \ + HistoryReport.cs \ + MemlogReport.cs \ + SummaryReport.cs \ + TypesReport.cs + +CSFILES = \ + HeapBuddy.cs \ + Util.cs \ + Table.cs \ + ObjectStats.cs \ + Type.cs \ + Frame.cs \ + Backtrace.cs \ + Gc.cs \ + Resize.cs \ + OutfileReader.cs \ + Report.cs \ + TypeLog.cs \ + MethodLog.cs \ + MemZone.cs \ + $(REPORT_CSFILES) + +bin_SCRIPTS = \ + $(WRAPPER) + +SRCDIR_CSFILES = $(CSFILES:%=$(srcdir)/%) +EXTRA_DIST = \ + $(CSFILES) \ + $(WRAPPER).in + +CLEANFILES = \ + $(TARGET) \ + $(TARGET).mdb \ + $(WRAPPER) + +all: all-am + +.SUFFIXES: +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \ + && exit 0; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu analyzer/Makefile'; \ + cd $(top_srcdir) && \ + $(AUTOMAKE) --gnu analyzer/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +install-binSCRIPTS: $(bin_SCRIPTS) + @$(NORMAL_INSTALL) + test -z "$(bindir)" || $(mkdir_p) "$(DESTDIR)$(bindir)" + @list='$(bin_SCRIPTS)'; for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + if test -f $$d$$p; then \ + f=`echo "$$p" | sed 's|^.*/||;$(transform)'`; \ + echo " $(binSCRIPT_INSTALL) '$$d$$p' '$(DESTDIR)$(bindir)/$$f'"; \ + $(binSCRIPT_INSTALL) "$$d$$p" "$(DESTDIR)$(bindir)/$$f"; \ + else :; fi; \ + done + +uninstall-binSCRIPTS: + @$(NORMAL_UNINSTALL) + @list='$(bin_SCRIPTS)'; for p in $$list; do \ + f=`echo "$$p" | sed 's|^.*/||;$(transform)'`; \ + echo " rm -f '$(DESTDIR)$(bindir)/$$f'"; \ + rm -f "$(DESTDIR)$(bindir)/$$f"; \ + done + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +distclean-libtool: + -rm -f libtool +uninstall-info-am: +tags: TAGS +TAGS: + +ctags: CTAGS +CTAGS: + + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \ + list='$(DISTFILES)'; for file in $$list; do \ + case $$file in \ + $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \ + $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \ + esac; \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test "$$dir" != "$$file" && test "$$dir" != "."; then \ + dir="/$$dir"; \ + $(mkdir_p) "$(distdir)$$dir"; \ + else \ + dir=''; \ + fi; \ + if test -d $$d/$$file; then \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ + fi; \ + cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ + else \ + test -f $(distdir)/$$file \ + || cp -p $$d/$$file $(distdir)/$$file \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(SCRIPTS) +installdirs: + for dir in "$(DESTDIR)$(bindir)"; do \ + test -z "$$dir" || $(mkdir_p) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES) + +distclean-generic: + -rm -f $(CONFIG_CLEAN_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-libtool mostlyclean-am + +distclean: distclean-am + -rm -f Makefile +distclean-am: clean-am distclean-generic distclean-libtool + +dvi: dvi-am + +dvi-am: + +html: html-am + +info: info-am + +info-am: + +install-data-am: install-data-local + +install-exec-am: install-binSCRIPTS + +install-info: install-info-am + +install-man: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-generic mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-binSCRIPTS uninstall-info-am uninstall-local + +.PHONY: all all-am check check-am clean clean-generic clean-libtool \ + distclean distclean-generic distclean-libtool distdir dvi \ + dvi-am html html-am info info-am install install-am \ + install-binSCRIPTS install-data install-data-am \ + install-data-local install-exec install-exec-am install-info \ + install-info-am install-man install-strip installcheck \ + installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-generic \ + mostlyclean-libtool pdf pdf-am ps ps-am uninstall uninstall-am \ + uninstall-binSCRIPTS uninstall-info-am uninstall-local + + +$(TARGET): $(SRCDIR_CSFILES) + $(CSC) -out:$@ $(CSFLAGS) $^ + +$(WRAPPER): $(srcdir)/$(WRAPPER).in + sed -e "s|[EMAIL PROTECTED]@|$(pkglibdir)|g" < $(srcdir)/$(WRAPPER).in > $@ + chmod +x $(WRAPPER) + +all: $(TARGET) $(WRAPPER) + +install-data-local: $(TARGET) + $(mkinstalldirs) $(DESTDIR)$(pkglibdir) + $(INSTALL_DATA) $(TARGET) $(DESTDIR)$(pkglibdir) + +uninstall-local: + cd $(DESTDIR)$(pkglibdir) && rm -f $(TARGET) +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: Added: trunk/heap-buddy/analyzer/MemZone.cs =================================================================== --- trunk/heap-buddy/analyzer/MemZone.cs 2006-07-15 06:04:13 UTC (rev 62633) +++ trunk/heap-buddy/analyzer/MemZone.cs 2006-07-15 06:06:01 UTC (rev 62634) @@ -0,0 +1,90 @@ +using System; +using System.Collections; + +namespace HeapBuddy { + + public class MemZone { + public uint Allocations; + public uint Bytes; + public Hashtable MethodHash; + public ArrayList Methods; + public string Name; + + public MemZone () + { + MethodHash = new Hashtable (); + Methods = new ArrayList (); + Allocations = 0; + Bytes = 0; + } + + public MemZone (string n) + { + MethodHash = new Hashtable (); + Methods = new ArrayList (); + Allocations = 0; + Bytes = 0; + Name = n; + } + + public bool Contains (string n) { + return MethodHash.ContainsKey (n); + } + + /* + * Return null if name not found + * + * Throws ArgumentException if + * MethodHash already contains n + */ + public MemZone this[string n] { + get { + if (n == null || n == "") + throw new ArgumentException (); + + return (MemZone)MethodHash[n]; + } + + set { + if (MethodHash.ContainsKey (n)) + throw new ArgumentException (); + + Methods.Add (value); + MethodHash.Add (n, value); + } + } + + public MemZone this[int n] { + get { + if (n < 0 || n >= Methods.Count) + return null; + + return (MemZone)Methods[n]; + } + } + + public void Sort () { + IComparer ic = new MemZoneComparer (); + + foreach (MemZone mz in Methods) + mz.Sort (); + + Methods.Sort (ic); + } + + } + + public class MemZoneComparer : IComparer { + + int IComparer.Compare (Object x, Object y) { + MemZone a = (MemZone)x; + MemZone b = (MemZone)y; + + if (a.Bytes > b.Bytes) return -1; + else if (a.Bytes < b.Bytes) return 1; + else return 0; + } + + } + +} Added: trunk/heap-buddy/analyzer/MemlogReport.cs =================================================================== --- trunk/heap-buddy/analyzer/MemlogReport.cs 2006-07-15 06:04:13 UTC (rev 62633) +++ trunk/heap-buddy/analyzer/MemlogReport.cs 2006-07-15 06:06:01 UTC (rev 62634) @@ -0,0 +1,376 @@ +// +// MemlogReport.cs +// based on BacktracesReport.cs +// + +// +// BacktracesReport.cs +// +// Copyright (C) 2005 Novell, Inc. +// + +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of version 2 of the GNU General Public +// License as published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +// USA. +// + +using System; +using System.Collections; +using System.IO; +using System.Text; + +namespace HeapBuddy { + + public class MemlogReport : Report { + const string PS1 = ">> "; + public int MaxRows = 10; + + public TypeLog TypeLog; + public MemZone Types; + + public MethodLog MethodLog; + public MemZone Methods; + + public string CurrentPath; + public MemZone CurrentZone; + + enum Operand { + OP_NONE, + OP_LIST + } + + public MemlogReport () : base ("Memlog") { } + + /* + * Set's the path given a path builder string + */ + public void SetPath (string path) { + if (path == "/") { + // Go to the root + CurrentPath = path; + CurrentZone = null; + + return; + + } else if (path[0] == '/') { + // Absolute Path + string [] segments = path.Split ('/'); + + if (segments[1] != "types" && segments[1] != "methods") + throw new ArgumentException (); + + CurrentPath = path; + + } else if (path == "up") { + int index = CurrentPath.LastIndexOf ('/'); + int length = CurrentPath.Length; + + CurrentPath = CurrentPath.Remove (index, length - index); + + } else { + // Relative Path + CurrentPath += "/" + path; + + } + + // Set the leading slash + if (!CurrentPath.StartsWith ("/")) + CurrentPath = "/" + CurrentPath; + + CurrentPath = CurrentPath.Replace ("//", "/"); + + if (CurrentPath.Length > 1 && CurrentPath.EndsWith ("/")) + CurrentPath = CurrentPath.Remove (CurrentPath.Length - 1, 1); + + CurrentZone = GetByPath (CurrentPath); + if (CurrentZone == null) + throw new ArgumentException (); + } + + /* + * Searches the data tree and returns a + * MemZone that meets the path's spec + */ + public MemZone GetByPath (string path) + { + string [] segments = path.Split ('/'); + MemZone mz = null; + + if (path == "/") + return null; + + // This is a relative path, + // so we must set the initial + // MemZone + if (path[0] != '/') { + mz = CurrentZone; + + if (mz == null) + throw new ArgumentException (); + } + + foreach (string s in segments) { + switch (s) { + + case "types": + mz = Types; + break; + + case "methods": + mz = Methods; + break; + + case "": + break; + + default: + mz = mz[s]; + if (mz == null) + throw new ArgumentException (s); + + break; + } + } + + return mz; + } + + public void PrintCallTrace (MemZone mz, string indent) + { + foreach (MemZone z in mz.Methods) { + Console.Write (indent); + Console.WriteLine ("{0} from {1} allocations - {2}", Util.PrettySize (z.Bytes), z.Allocations, z.Name); + + PrintCallTrace (z, indent + " "); + } + } + + /* + * Prints the methods in a given + * MemZone's Methods array + * + * Prints MaxRows rows + */ + public void PrintMethods (MemZone mz) + { + Table table = new Table (); + table.AddHeaders (" # ", "Size", " % ", "Tot %", "Count", "Method"); + int i = 0; + uint bytes = 0; + + if (CurrentPath == "/") { + PrintCategories (); + return; + } + + foreach (MemZone z in mz.Methods) { + if (MaxRows > 0 && i >= MaxRows) + break; + + table.AddRow (i++ + " :", + Util.PrettySize (z.Bytes), + String.Format ("{0:#0.0}", (float)z.Bytes / (float)mz.Bytes * 100), + String.Format (" {0:#0.000} ", (float)z.Bytes / (float)Types.Bytes * 100), + z.Allocations, + z.Name); + + bytes += z.Bytes; + } + + Console.WriteLine (table); + //if (mz.Name != null && mz.Name.IndexOf(':') != -1) + // Console.WriteLine ("\n{0} in Current Item: {1}", Util.PrettySize (mz.Bytes - bytes), mz.Name); + } + + public void ShowPath () { + Console.WriteLine (CurrentPath); + } + + public void PrintHelpInfo () + { + Console.WriteLine ("Memlog commands:"); + Console.WriteLine (" list: list the items in the current path"); + Console.WriteLine (" rows [n]: specify how many rows to print - zero for all"); + Console.WriteLine (" help: show this screen"); + Console.WriteLine (" quit: quit"); + } + + public void PrintCategories () { + Console.WriteLine ("0 : types"); + Console.WriteLine ("1 : methods"); + } + + public void Blert (string s) { + Console.WriteLine (" ~{0}~", s); + } + + public void Init (OutfileReader reader) { + TypeLog = new TypeLog (reader); + MethodLog = new MethodLog (reader); + + Types = TypeLog.Types; + Methods = MethodLog.Methods; + + CurrentPath = "/"; + CurrentZone = null; + + PrintHelpInfo (); + } + + override public void Run (OutfileReader reader, string [] args) + { + string cmd = ""; + string [] cmds; + + Init (reader); + + while (String.Compare (cmd, "quit") != 0 && String.Compare (cmd, "q") != 0) { + Console.Write ("{0}", PS1); + + cmd = Console.ReadLine (); + if (cmd == null) + cmd = "q"; + if (cmd == "") + continue; + + int n = new int (); + + cmds = cmd.Split (null); + Operand op = Operand.OP_NONE; + + int i = 0; + while (i < cmds.Length) { + string arg = cmds [i].ToLower (); + + switch (arg) { + + case "help": + PrintHelpInfo (); + break; + + case "list":case "lsit":case "ls":case "l": + op = Operand.OP_LIST; + + break; + + case "rows":case "rosw":case "rose": + n = -1; + try { + n = Int32.Parse (cmds [i+1]); + } catch { } + + if (n >= 0) { + MaxRows = n; + i++; + } + + break; + + case "/": + SetPath ("/"); + break; + + case "../":case "..":case "up": + try { + SetPath ("up"); + } catch { } + + PrintMethods (CurrentZone); + + break; + + case "path":case "pth": + if (i + 1 >= cmds.Length) + ShowPath (); + else { + try { + SetPath (cmds[++i]); + + PrintMethods (CurrentZone); + } catch (ArgumentException) { + Blert ("Invalid Path"); + } + } + + break; + + default: + + if (i > 0) + break; + + // Check for the user selecting + // a numbered item + + n = -1; + try { + n = Int32.Parse (arg); + } catch { } + + if (n >= 0) { + + if (CurrentPath == "/") { + + if (n == 0) + SetPath ("/types"); + else if (n == 1) + SetPath ("/methods"); + else { + Blert ("Invalid Category"); + return; + } + + } else { + + if (CurrentZone [n] == null) { + Blert ("Invalid Selection"); + break; + } else { + try { + SetPath (CurrentZone [n].Name); + } catch { } + } + } + + } + + PrintMethods (CurrentZone); + + break; + } + + ++i; + } + + switch (op) { + + case Operand.OP_LIST: + string category = ((string [])CurrentPath.Split ('/'))[1]; + + if (category != "types" && category != "methods") + PrintCategories (); + else + try { + PrintMethods (CurrentZone); + } catch { } + + break; + + default: + break; + } + } + } + } +} Added: trunk/heap-buddy/analyzer/MethodLog.cs =================================================================== --- trunk/heap-buddy/analyzer/MethodLog.cs 2006-07-15 06:04:13 UTC (rev 62633) +++ trunk/heap-buddy/analyzer/MethodLog.cs 2006-07-15 06:06:01 UTC (rev 62634) @@ -0,0 +1,98 @@ +using System; + +namespace HeapBuddy { + + public class MethodLog { + + public MemZone Methods; + public ulong TotalBytes = 0; + public uint Count = 0; + + public MethodLog (OutfileReader reader) { + Methods = new MemZone (); + MemZone zone; + + // Build the data + foreach (Backtrace bt in reader.Backtraces) { + if (bt.Frames.Length <= 0) + continue; + + Frame [] frames = (Frame [])bt.Frames.Clone (); + Array.Reverse (frames); + string name = frames[0].MethodName; + + if (Methods.Contains (name)) { + zone = Methods[name]; + } else { + zone = Methods[name] = new MemZone (name); + } + + AddBacktrace (bt, zone); + + TotalBytes += zone.Bytes; + Count++; + } + + // Sort the data + Methods.Sort (); + } + + public void AddBacktrace (Backtrace bt, MemZone mz) + { + // Make sure the calls are in the data structures + MergeBacktrace (bt, mz); + + // Add the new values to the calls + UpdateBacktrace (bt, mz); + } + + /* + * Make sure that all the methods in the + * call trace exist + */ + public void MergeBacktrace (Backtrace bt, MemZone mz) + { + MemZone Children = mz; + + Frame [] frames = (Frame [])bt.Frames.Clone (); + Array.Reverse (frames); + + foreach (Frame f in frames) { +// if (f.MethodName.StartsWith ("(wrapper")) +// continue; + + if (!Children.Contains (f.MethodName)) + Children[f.MethodName] = new MemZone (f.MethodName); + + Children = Children[f.MethodName]; + } + } + + /* + * Add in the number of allocations and the number + * of bytes in each method of this calltrace in the + * backtrace data structure. + * + * Errrr... something like that + */ + public void UpdateBacktrace (Backtrace bt, MemZone mz) + { + MemZone Children = mz; + + Frame [] frames = (Frame [])bt.Frames.Clone (); + Array.Reverse (frames); + + foreach (Frame f in frames) { + if (f.MethodName.IndexOf ("Main") != -1) + +// if (f.MethodName.StartsWith ("(wrapper")) +// continue; + + Children[f.MethodName].Allocations++; + Children.Bytes += bt.LastObjectStats.AllocatedTotalBytes; + + Children = Children[f.MethodName]; + } + } + } +} Added: trunk/heap-buddy/analyzer/TypeLog.cs =================================================================== --- trunk/heap-buddy/analyzer/TypeLog.cs 2006-07-15 06:04:13 UTC (rev 62633) +++ trunk/heap-buddy/analyzer/TypeLog.cs 2006-07-15 06:06:01 UTC (rev 62634) @@ -0,0 +1,87 @@ +namespace HeapBuddy { + + public class TypeLog { + + public MemZone Types; + public ulong TotalBytes = 0; + public uint Count = 0; + + public TypeLog (OutfileReader reader) { + Types = new MemZone (); + MemZone zone; + + // Build the data + foreach (Backtrace bt in reader.Backtraces) { + if (Types.Contains (bt.Type.Name)) { + zone = Types[bt.Type.Name]; + } else { + zone = Types[bt.Type.Name] = new MemZone (bt.Type.Name); + } + + AddBacktrace (bt, zone); + + TotalBytes += zone.Bytes; + Count++; + } + + // Sort the data + Types.Sort (); + } + + public void AddBacktrace (Backtrace bt, MemZone mz) + { + // Make sure the calls are in the data structures + MergeBacktrace (bt, mz); + + // Add the new values to the calls + UpdateBacktrace (bt, mz); + } + + /* + * Make sure that all the methods in the + * call trace exist + */ + public void MergeBacktrace (Backtrace bt, MemZone mz) + { + MemZone Callers = mz; + + foreach (Frame f in bt.Frames) { +// if (f.MethodName.StartsWith ("(wrapper")) +// continue; + + if (!Callers.Contains (f.MethodName)) + Callers[f.MethodName] = new MemZone (f.MethodName); + + Callers = Callers[f.MethodName]; + } + } + + /* + * Add in the number of allocations and the number + * of bytes in each method of this calltrace in the + * backtrace data structure. + * + * Errrr... something like that + */ + public void UpdateBacktrace (Backtrace bt, MemZone mz) + { + MemZone Callers = mz; + + mz.Allocations += bt.LastObjectStats.AllocatedCount; + mz.Bytes += bt.LastObjectStats.AllocatedTotalBytes; + + Types.Allocations += bt.LastObjectStats.AllocatedCount; + Types.Bytes += bt.LastObjectStats.AllocatedTotalBytes; + + foreach (Frame f in bt.Frames) { +// if (f.MethodName.StartsWith ("(wrapper")) +// continue; + + Callers[f.MethodName].Allocations += bt.LastObjectStats.AllocatedCount; + Callers[f.MethodName].Bytes += bt.LastObjectStats.AllocatedTotalBytes; + + Callers = Callers[f.MethodName]; + } + } + } +} _______________________________________________ Mono-patches maillist - Mono-patches@lists.ximian.com http://lists.ximian.com/mailman/listinfo/mono-patches