Skip to content

Commit

Permalink
DB: added the same format for stacktraces as for settings, PHP: modif…
Browse files Browse the repository at this point in the history
…ied the pages to work with the new stacktrace format
  • Loading branch information
Zydox authored and Zydox committed May 30, 2010
1 parent 459b2a7 commit 8c4338b
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 39 deletions.
97 changes: 78 additions & 19 deletions backend.py
Expand Up @@ -36,7 +36,7 @@ class Crash(Base):
contains_demo = Column( Boolean, default=False )

# settings = relation( 'Settings', order_by='Settings.setting.desc' )
stacktrace = relation( 'Stacktrace', order_by='Stacktrace.frame' )
# stacktrace = relation( 'Stacktrace', order_by='Stacktrace.frame' )

def __init__(self):
self.date = datetime.datetime.now()
Expand Down Expand Up @@ -70,16 +70,21 @@ class SettingsData(Base):

class Stacktrace(Base):
__tablename__ = 'stacktrace'
id = Column( Integer, ForeignKey( Crash.id ), primary_key=True )
stacktrace_id = Column( Integer, primary_key=True )
frame = Column( Integer )
reportid = Column( Integer, ForeignKey( Crash.id ), primary_key=True )
orderid = Column( Integer, primary_key=True )
stacktraceid = Column( Integer )
type = Column( String(10))
line = Column( Integer )
raw = Column( String(255) )


class StacktraceData(Base):
__tablename__ = 'stacktracedata'
id = Column( Integer, primary_key=True )
file = Column( String(128) )
functionname = Column( String(128) )
functionat = Column( String(16) )
functionaddress = Column( String(16) )
address = Column( String(10) )
raw = Column( String(255) )


class DbConfig(Base):
Expand Down Expand Up @@ -128,7 +133,8 @@ def __init__(self,alchemy_uri,verbose=False):
self.UpdateDBScheme( oldrev, current_db_rev )
self.SetDBRevision( current_db_rev )
self.getSettingIDCache = {}

self.getStacktraceIDCache = {}


def UpdateDBScheme( self, oldrev, current_db_rev ):
pass
Expand Down Expand Up @@ -261,7 +267,7 @@ def parseZipMembers(self, fn, data, date_time = '' ):
elif (is_stacktrace and re.search ('^\[[ 0-9]*\] \([0-9]*\) ', line)):
stacktrace_id = stacktrace_id + 1
stacktrace_key = int (self.parseInfologSub ('^\[[ 0-9]*\]', line, 0)[1:-1])
temp = {}
temp = {'function':None, 'functionat':None}
value = self.parseInfologSub ('^\[[ 0-9]*\] ', line)
value = value.split (' ')
temp['line'] = value[0][1:-1]
Expand All @@ -275,19 +281,42 @@ def parseZipMembers(self, fn, data, date_time = '' ):
temp['file'] = temp['file'][max (temp['file'].rfind ('\\'), temp['file'].rfind ('/')) + 1:]

stacktrace = Stacktrace()
stacktrace.id = crash.id
stacktrace.stacktrace_id = stacktrace_id
stacktrace.frame = stacktrace_key
stacktrace.reportid = crash.id
stacktrace.orderid = stacktrace_id
stacktrace.stacktraceid = self.getStacktraceID (session, temp['file'], temp['address'], temp['function'], temp['functionat'])
stacktrace.type = stacktrace_type
stacktrace.raw = self.dbEncode (line)
stacktrace.line = int (temp['line'])
stacktrace.file = temp['file']
if (temp.has_key ('function')):
stacktrace.functionname = temp['function']
if (temp.has_key ('functionat')):
stacktrace.functionat = temp['functionat']
stacktrace.address = temp['address']
stacktrace.raw = line
stacktracelist.append ( stacktrace )

# stacktrace_id = stacktrace_id + 1
# stacktrace_key = int (self.parseInfologSub ('^\[[ 0-9]*\]', line, 0)[1:-1])
# temp = {}
# value = self.parseInfologSub ('^\[[ 0-9]*\] ', line)
# value = value.split (' ')
# temp['line'] = value[0][1:-1]
# temp['address'] = value[len (value) - 1][1:-1]
# if (value[len (value) - 2][-1] == ')'):
# temp['file'] = value[len (value) - 2][:value[len (value) - 2].rfind ('(')]
# temp['function'] = value[len (value) - 2][value[len (value) - 2].rfind ('(') + 1:value[len (value) - 2].rfind ('+')]
# temp['functionat'] = value[len (value) - 2][value[len (value) - 2].rfind ('+') + 1:-1]
# else:
# temp['file'] = value[len (value) - 2]
# temp['file'] = temp['file'][max (temp['file'].rfind ('\\'), temp['file'].rfind ('/')) + 1:]
#
# stacktrace = Stacktrace()
# stacktrace.id = crash.id
# stacktrace.stacktrace_id = stacktrace_id
# stacktrace.frame = stacktrace_key
# stacktrace.type = stacktrace_type
# stacktrace.raw = self.dbEncode (line)
# stacktrace.line = int (temp['line'])
# stacktrace.file = temp['file']
# if (temp.has_key ('function')):
# stacktrace.functionname = temp['function']
# if (temp.has_key ('functionat')):
# stacktrace.functionat = temp['functionat']
# stacktrace.address = temp['address']

if (al_available_devices):
crash.al_available_devices = self.dbEncode ("\n".join (al_available_devices))
Expand Down Expand Up @@ -358,4 +387,34 @@ def getSettingID (self, session, setting, value):
settingsdata.value = value
session.add( settingsdata )
session.commit()
return (settingsdata.id)
return (settingsdata.id)


def getStacktraceID (self, session, file, address, functionname, functionaddress):
if self.getStacktraceIDCache.has_key (file):
if self.getStacktraceIDCache[file].has_key (address):
if self.getStacktraceIDCache[file][address].has_key (functionname):
if self.getStacktraceIDCache[file][address][functionname].has_key (functionaddress):
return (self.getStacktraceIDCache[file][address][functionname][functionaddress])


id = session.query( StacktraceData.id ).filter( StacktraceData.file == file ).filter( StacktraceData.address == address ).filter ( StacktraceData.functionname == functionname ).filter ( StacktraceData.functionaddress == functionaddress ).first()
try:
if session.query( StacktraceData.id ).filter( and_ (StacktraceData.file == file, StacktraceData.address == address, StacktraceData.functionname == functionname, StacktraceData.functionaddress == functionaddress ) ).one():
if not self.getStacktraceIDCache.has_key (file):
self.getStacktraceIDCache[file] = {}
if not self.getStacktraceIDCache[file].has_key (address):
self.getStacktraceIDCache[file][address] = {}
if not self.getStacktraceIDCache[file][address].has_key (functionname):
self.getStacktraceIDCache[file][address][functionname] = {}
self.getStacktraceIDCache[file][address][functionname][functionaddress] = id.id
return (id.id)
except:
stacktracedata = StacktraceData()
stacktracedata.file = file
stacktracedata.address = address
stacktracedata.functionname = functionname
stacktracedata.functionaddress = functionaddress
session.add( stacktracedata )
session.commit()
return (stacktracedata.id)
25 changes: 13 additions & 12 deletions php/logical/common.php
Expand Up @@ -37,9 +37,9 @@ function GetSettings ($ID) {


function GetStacktrace ($ID) {
$MySQL_Result = DB_Query ("SELECT * FROM stacktrace WHERE id='" . mysql_escape_string ($ID) . "'");
$MySQL_Result = DB_Query ("SELECT stacktrace.orderid, stacktrace.raw, stacktracedata.* FROM stacktrace LEFT JOIN stacktracedata ON stacktrace.stacktraceid=stacktracedata.id WHERE reportid='" . mysql_escape_string ($ID) . "'");
while ($Data = mysql_fetch_assoc ($MySQL_Result))
$Return[$Data['line']] = $Data;
$Return[$Data['orderid']] = $Data;
return ($Return);
}

Expand All @@ -49,25 +49,26 @@ function GetCrashes () {
$Crashed = join ("", mysql_fetch_assoc ($MySQL_Result));
$MySQL_Result = DB_Query ("SELECT settingsdata.id, settingsdata.setting, settingsdata.value, COUNT(records.id) AS Crashes FROM records LEFT JOIN settings ON records.id=settings.reportid LEFT JOIN settingsdata on settings.settingid=settingsdata.id WHERE crashed='1' GROUP BY settings.settingid");
while ($Data = mysql_fetch_assoc ($MySQL_Result))
$Return['Settings'][$Data['setting']][$Data['value']] = array ("ID" => $Data['id'], "Reports" => $Data['Crashes'], "Percentage" => number_format ($Data['Crashes'] / $Crashed * 100, 1, ".", ""));
ksort ($Return['Settings']);
foreach (array_keys ($Return['Settings']) as $Setting)
ksort ($Return['Settings'][$Setting]);
$Return['Data'][$Data['setting']][$Data['value']] = array ("ID" => $Data['id'], "Reports" => $Data['Crashes'], "Percentage" => number_format ($Data['Crashes'] / $Crashed * 100, 1, ".", ""));
ksort ($Return['Data']);
foreach (array_keys ($Return['Data']) as $Setting)
ksort ($Return['Data'][$Setting]);
return ($Return);
}


function GetCrashes2 () {
$MySQL_Result = DB_Query ("SELECT COUNT(id) FROM records WHERE crashed='1'");
$Crashed = join ("", mysql_fetch_assoc ($MySQL_Result));
$MySQL_Result = DB_Query ("SELECT stacktrace.file, stacktrace.functionname, stacktrace.functionat, stacktrace.address, COUNT(records.id) AS Crashes FROM records LEFT JOIN stacktrace ON records.id=stacktrace.id WHERE crashed='1' GROUP BY stacktrace.file, stacktrace.functionname, stacktrace.functionat, stacktrace.address");
$MySQL_Result = DB_Query ("SELECT stacktracedata.*, COUNT(records.id) AS Crashes FROM records LEFT JOIN stacktrace ON records.id=stacktrace.reportid AND stacktrace.orderid='1' LEFT JOIN stacktracedata ON stacktrace.stacktraceid=stacktracedata.id WHERE crashed='1' GROUP BY stacktrace.stacktraceid");
while ($Data = mysql_fetch_assoc ($MySQL_Result)) {
$Return['Settings'][$Data['file']][$Data['address']]['Reports'] += $Data['Crashes'];
$Return['Settings'][$Data['file']][$Data['address']]['Percentage'] = number_format ($Return['Settings'][$Data['file']][$Data['address']]['Reports'] / $Crashed * 100, 1, ".", "");
$Return['Data'][$Data['file']][$Data['address']]['Reports'] += $Data['Crashes'];
$Return['Data'][$Data['file']][$Data['address']]['Percentage'] = number_format ($Return['Settings'][$Data['file']][$Data['address']]['Reports'] / $Crashed * 100, 1, ".", "");
$Return['Data'][$Data['file']][$Data['address']]['ID'] = $Data['id'];
}
ksort ($Return['Settings']);
foreach (array_keys ($Return['Settings']) as $Setting)
ksort ($Return['Settings'][$Setting]);
ksort ($Return['Data']);
foreach (array_keys ($Return['Data']) as $Setting)
ksort ($Return['Data'][$Setting]);
return ($Return);
}

Expand Down
15 changes: 8 additions & 7 deletions php/pages/Crashes.php
@@ -1,5 +1,6 @@
<?
$Data = ($Post['Version'] == 1 ? GetCrashes2 () : GetCrashes ());
$FilterType = ($Post['Version'] == 1 ? "stacktraceid" : "settingid");
echo "<!---";
//print_r ($Data);
echo "--->";
Expand All @@ -10,23 +11,23 @@
<TR><TH CLASS="Sub">Setting</TH><TH CLASS="Sub">Value</TH><TH CLASS="Sub">Crash reports</TH><TH CLASS="Sub">Percentage</TH></TR>
<?
$iSettings = -1;
foreach (array_keys ($Data['Settings']) as $Setting) {
foreach (array_keys ($Data['Data']) as $Setting) {
++$iSettings;
$iSettings2 = -1;
foreach (array_keys ($Data['Settings'][$Setting]) as $Value) {
foreach (array_keys ($Data['Data'][$Setting]) as $Value) {
++$iSettings2;
?>
<TR>
<? if (++$i[$Setting] == 1) {
unset ($SettingIDs);
foreach ($Data['Settings'][$Setting] as $ValueData)
foreach ($Data['Data'][$Setting] as $ValueData)
$SettingIDs[$ValueData['ID']] = $ValueData['ID'];
?>
<TD CLASS="LineM<? echo ($iSettings % 2); ?>" ROWSPAN="<? echo count ($Data['Settings'][$Setting]); ?>"><A HREF="?List&Filter[]=crashed@1&Filter[]=settingid@<? echo join ("&Filter[]=settingid@", $SettingIDs); ?>"><? echo $Setting; ?></A></TD>
<TD CLASS="LineM<? echo ($iSettings % 2); ?>" ROWSPAN="<? echo count ($Data['Data'][$Setting]); ?>"><A HREF="?List&Filter[]=crashed@1&Filter[]=<? echo $FilterType; ?>@<? echo join ("&Filter[]=" . $FilterType . "@", $SettingIDs); ?>"><? echo $Setting; ?></A></TD>
<? } ?>
<TD CLASS="LineM<? echo ($iSettings % 2); ?>S<? echo ($iSettings2 % 2); ?>"><A HREF="?List&Filter[]=crashed@1&Filter[]=settingid@<? echo $Data['Settings'][$Setting][$Value]['ID']; ?>"><? echo $Value; ?></A></TD>
<TD CLASS="LineM<? echo ($iSettings % 2); ?>S<? echo ($iSettings2 % 2); ?>"><? echo $Data['Settings'][$Setting][$Value]['Reports']; ?></TD>
<TD CLASS="LineM<? echo ($iSettings % 2); ?>S<? echo ($iSettings2 % 2); ?>"><? echo $Data['Settings'][$Setting][$Value]['Percentage']; ?>%</TD>
<TD CLASS="LineM<? echo ($iSettings % 2); ?>S<? echo ($iSettings2 % 2); ?>"><A HREF="?List&Filter[]=crashed@1&Filter[]=<? echo $FilterType; ?>@<? echo $Data['Data'][$Setting][$Value]['ID']; ?>"><? echo $Value; ?></A></TD>
<TD CLASS="LineM<? echo ($iSettings % 2); ?>S<? echo ($iSettings2 % 2); ?>"><? echo $Data['Data'][$Setting][$Value]['Reports']; ?></TD>
<TD CLASS="LineM<? echo ($iSettings % 2); ?>S<? echo ($iSettings2 % 2); ?>"><? echo $Data['Data'][$Setting][$Value]['Percentage']; ?>%</TD>
</TR>
<? }
}
Expand Down
2 changes: 1 addition & 1 deletion php/pages/Details.php
Expand Up @@ -14,7 +14,7 @@
<? foreach ($Stacktrace as $Row) {
?>
<TR>
<TD><? echo $Row['line']; ?></TD>
<TD><? echo $Row['orderid']; ?></TD>
<TD><? echo $Row['file']; ?></TD>
<TD><? echo $Row['functionname']; ?></TD>
<TD><? echo $Row['functionat']; ?></TD>
Expand Down
7 changes: 7 additions & 0 deletions php/pages/List.php
Expand Up @@ -14,6 +14,13 @@
$Join['LEFT JOIN settings ON records.id=settings.reportid'] = "LEFT JOIN settings ON records.id=settings.reportid";
$Where[] = "(" . join (" OR ", $NewWhere) . ")";
}
if (is_array ($Filter['stacktraceid'])) {
unset ($NewWhere);
foreach ($Filter['stacktraceid'] as $ID)
$NewWhere[] = "stacktrace.stacktraceid='" . mysql_escape_string ($ID) . "'";
$Join['LEFT JOIN stacktrace ON records.id=stacktrace.reportid'] = "LEFT JOIN stacktrace ON records.id=stacktrace.reportid";
$Where[] = "(" . join (" OR ", $NewWhere) . ")";
}
if (is_array ($Filter['crashed'])) {
unset ($NewWhere);
$NewWhere[] = "records.crashed='" . mysql_escape_string (key ($Filter['crashed'])) . "'";
Expand Down

0 comments on commit 8c4338b

Please sign in to comment.