Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query profiler tree page update #260

Merged
merged 2 commits into from
May 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
157 changes: 139 additions & 18 deletions project/ui/qprof-ui.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,25 @@
"cells": [
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"id": "c7fde2aa-9a00-43b2-8e83-dc89087fa142",
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "02d833789e9d402d8b05bfcf10d8c179",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(HTML(value=\"<a href='/lab/' style='text-decoration: none; padding: 8px; background-color: #007b…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import ipywidgets as widgets\n",
"from IPython.display import display, HTML\n",
Expand Down Expand Up @@ -41,7 +56,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"id": "4d76e603-bb3e-4e2f-9664-56b67efd3edd",
"metadata": {},
"outputs": [],
Expand All @@ -57,7 +72,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"id": "0221f436-1e34-405a-b28c-293eac20c369",
"metadata": {
"scrolled": true
Expand All @@ -71,6 +86,7 @@
"from verticapy.performance.vertica import QueryProfilerInterface, QueryProfiler\n",
"logging.info('[Query Profile Tree Page] Successfully Imported Libraries ')\n",
"output_initial = widgets.Output()\n",
"global qprof\n",
"with output_initial:\n",
" %store -r query_val\n",
" %store -r key_val\n",
Expand Down Expand Up @@ -125,12 +141,12 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"id": "b74b0305-6612-4f85-aa18-ff0b36e5cd80",
"metadata": {},
"outputs": [],
"source": [
"button_qprof_save = widgets.Button(description=\"Save Query Plan\")\n",
"button_qprof_save = widgets.Button(description=\"Save Query Plan\", layout=widgets.Layout(width='150px'))\n",
"output_export = widgets.Output()\n",
"\n",
"def click_export_query(_):\n",
Expand All @@ -145,12 +161,24 @@
"\n",
"button_qprof_save.on_click(click_export_query)\n",
"\n",
"qpof_save = widgets.VBox([button_qprof_save, output_export])"
"qpof_save = widgets.VBox([button_qprof_save, output_export])\n",
"\n",
"button_download_report = widgets.Button(description=\"Download Report\", layout=widgets.Layout(width='150px'))\n",
"output_download_report = widgets.Output()\n",
"def click_download_report(_):\n",
" output_download_report.clear_output(wait=True)\n",
" with output_download_report:\n",
" print(\"Downloading report. It may take a while...\")\n",
" print(\"Ready to Download\")\n",
" display(download_report_output)\n",
" display(btn_report)\n",
"\n",
"button_download_report.on_click(click_download_report)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"id": "72beb96c-85b4-4331-8e92-c59be23ae5fb",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -181,7 +209,7 @@
"\n",
"def download_qprof(e=None):\n",
" # Assuming 'qprof.tar' is stored in the file path 'qprof_path'\n",
" qprof_path = 'qprof.tar' # Replace 'qprof.tar' with the actual file path\n",
" qprof_path = 'qprof.tar' \n",
" with open(qprof_path, 'rb') as file:\n",
" qprof_data = file.read()\n",
" trigger_download(qprof_data, 'qprof.tar')\n",
Expand All @@ -191,7 +219,40 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"id": "ad4a224b-157f-4437-a053-45f3145eb584",
"metadata": {},
"outputs": [],
"source": [
"def trigger_download_report(data, filename, file_type='text/html'):\n",
" content_b64 = b64encode(data).decode()\n",
" data_url = f'data:{file_type};base64,{content_b64}'\n",
" js_code = f\"\"\"\n",
" var a = document.createElement('a');\n",
" a.setAttribute('download', '{filename}');\n",
" a.setAttribute('href', '{data_url}');\n",
" a.click();\n",
" \"\"\"\n",
" with download_report_output:\n",
" clear_output()\n",
" display(HTML(f'<script>{js_code}</script>'))\n",
"\n",
"download_report_output = widgets.Output()\n",
"btn_report = Button(description='Click to download')\n",
"\n",
"def download_html(e=None):\n",
" global qprof\n",
" # Define the HTML content\n",
" html_content = qprof.to_html()\n",
" html_data = html_content.encode('utf-8')\n",
" trigger_download_report(html_data, 'sample.html')\n",
"\n",
"btn_report.on_click(download_html)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "da8af3a2-0c8c-4a82-a6ef-5edb15d53f72",
"metadata": {},
"outputs": [],
Expand All @@ -208,14 +269,57 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"id": "47599ae0-6ffa-41d9-b16a-f346b3f52d72",
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "c8c3fc00be5244139de35530d14bb193",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(HTML(value=\"<a href='/voila/render/ui/qprof_main.ipynb' style='text-decoration: none; padding: …"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "54b45da812df4224a1715f0880badfc7",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Output()"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "4f5abbe49dd64384865f86f9dff2865c",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Output()"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"logging.info(f'[Query Profile Tree Page] Trying to display the back and \"save query plan\" button')\n",
"display(widgets.HBox([html_button1,button_qprof_save]))\n",
"display(output_export)"
"display(widgets.HBox([html_button1,button_download_report, button_qprof_save ]))\n",
"display(output_export, output_download_report)"
]
},
{
Expand Down Expand Up @@ -290,8 +394,15 @@
" tables = widgets.Tab()\n",
" tables.children = [table_1, table_2]\n",
" tables.titles = [\"Slow Events\", \"Optimimzer Events\"]\n",
"\n",
"except Exception as e:\n",
" tables = widgets.VBox([widgets.HTML(f\"<p style='color:red'>The following error occured: </p> <p> {e}</p>\")])\n"
" tables = widgets.VBox([widgets.HTML(f\"<p style='color:red'>The following error occured: </p> <p> {e}</p>\")])\n",
"\n",
"try:\n",
" transactions_table = qprof.get_queries()\n",
" transactions_table = widgets.VBox([widgets.HTML(transactions_table._repr_html_())])\n",
"except Exception as e:\n",
" transactions_table = widgets.VBox([widgets.HTML(f\"<p style='color:red'>The following error occured: </p> <p> {e}</p>\")])"
]
},
{
Expand All @@ -311,9 +422,11 @@
"tabs = widgets.Tab()\n",
"\n",
"child_1 = widgets.VBox([output_tree])\n",
"child_2 = widgets.VBox([tables])\n",
"tabs.children = [child_1, child_2]\n",
"tabs.titles = [\"Tree\", \"Other info\"]\n",
"child_2 = widgets.VBox([transactions_table])\n",
"child_3 = widgets.VBox([tables])\n",
"\n",
"tabs.children = [child_1, child_2, child_3]\n",
"tabs.titles = [\"Tree\", \"Transaction\", \"Other info\"]\n",
"display(tabs)"
]
},
Expand Down Expand Up @@ -366,6 +479,14 @@
"logging.info(f'[Query Profile Tree Page] Trying to display the error log at the bottom of the page')\n",
"accordion\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3e6fadfb-e275-4944-8926-cb8a33a9c866",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
Loading