From a2d9ad75900ce10d4fe6f6a95fcbb7d3eaf40c42 Mon Sep 17 00:00:00 2001 From: Aditya Hase Date: Sat, 3 Nov 2018 20:59:29 +0530 Subject: [PATCH] feat(recorder): Use MariaDB's built in profiler --- frappe/recorder.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/frappe/recorder.py b/frappe/recorder.py index 36a661e33d..094e782ce1 100644 --- a/frappe/recorder.py +++ b/frappe/recorder.py @@ -120,12 +120,19 @@ def recorder(function): # __self__ will refer to frappe.db # Rest is trivial query = function.__self__._cursor._executed + + # Built in profiler is already turned on + # Now fetch the profile data for last query + # This must be done after collecting query from _cursor._executed + profile_result = function("SHOW PROFILE ALL") + data = { "function": function.__name__, "args": args, "kwargs": kwargs, "result": result, "query": query, + "profile_result": profile_result, "stack": stack, "time": { "start": start_time_ms, @@ -140,6 +147,10 @@ def recorder(function): wrapper.calls = list() wrapper.path = frappe.request.path + + # Enable MariaDB's builtin query profiler. + # Profile data can be collected after each query. + function("SET profiling = 1") return wrapper def dumps(stuff):