Commit f9245714 authored by inkhey's avatar inkhey

performance timer

parent 6c6915ae
......@@ -13,10 +13,24 @@ import sqlite3
import os
from subprocess import Popen, PIPE
from walkdir import filtered_walk
from timeit import default_timer as timer
# use walkir instead of os.walk to be able
# to select a depth
def calctime(method):
def calctime(*args, **kw):
ts = timer()
result = method(*args, **kw)
te = timer()
print( "\t%r : %2.2f sec" % \
(method.__name__, te-ts))
return result
return calctime
class sqlGit(object):
''' Transform Git data into sqlite database to
......@@ -28,6 +42,7 @@ class sqlGit(object):
''' Initialise sqlite database file'''
self.conn = sqlite3.connect(db)
@calctime
def create_table(self):
''' create SQL tables : author, commits, file, link_author
commit and link commit_file .'''
......@@ -107,6 +122,7 @@ class sqlGit(object):
self.insert_dates()
self.delete_unused_file()
@calctime
def insert_author(self):
''' insert author data into author table'''
......@@ -123,6 +139,7 @@ class sqlGit(object):
values (?,?);''', data)
self.conn.commit()
@calctime
def insert_commit(self):
''' insert commit data into commits table'''
log = Popen(
......@@ -147,6 +164,7 @@ class sqlGit(object):
total_size += os.path.getsize(fp)
return total_size
@calctime
def insert_file(self,depth):
''' insert file data into file table, depth define how precise
file data will be.'''
......@@ -177,6 +195,7 @@ class sqlGit(object):
self.conn.commit()
# LINKS
@calctime
def insert_link_A_C(self):
''' insert link data between author and commit into
link_author_commits table'''
......@@ -194,6 +213,7 @@ class sqlGit(object):
values (?,?,?);''', data)
self.conn.commit()
@calctime
def insert_link_F_C(self):
''' insert link data between file and commit into
link_author_commits table'''
......@@ -214,6 +234,7 @@ class sqlGit(object):
values (?,?,?);''', data)
self.conn.commit()
@calctime
def insert_dates(self):
c = self.conn.cursor()
......@@ -233,6 +254,7 @@ class sqlGit(object):
)
self.conn.commit()
@calctime
def view_3nodestype(self):
'''View with 3 types of nodes : author,commit,file'''
c = self.conn.cursor()
......@@ -297,6 +319,7 @@ class sqlGit(object):
''')
self.conn.commit()
@calctime
def view_2nodestype(self):
'''View with 2 types of nodes : author,file'''
c = self.conn.cursor()
......@@ -348,6 +371,7 @@ class sqlGit(object):
''')
self.conn.commit()
@calctime
def view_files(self):
'''View of relation between files'''
c = self.conn.cursor()
......@@ -390,7 +414,7 @@ class sqlGit(object):
group by f1.file , f2.file;''')
self.conn.commit()
@calctime
def view_authors(self):
'''View of relation between authors'''
c = self.conn.cursor()
......@@ -434,13 +458,16 @@ class sqlGit(object):
;''')
self.conn.commit()
def view_file_commits():
@calctime
def view_file_commits(self):
pass
@calctime
def view_authors_commits():
pass
# CLEAN
@calctime
def delete_unused_file(self):
''' delete unused file (who are not linked to any commit.)'''
......@@ -457,6 +484,7 @@ class sqlGit(object):
'" and dir="' + row[1] + '";')
self.conn.commit()
@calctime
def clean_DB(self):
''' drop alls tables'''
......@@ -467,6 +495,7 @@ class sqlGit(object):
c.execute('DROP TABLE IF EXISTS ' + table + ' ;')
self.conn.commit()
@calctime
def dropView(self):
''' drop current view'''
......@@ -478,13 +507,15 @@ class sqlGit(object):
# autotest
if __name__ == '__main__':
ts = timer()
print("Creating database…")
db = sqlGit('self.db')
db.clean_DB()
db.dropView()
db.create_table()
db.insert_all('../Serpent', 0)
print("inserting data…(this may take a while)")
print("inserting data…")
db.insert_all('.', 0)
print("Creating view…")
db.view_3nodestype()
print("database ready")
db.view_authors()
te = timer()
print("database ready : %2.2f sec" % (te-ts))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment