summaryrefslogtreecommitdiff
path: root/scripts/profiling/doc_put_memory_usage/get-soledad-and-couch-mem.py
blob: b2b35d30740b30745079ca8ced0ee4270c8d56f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/python


import logging
import argparse
import psutil
import time


def find_procs(procs):
    result = []
    for name, executable in procs:
        found = filter(
            lambda p: executable == p.name,
            psutil.process_iter())
        if len(found) == 1:
            result.append(found[0])
    return result


def log_memory(soledad, bigcouch):
    while True:
        print "%f %f" % \
            (soledad.get_memory_percent(), bigcouch.get_memory_percent())
        time.sleep(1)


if __name__ == '__main__':
    
    # configure logger
    logger = logging.getLogger(__name__)
    LOG_FORMAT = '%(asctime)s %(message)s'
    logging.basicConfig(format=LOG_FORMAT, level=logging.INFO)


    # parse command line
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '-l', dest='logfile',
        help='log output to file')
    args = parser.parse_args()

    log_memory(*find_procs([
        ('Soledad', 'twistd'),
        ('Bigcouch', 'beam.smp')]))