forked from ryanontheinside/ComfyUI_ProfilerX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
48 lines (43 loc) · 1.99 KB
/
server.py
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
"""Server routes for the profiler extension"""
import json
from aiohttp import web
from server import PromptServer
from .profiler_core import ProfilerManager
@PromptServer.instance.routes.get('/profilerx/stats')
async def get_stats(request):
"""Get the current profiling stats"""
profiler = ProfilerManager.get_instance()
stats = profiler.get_stats()
return web.json_response(stats if stats else {})
@PromptServer.instance.routes.get('/profilerx/archives')
async def get_archives(request):
"""Get list of archived history files"""
profiler = ProfilerManager.get_instance()
archives = profiler.get_archives()
return web.json_response(archives)
@PromptServer.instance.routes.post('/profilerx/archive')
async def create_archive(request):
"""Create a new archive of current history"""
profiler = ProfilerManager.get_instance()
archive_name = profiler.archive_history()
if archive_name:
return web.json_response({"success": True, "archive": archive_name})
return web.json_response({"success": False, "error": "Failed to create archive"}, status=500)
@PromptServer.instance.routes.post('/profilerx/archive/{filename}/load')
async def load_archive(request):
"""Load an archived history file"""
filename = request.match_info['filename']
profiler = ProfilerManager.get_instance()
success = profiler.load_archive(filename)
if success:
return web.json_response({"success": True})
return web.json_response({"success": False, "error": f"Failed to load archive: {filename}"}, status=400)
@PromptServer.instance.routes.delete('/profilerx/archive/{filename}')
async def delete_archive(request):
"""Delete an archived history file"""
filename = request.match_info['filename']
profiler = ProfilerManager.get_instance()
success = profiler.delete_archive(filename)
if success:
return web.json_response({"success": True})
return web.json_response({"success": False, "error": f"Failed to delete archive: {filename}"}, status=400)