Last active
June 27, 2025 18:22
-
-
Save vshankar/601aa9c579fe4af968c8c18e8f8d9504 to your computer and use it in GitHub Desktop.
MDS op times
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import sys | |
import stat | |
import datetime | |
def parselog(logfile): | |
client_request_map = {} | |
with open(logfile, 'r') as logf: | |
for loge in logf: | |
is_incoming_request = True | |
# try match request start | |
m = re.match(r"(\d+\-\d+-\d+T\d+\:\d+\:\d+\.\d+)\+000.*handle_client_request client_request\(client\.(\d+)\:(\d+) .*", loge) | |
if not m: | |
# try match request reply | |
m = re.match(r"(\d+\-\d+-\d+T\d+\:\d+\:\d+\.\d+)\+000.*reply_client_request .* client_request\(client\.(\d+)\:(\d+) .*", loge) | |
if not m: | |
continue | |
is_incoming_request = False | |
dt = datetime.datetime.strptime(m.group(1), "%Y-%m-%dT%H:%M:%S.%f") | |
dts = dt.timestamp() | |
clientid = int(m.group(2)) | |
reqid = int(m.group(3)) | |
#print(f'{loge}') | |
if is_incoming_request: | |
# first time seen this client | |
if not clientid in client_request_map: | |
client_request_map[clientid] = {} | |
client_request_map[clientid][reqid] = [dts, dts] | |
else: | |
# log does not have request start | |
if not clientid in client_request_map or \ | |
not reqid in client_request_map[clientid]: | |
continue | |
client_request_map[clientid][reqid][1] = dts | |
for clientid,reqmap in client_request_map.items(): | |
sm = sorted(reqmap.items(), key=lambda val: val[1][1] - val[1][0], reverse=True) | |
print(f'client.{clientid}') | |
for e in sm[:5]: | |
print(f' requestid: {e[0]}, took {e[1][1] - e[1][0]}s') | |
if __name__ == '__main__': | |
if len(sys.argv) < 2: | |
print(f'usage: {sys.argv[0]} /path/to/mds/debug.log') | |
sys.exit(-1) | |
parselog(sys.argv[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment