Make analyze_rpc_calls script work with new TypeInfo
Reviewers: mferencevic Reviewed By: mferencevic Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D1750
This commit is contained in:
parent
2453b1582c
commit
d819c7b48c
@ -5,6 +5,7 @@ import dpkt
|
|||||||
import json
|
import json
|
||||||
import operator
|
import operator
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import socket
|
import socket
|
||||||
import subprocess
|
import subprocess
|
||||||
import struct
|
import struct
|
||||||
@ -14,6 +15,14 @@ import tabulate
|
|||||||
SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
|
SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
|
||||||
PROJECT_DIR = os.path.normpath(os.path.join(SCRIPT_DIR, ".."))
|
PROJECT_DIR = os.path.normpath(os.path.join(SCRIPT_DIR, ".."))
|
||||||
|
|
||||||
|
TYPE_INFO_PATTERN = re.compile(r"""
|
||||||
|
const\s+utils::TypeInfo\s+
|
||||||
|
(\S+)\s* # <class-name>::kType
|
||||||
|
{\s*
|
||||||
|
(\S+)ULL\s*,\s* # <id-hex>
|
||||||
|
"(\S+)"\s* # "<class-name>"
|
||||||
|
}
|
||||||
|
""", re.VERBOSE)
|
||||||
|
|
||||||
# helpers
|
# helpers
|
||||||
|
|
||||||
@ -21,40 +30,28 @@ def format_endpoint(addr, port):
|
|||||||
return "{}:{}".format(socket.inet_ntoa(addr), port)
|
return "{}:{}".format(socket.inet_ntoa(addr), port)
|
||||||
|
|
||||||
|
|
||||||
def parse_capnp_header(fname):
|
def parse_source_file(fname):
|
||||||
ret = {}
|
ret = {}
|
||||||
last_struct = ""
|
|
||||||
with open(fname) as f:
|
with open(fname) as f:
|
||||||
for row in f:
|
for match in TYPE_INFO_PATTERN.finditer(f.read()):
|
||||||
row = row.strip()
|
id_hex = int(match.groups()[1], 16)
|
||||||
if row.startswith("struct") and \
|
class_name = match.groups()[2]
|
||||||
not row.startswith("struct _capnpPrivate"):
|
ret[id_hex] = class_name
|
||||||
last_struct = row.split()[1]
|
|
||||||
if row.startswith("CAPNP_DECLARE_STRUCT_HEADER"):
|
|
||||||
bytes_val = bytes.fromhex(row.split("(")[1].split(",")[0])
|
|
||||||
val = struct.unpack(">Q", bytes_val)[0]
|
|
||||||
ret[val] = last_struct
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
# TODO(mferencevic): Update this to parse .cpp files (99% are .lcp.cpp),
|
def parse_all_source_files(dirname):
|
||||||
# containing the following line.
|
|
||||||
#
|
|
||||||
# const utils::TypeInfo <class-name>::kType{<id-hex>, "<class-name>"};
|
|
||||||
#
|
|
||||||
# Note that clang-format may break the line at any of the spaces or after '{'.
|
|
||||||
def parse_all_capnp_headers(dirname):
|
|
||||||
ids = {}
|
ids = {}
|
||||||
ret = subprocess.run(["find", dirname, "-name", "*.capnp.h"],
|
ret = subprocess.run(["find", dirname, "-name", "*.lcp.cpp"],
|
||||||
stdout=subprocess.PIPE)
|
stdout=subprocess.PIPE)
|
||||||
ret.check_returncode()
|
ret.check_returncode()
|
||||||
headers = list(filter(None, ret.stdout.decode("utf-8").split("\n")))
|
headers = list(filter(None, ret.stdout.decode("utf-8").split("\n")))
|
||||||
for header in headers:
|
for header in headers:
|
||||||
ids.update(parse_capnp_header(header))
|
ids.update(parse_source_file(header))
|
||||||
return ids
|
return ids
|
||||||
|
|
||||||
|
|
||||||
MESSAGES = parse_all_capnp_headers(os.path.join(PROJECT_DIR, "src"))
|
MESSAGES = parse_all_source_files(os.path.join(PROJECT_DIR, "src"))
|
||||||
|
|
||||||
|
|
||||||
class Connection:
|
class Connection:
|
||||||
|
Loading…
Reference in New Issue
Block a user