summaryrefslogtreecommitdiffstats
path: root/jjb/cperf/parse-node-yaml.py
blob: 5a7575540b8428344b87e95118fa1f4b7731a136 (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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
##############################################################################
# Copyright (c) 2018 Tim Rozet (trozet@redhat.com) and others.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################

import argparse
import sys
import yaml


def get_node_data_by_number(node_type, node_number):
    node_idx = 1
    for node_name, node_data in data['servers'].items():
        if node_type == node_data['type']:
            if node_idx == node_number:
                return node_name, node_data
            else:
                node_idx += 1


def get_node_value(node_type, node_number, key):
    node_name, node_data = get_node_data_by_number(node_type, node_number)
    if not key and node_name is not None:
        return node_name
    elif node_data and isinstance(node_data, dict) and key in node_data:
        return node_data[key]


def get_number_of_nodes(node_type):
    nodes = data['servers']
    num_nodes = 0
    for node_name, node_data in nodes.items():
        if node_data['type'] == node_type:
            num_nodes += 1
    return num_nodes


FUNCTION_MAP = {'num_nodes':
                {'func': get_number_of_nodes,
                 'args': ['node_type']},
                'get_value':
                    {'func': get_node_value,
                     'args': ['node_type', 'node_number', 'key']},
                }

if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument('command', choices=FUNCTION_MAP.keys())
    parser.add_argument('-f', '--file',
                        dest='node_file',
                        required=True)
    parser.add_argument('--node-type',
                        default='controller',
                        required=False)
    parser.add_argument('--node-number',
                        default=1,
                        type=int,
                        required=False)
    parser.add_argument('-k', '--key',
                        required=False)
    args = parser.parse_args(sys.argv[1:])
    with open(args.node_file, 'r') as fh:
        data = yaml.safe_load(fh)
    assert 'servers' in data
    func = FUNCTION_MAP[args.command]['func']
    args = [getattr(args, x) for x in FUNCTION_MAP[args.command]['args']]
    print(func(*args))
tmspec.tv_nsec, td->fn, td->hno, td->tag, td->data[0], td->data[1], td->data[2], td->data[3], td->data[4]); return len; } /* end of snic_fmt_trc_data */ /* * snic_get_trc_data : Returns a formatted trace buffer. */ int snic_get_trc_data(char *buf, int buf_sz) { struct snic_trc_data *td = NULL; struct snic_trc *trc = &snic_glob->trc; unsigned long flags; spin_lock_irqsave(&trc->lock, flags); if (trc->rd_idx == trc->wr_idx) { spin_unlock_irqrestore(&trc->lock, flags); return -1; } td = &trc->buf[trc->rd_idx]; if (td->ts == 0) { /* write in progress. */ spin_unlock_irqrestore(&trc->lock, flags); return -1; } trc->rd_idx++; if (trc->rd_idx == trc->max_idx) trc->rd_idx = 0; spin_unlock_irqrestore(&trc->lock, flags); return snic_fmt_trc_data(td, buf, buf_sz); } /* end of snic_get_trc_data */ /* * snic_trc_init() : Configures Trace Functionality for snic. */ int snic_trc_init(void) { struct snic_trc *trc = &snic_glob->trc; void *tbuf = NULL; int tbuf_sz = 0, ret; tbuf_sz = (snic_trace_max_pages * PAGE_SIZE); tbuf = vmalloc(tbuf_sz); if (!tbuf) { SNIC_ERR("Failed to Allocate Trace Buffer Size. %d\n", tbuf_sz); SNIC_ERR("Trace Facility not enabled.\n"); ret = -ENOMEM; return ret; } memset(tbuf, 0, tbuf_sz); trc->buf = (struct snic_trc_data *) tbuf; spin_lock_init(&trc->lock); ret = snic_trc_debugfs_init(); if (ret) { SNIC_ERR("Failed to create Debugfs Files.\n"); goto error; } trc->max_idx = (tbuf_sz / SNIC_TRC_ENTRY_SZ); trc->rd_idx = trc->wr_idx = 0; trc->enable = true; SNIC_INFO("Trace Facility Enabled.\n Trace Buffer SZ %lu Pages.\n", tbuf_sz / PAGE_SIZE); ret = 0; return ret; error: snic_trc_free(); return ret; } /* end of snic_trc_init */ /* * snic_trc_free : Releases the trace buffer and disables the tracing. */ void snic_trc_free(void) { struct snic_trc *trc = &snic_glob->trc; trc->enable = false; snic_trc_debugfs_term(); if (trc->buf) { vfree(trc->buf); trc->buf = NULL; } SNIC_INFO("Trace Facility Disabled.\n"); } /* end of snic_trc_free */