增加可选性能埋点并完成物性效率评估
This commit is contained in:
1 parent
4e0b9fd8cc
commit
57b459bc72
21 files changed
+2029
-179
No files matched your search
+29
-6
@@ -21,6 +21,7 @@ from fastapi import FastAPI, HTTPException, Request, Response
|
||||
from fastapi.responses import FileResponse, HTMLResponse, StreamingResponse
|
||||
from pydantic import BaseModel, ConfigDict, Field, ValidationError
|
||||
|
||||
from app.simulation.performance import performance_span, profile_phase, profile_run
|
||||
from app.system_xml import (
|
||||
SystemXmlDocument,
|
||||
SystemXmlValidationReport,
|
||||
@@ -666,6 +667,26 @@ def run_system_xml_simulation(
|
||||
xml_bytes: bytes,
|
||||
progress_callback: SimulationProgressEmitter | None = None,
|
||||
cancel_check: Callable[[], bool] | None = None,
|
||||
) -> dict[str, object]:
|
||||
with profile_run() as trace:
|
||||
result = _run_system_xml_simulation_profiled(
|
||||
xml_bytes,
|
||||
progress_callback,
|
||||
cancel_check,
|
||||
)
|
||||
|
||||
performance = trace.snapshot()
|
||||
if performance.get("mode") != "off":
|
||||
diagnostics = dict(result.get("diagnostics", {}))
|
||||
diagnostics["performance"] = performance
|
||||
result["diagnostics"] = diagnostics
|
||||
return result
|
||||
|
||||
|
||||
def _run_system_xml_simulation_profiled(
|
||||
xml_bytes: bytes,
|
||||
progress_callback: SimulationProgressEmitter | None = None,
|
||||
cancel_check: Callable[[], bool] | None = None,
|
||||
) -> dict[str, object]:
|
||||
from app.simulation.solvers.algebraic import AlgebraicSolveError
|
||||
from app.simulation.solvers.solver import SolveIVPConfig
|
||||
@@ -792,12 +813,13 @@ def run_system_xml_simulation(
|
||||
},
|
||||
) from exc
|
||||
|
||||
return {
|
||||
"validation": report.as_dict(),
|
||||
"simulation": document.as_model_data()["simulation"],
|
||||
"model": network.as_interface_dict(),
|
||||
**result.as_dict(),
|
||||
}
|
||||
with performance_span("simulation.response_assembly"):
|
||||
return {
|
||||
"validation": report.as_dict(),
|
||||
"simulation": document.as_model_data()["simulation"],
|
||||
"model": network.as_interface_dict(),
|
||||
**result.as_dict(),
|
||||
}
|
||||
|
||||
|
||||
def simulation_event_stream(
|
||||
@@ -1200,6 +1222,7 @@ def compile_reactflow_network(
|
||||
)
|
||||
|
||||
|
||||
@profile_phase("simulation.network_compilation")
|
||||
def compile_system_xml_network(
|
||||
document: SystemXmlDocument,
|
||||
*,
|
||||
|
||||
Reference in new issue
Block a user