Commit fdcc133b authored by Konrad Sztyber's avatar Konrad Sztyber Committed by Tomasz Zawadzki
Browse files

scripts/calc-iobuf: add option to output the result in JSON



Users can utilize this option to generate something that can be
directly copy pasted into a config file.  For example:

$ scripts/calc-iobuf.py -m 0xff -c nvmf.conf --format json | jq
{
  "method": "iobuf_set_options",
  "params": {
    "small_bufsize": 8192,
    "large_bufsize": 135168,
    "small_pool_count": 5488,
    "large_pool_count": 3696
  }
}

Signed-off-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/18359

 (master)

(cherry picked from commit fefe14e4)
Change-Id: Id521a42119ece9003e397fce6598e68cb32fc6d7
Signed-off-by: default avatarKrzysztof Karas <krzysztof.karas@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/18404


Reviewed-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
Tested-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
parent 37eb6e33
Loading
Loading
Loading
Loading
+16 −1
Original line number Diff line number Diff line
@@ -162,11 +162,26 @@ def main():
                            'larger values to leave some buffers in the global pool.')
    parser.add_argument('--core-mask', '-m', help='Core mask', type=lambda v: int(v, 0))
    parser.add_argument('--config', '-c', help='Config file', required=True)
    parser.add_argument('--format', '-f', help='Output format (json, text)', default='text')

    args = parser.parse_args()
    if args.format not in ('json', 'text'):
        print(f'{appname}: {args.format}: Invalid format')
        sys.exit(1)
    try:
        with open(args.config, 'r') as f:
            pool = parse_config(json.load(f), args.core_mask)
            config = json.load(f)
        pool = parse_config(config, args.core_mask)
        if args.format == 'json':
            opts = next(Subsystem.get_method(Subsystem.get_subsystem_config(config, 'iobuf'),
                                             'iobuf_set_options'), None)
            if opts is None:
                opts = {'method': 'iobuf_set_options',
                        'params': {'small_bufsize': 8 * 1024, 'large_bufsize': 132 * 1024}}
            opts['params']['small_pool_count'] = pool.small
            opts['params']['large_pool_count'] = pool.large
            print(json.dumps(opts))
        else:
            print('This script will only calculate the minimum values required to populate the '
                  'per-thread caches.\nMost users will usually want to use larger values to leave '
                  'some buffers in the global pool.\n')