image.domain\self_evolve\root_cause.mbt

65.5% · 38 / 58 points · 147 lines

Background color reports the state of each line. Underlined characters mark exact instrumented byte offsets; hover them to inspect the visit count.

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