+ vpp.disconnect()
+ raise RuntimeError(
+ f"PAPI command {api_name}({api_args}) error:\n{err!r}"
+ )
+ vpp.disconnect()
+
+ return json.dumps(reply)
+
+
+def process_stats(args):
+ """Process the VPP Stats.
+
+ The reply contains single item covering all paths.
+
+ :param args: Command line arguments passed to VPP PAPI Provider.
+ :type args: ArgumentParser
+ :returns: JSON formatted string.
+ :rtype: str
+ :raises RuntimeError: If PAPI command error occurs.
+ """
+
+ try:
+ stats = VPPStats(args.socket)
+ except Exception as err:
+ raise RuntimeError(f"PAPI init failed:\n{err!r}")
+
+ paths = json.loads(args.data)
+ directory = stats.ls(paths)
+ reply = [stats.dump(directory)]
+
+ try:
+ return json.dumps(reply)
+ except UnicodeDecodeError as err:
+ raise RuntimeError(f"PAPI reply {reply} error:\n{err!r}")
+
+
+def process_stats_request(args):
+ """Process the VPP Stats requests.
+
+ :param args: Command line arguments passed to VPP PAPI Provider.
+ :type args: ArgumentParser
+ :returns: JSON formatted string.
+ :rtype: str
+ :raises RuntimeError: If PAPI command error occurs.
+ """
+
+ try:
+ stats = VPPStats(args.socket)
+ except Exception as err:
+ raise RuntimeError(f"PAPI init failed:\n{err!r}")
+
+ try:
+ json_data = json.loads(args.data)
+ except ValueError as err:
+ raise RuntimeError(f"Input json string is invalid:\n{err!r}")
+
+ papi_fn = getattr(stats, json_data[u"api_name"])
+ reply = papi_fn(**json_data.get(u"api_args", {}))