Cleaned up matching, and added matching to the backtraces

report.

svn path=/trunk/heap-buddy/; revision=51514
This commit is contained in:
Jon Trowbridge 2005-10-10 14:52:07 +00:00
Родитель d293ab81e0
Коммит f898e037bb
6 изменённых файлов: 46 добавлений и 25 удалений

Просмотреть файл

@ -59,6 +59,25 @@ namespace HeapBuddy {
frames = value;
}
}
public bool MatchesType (string pattern)
{
return Type.Matches (pattern);
}
public bool MatchesMethod (string pattern)
{
int n = Frames.Length;
for (int i = 0; i < n; ++i)
if (Util.ContainsNoCase (frames [i].MethodName, pattern))
return true;
return false;
}
public bool Matches (string pattern)
{
return MatchesType (pattern) || MatchesMethod (pattern);
}
}
}

Просмотреть файл

@ -70,6 +70,7 @@ namespace HeapBuddy {
{
SortOrder order = SortOrder.ByTotalBytes;
int max_rows = 25;
string match_string = null;
bool ellipsize_names = true;
// Hacky free-form arg parser
@ -88,7 +89,10 @@ namespace HeapBuddy {
order = SortOrder.ByAverageAge;
else if (arg == "all")
max_rows = -1;
else if (arg == "full" || arg == "long" || arg == "unellipsized")
else if (arg == "match" || arg == "matching" || arg == "like") {
++i;
match_string = args [i];
} else if (arg == "full" || arg == "long" || arg == "unellipsized")
ellipsize_names = false;
else {
int n = -1;
@ -122,6 +126,8 @@ namespace HeapBuddy {
table.SetStringify (4, "0.0");
foreach (Backtrace bt in reader.Backtraces) {
if (match_string != null && ! bt.Matches (match_string))
continue;
table.AddRow (bt,
bt.LastObjectStats.AllocatedCount,
bt.LastObjectStats.AllocatedTotalBytes,

Просмотреть файл

@ -1093,33 +1093,10 @@ namespace HeapBuddy {
get { return backtraces; }
}
///////////////////////////////////////////////////////////////////
public Type [] Types {
get { return types; }
}
public ArrayList GetTypesMatching (Regex regex)
{
if (regex == null)
return new ArrayList (types);
ArrayList matches;
matches = new ArrayList ();
for (int i = 0; i < types.Length; ++i)
if (regex.Match (types [i].Name).Success)
matches.Add (types [i]);
return matches;
}
public ArrayList GetTypesMatching (string regex)
{
if (regex == null)
return new ArrayList (types);
return GetTypesMatching (new Regex (regex));
}
///////////////////////////////////////////////////////////////////
private void GetMethod (uint code, out string name, out string args)

Просмотреть файл

@ -39,6 +39,11 @@ namespace HeapBuddy {
// Total allocation stats for this type as of the
// last generation in which there were live objects.
public ObjectStats LastObjectStats;
public bool Matches (string pattern)
{
return Util.ContainsNoCase (Name, pattern);
}
}
}

Просмотреть файл

@ -99,7 +99,9 @@ namespace HeapBuddy {
table.SetStringify (3, "0.0");
table.SetStringify (4, "0.0");
foreach (Type type in reader.GetTypesMatching (match_string)) {
foreach (Type type in reader.Types) {
if (match_string != null && ! type.Matches (match_string))
continue;
table.AddRow (type.Name,
type.LastObjectStats.AllocatedCount,
type.LastObjectStats.AllocatedTotalBytes,

Просмотреть файл

@ -32,6 +32,16 @@ namespace HeapBuddy {
return base_time.AddSeconds (time_t);
}
/////////////////////////////////////////////////////////////////////////////////////
static public bool ContainsNoCase (string haystack, string needle)
{
// FIXME: This could be much more efficient
return haystack.ToLower ().IndexOf (needle.ToLower ()) >= 0;
}
/////////////////////////////////////////////////////////////////////////////////////
static public string Ellipsize (int max_length, string str)
{
if (str.Length < max_length || max_length < 0)
@ -45,6 +55,8 @@ namespace HeapBuddy {
return Ellipsize (40, (string) str);
}
/////////////////////////////////////////////////////////////////////////////////////
static public string PrettySize (uint num_bytes)
{
if (num_bytes < 1024)