-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path__init__.py
More file actions
102 lines (82 loc) · 3.49 KB
/
__init__.py
File metadata and controls
102 lines (82 loc) · 3.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
"""
ComfyUI-KikoStats: Real-time monitoring and statistics for ComfyUI
All nodes are grouped under the "ComfyAssets" category
"""
import os
import re
from pathlib import Path
try:
from .kikostats import NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS
except ImportError:
# Handle direct import when run as a custom node
from kikostats import NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS
# Tell ComfyUI where to find our JavaScript extensions
WEB_DIRECTORY = os.path.join(os.path.dirname(os.path.abspath(__file__)), "web")
def get_version():
"""Parse version from pyproject.toml"""
try:
pyproject_path = Path(__file__).parent / "pyproject.toml"
if pyproject_path.exists():
content = pyproject_path.read_text()
match = re.search(r'version\s*=\s*["\']([^"\']+)["\']', content)
if match:
return match.group(1)
except Exception:
pass
return "unknown"
# Start continuous monitoring when ComfyUI loads
try:
from .kikostats.tools.resource_monitor.logic import get_global_monitor
# Initialize the global monitor (starts automatically)
monitor = get_global_monitor()
# Make monitor available globally for JavaScript access
import sys
if "server" in sys.modules:
# Store reference for web access
import server
if hasattr(server, "PromptServer") and hasattr(server.PromptServer, "instance"):
server.PromptServer.instance.kikostats_monitor = monitor
# Add a simple route to expose monitor to JavaScript
try:
from aiohttp import web
async def get_monitor_reference(request):
# This is a hack to expose Python object to JavaScript
return web.Response(
text="window.kikoStatsGlobalMonitor = "
+ str(id(monitor))
+ ";",
content_type="application/javascript",
)
# Don't actually add route - just store reference for JS access
server.PromptServer.instance.kikostats_monitor_id = id(monitor)
except Exception as e:
print(f"[KikoStats] Could not set up monitor access: {e}")
pass
# Install execution hooks for per-node tracking
try:
from .kikostats.execution_hooks import install_execution_hooks
if install_execution_hooks():
print(
"\033[92m[KikoStats] Execution hooks installed for per-node tracking\033[0m"
)
else:
print(
"\033[93m[KikoStats] Could not install execution hooks - per-node tracking disabled\033[0m"
)
except Exception as e:
print(f"\033[93m[KikoStats] Execution hooks error: {e}\033[0m")
print(
"\033[92m[KikoStats] Continuous monitoring initialized on ComfyUI startup\033[0m"
)
except Exception as e:
print(
f"\033[93m[KikoStats] Warning: Could not start continuous monitoring: {e}\033[0m"
)
# Print startup message with loaded tools
print() # Empty line before
print(f"\033[94m[ComfyUI-KikoStats] Version:\033[0m {get_version()}")
for node_key, display_name in NODE_DISPLAY_NAME_MAPPINGS.items():
print(f"🫶 \033[94mLoaded:\033[0m {display_name}")
print(f"\033[94mTotal: {len(NODE_CLASS_MAPPINGS)} monitoring tools loaded\033[0m")
print() # Empty line after
__all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS", "WEB_DIRECTORY"]