diff options
Diffstat (limited to 'scripts/profiling/sync')
| l--------- | scripts/profiling/sync/client_side_db.py | 1 | ||||
| -rwxr-xr-x | scripts/profiling/sync/plot.py | 93 | ||||
| -rw-r--r-- | scripts/profiling/sync/profile-sync.py | 62 | ||||
| l--------- | scripts/profiling/sync/util.py | 1 | 
4 files changed, 157 insertions, 0 deletions
| diff --git a/scripts/profiling/sync/client_side_db.py b/scripts/profiling/sync/client_side_db.py new file mode 120000 index 00000000..9e49a7f0 --- /dev/null +++ b/scripts/profiling/sync/client_side_db.py @@ -0,0 +1 @@ +../../db_access/client_side_db.py
\ No newline at end of file diff --git a/scripts/profiling/sync/plot.py b/scripts/profiling/sync/plot.py new file mode 100755 index 00000000..8e3e1c15 --- /dev/null +++ b/scripts/profiling/sync/plot.py @@ -0,0 +1,93 @@ +#!/usr/bin/python + + +import argparse +from matplotlib import pyplot as plt +from movingaverage import movingaverage +from scipy.interpolate import interp1d +from numpy import linspace + + +def smooth(l): +    return movingaverage(l, 3, data_is_list=True, avoid_fp_drift=False) + + +def plot(filename, subtitle=''): + +    # config the plot +    plt.xlabel('time (s)') +    plt.ylabel('usage (%)') +    title = 'soledad sync' +    if subtitle != '': +        title += '- %s' % subtitle +    plt.title(title) + +    x = [] +    ycpu = [] +    ymem = [] +    ypcpu = [] +    ypmem = [] + +    ys = [ +        (ycpu, 'total cpu', 'r'), +        (ymem, 'total mem', 'b'), +        (ypcpu, 'proc cpu', 'm'), +        (ypmem, 'proc mem', 'g'), +    ] + +    # read data from file +    with open(filename, 'r') as f: +        line = f.readline() +        while True: +            line = f.readline() +            if line.startswith('#'): +                continue +            if line == '' or line is None: +                break +            time, cpu, mem, pcpu, pmem = tuple(line.strip().split(' ')) +            x.append(float(time)) +            ycpu.append(float(cpu)) +            ymem.append(float(mem)) +            ypcpu.append(float(pcpu)) +            ypmem.append(float(pmem)) + +    smoothx = [n for n in smooth(x)] +    #xnew = linspace(0.01, 19, 100) + +    for y in ys: +        kwargs = { +            'linewidth': 1.0, +            'linestyle': '-', +        #    'marker': '.', +            'color': y[2], +        } +        #f = interp1d(x, y[0], kind='cubic') +        plt.plot( +            smoothx, +            [n for n in smooth(y[0])], +            #xnew, +            #f(xnew), +            label=y[1], **kwargs) + +    #plt.axes().get_xaxis().set_ticks(x) +    #plt.axes().get_xaxis().set_ticklabels(x) + +    # annotate max and min values +    plt.xlim(0, 20) +    plt.ylim(0, 100) +    plt.grid() +    plt.legend() +    plt.show() + + +if __name__ == '__main__': +    # parse command line +    parser = argparse.ArgumentParser() +    parser.add_argument( +        '-d', dest='datafile', required=False, default='/tmp/profile.log', +        help='the data file to plot') +    parser.add_argument( +        '-s', dest='subtitle', required=False, default='', +        help='a subtitle for the plot') +    args = parser.parse_args() +    plot(args.datafile, args.subtitle) diff --git a/scripts/profiling/sync/profile-sync.py b/scripts/profiling/sync/profile-sync.py new file mode 100644 index 00000000..fdd5b5a6 --- /dev/null +++ b/scripts/profiling/sync/profile-sync.py @@ -0,0 +1,62 @@ +#!/usr/bin/python + + +import argparse +import logging + + +from util import StatsLogger, ValidateUserHandle +from client_side_db import get_soledad_instance +#from plot import plot + + +# create a logger +logger = logging.getLogger(__name__) +LOG_FORMAT = '%(asctime)s %(message)s' +logging.basicConfig(format=LOG_FORMAT, level=logging.INFO) + + +# main program + +if __name__ == '__main__': + +    # parse command line +    parser = argparse.ArgumentParser() +    parser.add_argument( +        'user@provider', action=ValidateUserHandle, help='the user handle') +    parser.add_argument( +        '-b', dest='basedir', required=False, default=None, +        help='soledad base directory') +    parser.add_argument( +        '-p', dest='passphrase', required=False, default=None, +        help='the user passphrase') +    parser.add_argument( +        '-l', dest='logfile', required=False, default='/tmp/profile.log', +        help='the file to which write the log') +    args = parser.parse_args() + +    # get the password +    passphrase = args.passphrase +    if passphrase is None: +        passphrase = getpass.getpass( +            'Password for %s@%s: ' % (args.username, args.provider)) + +    # get the basedir +    basedir = args.basedir +    if basedir is None: +        basedir = tempfile.mkdtemp() +    logger.info('Using %s as base directory.' % basedir) + +    # get the soledad instance +    s = get_soledad_instance( +        args.username, args.provider, passphrase, basedir) +    for i in xrange(10): +        s.create_doc({}) + +    sl = StatsLogger( +        "soledad-sync", args.logfile, procs=["python"], interval=0.001) +    sl.start() +    s.sync() +    sl.stop() + +    #plot(args.logfile) diff --git a/scripts/profiling/sync/util.py b/scripts/profiling/sync/util.py new file mode 120000 index 00000000..7f16d684 --- /dev/null +++ b/scripts/profiling/sync/util.py @@ -0,0 +1 @@ +../util.py
\ No newline at end of file | 
