image.domain\self_evolve\root_cause.mbt
65.5% · 38 / 58 points · 147 linesBackground color reports the state of each line. Underlined characters mark exact instrumented byte offsets; hover them to inspect the visit count.
- 1
///| - 2
/// # 根因分析 self_evolve/root_cause - 3
/// - 4
/// 图像处理库子模块 - 5
/// 图像处理库子模块 Image processing library submodule - 6
// 退化根因分析 — 分析退化根因(参数来源/传播路径) - 7
// Root cause analysis: analyze degradation root cause - 8
// - 9
// Phase 6 v289: 将退化检测从"发现"推向"根因定位" — 指出根因参数 + 修复建议。 - 10
- 11
///| - 12
/// 单个退化根因。 - 13
/// 描述 Single degradation root cause. - 14
#derive(Eq, @debug.Debug) - 15
pub(all) struct RootCause { - 16
op_tag : String - 17
degradation_kind : DegradationKind - 18
root_param : String - 19
cause_desc : String - 20
fix_suggestion : String - 21
} - 22
- 23
///| - 24
pub extend RootCause with @debug.Debug::{to_repr} - 25
- 26
///| - 27
pub extend RootCause with Eq::{not_equal, equal} - 28
- 29
///| - 30
/// 根因分析报告。 - 31
/// 描述 Root cause analysis report. - 32
#derive(Eq, @debug.Debug) - 33
pub(all) struct RootCauseReport { - 34
causes : Array[RootCause] - 35
total : Int32 - 36
summary : String - 37
} - 38
- 39
///| - 40
pub extend RootCauseReport with @debug.Debug::{to_repr} - 41
- 42
///| - 43
pub extend RootCauseReport with Eq::{not_equal, equal} - 44
- 45
///| - 46
/// 分析单算子退化根因(根因参数 + 修复建议)。 - 47
/// 描述 Analyze root cause of a single op's degradations. - 48
pub fn analyze_root_cause(op : @imgir.IROp) -> Array[RootCause] { - 49●
let degs = detect_degradation(op) - 50
let causes : Array[RootCause] = [] - 51
for d in degs { - 52●
let root_param = match op { - 53◐
Resize(w, _h) => if w == 0 { "w=0" } else { "h=0" } - 54◐
Crop(_x, _y, w, _h) => if w == 0 { "w=0" } else { "h=0" } - 55
GaussianBlur(_r, sigma) => - 56●
if sigma == 0.0F { - 57●
"sigma=0" - 58
} else { - 59○
"sigma<0" - 60
} - 61○
Sharpen(amount) => "amount=" + amount.to_string() - 62○
FieldClamp(lo, hi) => "lo=" + lo.to_string() + ">hi=" + hi.to_string() - 63○
FieldMask(t) => "threshold=" + t.to_string() - 64●
STSnapshot(t) => "t=" + t.to_string() - 65○
STInterpolate(t) => "t=" + t.to_string() - 66○
_ => "unknown" - 67
} - 68●
let fix = match op { - 69●
Resize(_, _) => "尺寸→1" - 70●
Crop(_, _, _, _) => "尺寸→1" - 71●
GaussianBlur(_, _) => "sigma→1.0" - 72○
Sharpen(_) => "clamp[-100,100]" - 73○
FieldClamp(_, _) => "swap(lo,hi)" - 74○
FieldMask(_) => "threshold→0.0" - 75●
STSnapshot(_) => "clamp[0,1]" - 76○
STInterpolate(_) => "clamp[0,1]" - 77○
_ => "review" - 78
} - 79●
causes.push({ - 80●
op_tag: op.tag(), - 81
degradation_kind: d.kind, - 82
root_param, - 83
cause_desc: d.description, - 84
fix_suggestion: fix, - 85
}) - 86
} - 87
causes - 88
} - 89
- 90
///| - 91
/// 对全部 19 种算子分析根因。 - 92
/// 描述 Analyze root cause for all 19 op variants. - 93
pub fn analyze_root_cause_all() -> RootCauseReport { - 94●
let causes : Array[RootCause] = [] - 95●
for op in all_ops() { - 96●
for c in analyze_root_cause(op) { - 97○
causes.push(c) - 98
} - 99
} - 100●
let total = causes.length() - 101●
let summary = "根因分析: " + total.to_string() + " 处退化根因定位" - 102
{ causes, total, summary, } - 103
} - 104
- 105
///| - 106
/// 对管道分析根因。 - 107
/// 描述 Analyze root cause for a pipeline. - 108
pub fn analyze_pipeline_root_cause( - 109
pipeline : @imgir.IRPipeline, - 110
) -> RootCauseReport { - 111●
let causes : Array[RootCause] = [] - 112
for op in pipeline.ops { - 113●
for c in analyze_root_cause(op) { - 114●
causes.push(c) - 115
} - 116
} - 117●
let total = causes.length() - 118
let summary = "管道根因分析: " + - 119●
total.to_string() + - 120
" 处退化根因(管道 " + - 121●
@imgir.ir_describe(pipeline) + - 122
")" - 123
{ causes, total, summary, } - 124
} - 125
- 126
///| - 127
/// 根因报告是否无退化。 - 128
/// 描述 Whether root cause report has no degradation. - 129
pub fn RootCauseReport::is_clean(self : RootCauseReport) -> Bool { - 130●
self.total == 0 - 131
} - 132
- 133
///| - 134
/// 按退化类型过滤根因。 - 135
/// 滤波 Filter root causes by degradation kind. - 136
pub fn filter_by_kind( - 137
causes : Array[RootCause], - 138
kind : DegradationKind, - 139
) -> Array[RootCause] { - 140●
let result : Array[RootCause] = [] - 141
for c in causes { - 142●
if c.degradation_kind == kind { - 143●
result.push(c) - 144
} - 145
} - 146
result - 147
}