SAP HANA Performance MCP Server
MCP server for SAP HANA performance analysis: query plan capture, PlanViz export, expensive statement monitoring, plan cache inspection, table statistics, memory stats, and active session tracking.
This commit is contained in:
37
src/hana_performance_mcp/formatting.py
Normal file
37
src/hana_performance_mcp/formatting.py
Normal file
@@ -0,0 +1,37 @@
|
||||
from __future__ import annotations
|
||||
|
||||
|
||||
def format_bytes(n: int | None) -> str:
|
||||
if n is None or n < 0:
|
||||
return "N/A"
|
||||
if n < 1024:
|
||||
return f"{n} B"
|
||||
if n < 1024**2:
|
||||
return f"{n / 1024:.1f} KB"
|
||||
if n < 1024**3:
|
||||
return f"{n / 1024 ** 2:.1f} MB"
|
||||
return f"{n / 1024 ** 3:.2f} GB"
|
||||
|
||||
|
||||
def format_duration(microseconds: int | None) -> str:
|
||||
if microseconds is None:
|
||||
return "N/A"
|
||||
if microseconds < 1000:
|
||||
return f"{microseconds} us"
|
||||
ms = microseconds / 1000
|
||||
if ms < 1000:
|
||||
return f"{ms:.1f} ms"
|
||||
sec = ms / 1000
|
||||
if sec < 60:
|
||||
return f"{sec:.1f} s"
|
||||
minutes = int(sec // 60)
|
||||
remaining_sec = sec % 60
|
||||
return f"{minutes}m {remaining_sec:.0f}s"
|
||||
|
||||
|
||||
def truncate(s: str | None, max_len: int = 200) -> str:
|
||||
if s is None:
|
||||
return ""
|
||||
if len(s) <= max_len:
|
||||
return s
|
||||
return s[:max_len] + "..."
|
||||
Reference in New Issue
Block a user