Skip to content

Commit

Permalink
Merge pull request #2131 from JulienBalestra/master
Browse files Browse the repository at this point in the history
Pythonic way for samples
  • Loading branch information
michaelcahill committed Aug 20, 2015
2 parents 1792af8 + d832c81 commit cc4ad7f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
2 changes: 1 addition & 1 deletion examples/python/ex_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@
# Iterate through the records
cursor.reset()
for key, value in cursor:
print('Got record: ' + key + ' : ' + value)
print('Got record: %s : %s' % (key, value))

conn.close()
30 changes: 18 additions & 12 deletions examples/python/ex_stat.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,24 @@
import os
from wiredtiger import wiredtiger_open,WIREDTIGER_VERSION_STRING,stat


def main():
# Create a clean test directory for this run of the test program
os.system('rm -rf WT_HOME')
os.makedirs('WT_HOME')
# Connect to the database and open a session
conn = wiredtiger_open('WT_HOME', 'create,statistics=(all)')
session = conn.open_session()

# Create a simple table
session.create('table:access', 'key_format=S,value_format=S')

# Open a cursor and insert a record
cursor = session.open_cursor('table:access', None)

cursor['key'] = 'value'
cursor['key'] = 'value'
cursor.close()

session.checkpoint()
print WIREDTIGER_VERSION_STRING
print_database_stats(session)
Expand All @@ -57,46 +58,51 @@ def main():
print_derived_stats(session)
conn.close()


def print_database_stats(session):
statcursor = session.open_cursor("statistics:")
print_cursor(statcursor)
statcursor.close()


def print_file_stats(session):
fstatcursor = session.open_cursor("statistics:table:access")
print_cursor(fstatcursor)
fstatcursor.close()


def print_overflow_pages(session):
ostatcursor = session.open_cursor("statistics:table:access")
val = ostatcursor[stat.dsrc.btree_overflow]
if val != 0 :
print str(val[0]) + '=' + str(val[1])
if val != 0:
print '%s=%s' % (str(val[0]), str(val[1]))
ostatcursor.close()


def print_derived_stats(session):
dstatcursor = session.open_cursor("statistics:table:access")
ckpt_size = dstatcursor[stat.dsrc.block_checkpoint_size][1]
file_size = dstatcursor[stat.dsrc.block_size][1]
percent = 0
if file_size != 0 :
if file_size != 0:
percent = 100 * ((float(file_size) - float(ckpt_size)) / float(file_size))
print "Table is %" + str(percent) + " fragmented"
print "Table is %%%s fragmented" % str(percent)

app_insert = int(dstatcursor[stat.dsrc.cursor_insert_bytes][1])
app_remove = int(dstatcursor[stat.dsrc.cursor_remove_bytes][1])
app_update = int(dstatcursor[stat.dsrc.cursor_update_bytes][1])
fs_writes = int(dstatcursor[stat.dsrc.cache_bytes_write][1])
fs_writes = int(dstatcursor[stat.dsrc.cache_bytes_write][1])

if(app_insert + app_remove + app_update != 0):
if app_insert + app_remove + app_update != 0:
print "Write amplification is " + '{:.2f}'.format(fs_writes / (app_insert + app_remove + app_update))
dstatcursor.close()


def print_cursor(mycursor):
while mycursor.next() == 0:
val = mycursor.get_value()
if val[1] != '0' :
print str(val[0]) + '=' + str(val[1])
if val[1] != '0':
print '%s=%s' % (str(val[0]), str(val[1]))

if __name__ == "__main__":
main()
Expand Down

0 comments on commit cc4ad7f

Please sign in to comment.