File indexing completed on 2024-05-05 05:45:27
0001 # 0002 # Copyright 2014-2017 by Aleix Pol Gonzalez <aleixpol@blue-systems.com> 0003 # 0004 # This program is free software; you can redistribute it and/or modify 0005 # it under the terms of the GNU Library General Public License as 0006 # published by the Free Software Foundation; either version 2, or 0007 # (at your option) any later version. 0008 # 0009 # This program is distributed in the hope that it will be useful, 0010 # but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0012 # GNU General Public License for more details 0013 # 0014 # You should have received a copy of the GNU Library General Public 0015 # License along with this program; if not, write to the 0016 # Free Software Foundation, Inc., 0017 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 0018 0019 import argparse 0020 import json 0021 import random, string 0022 import sys 0023 0024 header="""<html> 0025 <head> 0026 <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> 0027 <script type="text/javascript"> 0028 google.charts.load('current', {'packages':['timeline']}); 0029 google.charts.setOnLoadCallback(drawChart); 0030 function drawChart() { 0031 var container = document.getElementById('timeline'); 0032 var chart = new google.visualization.Timeline(container); 0033 var dataTable = new google.visualization.DataTable(); 0034 dataTable.addColumn({ type: 'string', id: 'Object-Property' }); 0035 dataTable.addColumn({ type: 'string', id: 'Value' }); 0036 dataTable.addColumn({ type: 'number', id: 'Start' }); 0037 dataTable.addColumn({ type: 'number', id: 'End' }); 0038 """ 0039 0040 0041 0042 footer=""" 0043 var options = {} 0044 chart.draw(dataTable, options); 0045 } 0046 0047 </script> 0048 </head> 0049 <body> 0050 <div id="timeline" style="height: 100%; width: 100%"></div> 0051 </body> 0052 </html> 0053 """ 0054 0055 names = set() 0056 def uniqueObjectName(name): 0057 global names 0058 orig = name 0059 while name in names: 0060 name = orig 0061 name += ("-" + ''.join(random.SystemRandom().choice(string.ascii_uppercase + string.digits) for _ in range(5))) 0062 names |= set({name}) 0063 return name 0064 0065 if __name__ == '__main__': 0066 parser = argparse.ArgumentParser() 0067 parser.add_argument("input", help="input text file. /tmp/debug-$appname-$USER.json") 0068 args = parser.parse_args() 0069 0070 values = [] 0071 with open(args.input) as json_data: 0072 data = json.load(json_data) 0073 0074 endoftimes = 0 0075 for v in data: 0076 endoftimes = max(endoftimes, v['events'][-1]['time']) 0077 0078 for v in data: 0079 name = uniqueObjectName(v['name']) 0080 events = v['events'] 0081 initial = v["initial"] 0082 construction = events[0]['time'] 0083 destruction = events[-1]['time'] if events[-1]['type'] == 'destruction' else endoftimes 0084 lastTime = {} 0085 unchangedProperties = initial.copy() 0086 0087 values.append([name, "lifetime", construction, destruction]) 0088 for e in events: 0089 propName = e['name'] if 'name' in e else None 0090 if not propName: 0091 continue 0092 0093 event = lastTime.get(propName, {'value': str(initial[propName]), 'time': construction}) 0094 0095 values.append([name +"-"+ propName, event["value"], event['time'], e['time']]) 0096 0097 if propName in unchangedProperties: 0098 del unchangedProperties[propName] 0099 lastTime[propName] = e 0100 0101 for (propName, e) in lastTime.items(): 0102 values.append([name +"-"+ propName, e["value"], e['time'], destruction]) 0103 0104 #too boring... 0105 #for (v, i) in unchangedProperties.items(): 0106 #values += (" [\"%s\", new Date(%u), new Date(%u) ],\n" % (name +"-"+ v, construction, destruction)) 0107 0108 0109 values = values[:-2] 0110 print(header) 0111 print(" dataTable.addRows(\n", json.dumps(values, indent=4), " );") 0112 print(footer)