Skip to content

Commit 6feadbf

Browse files
committed
feat: Update sampling config. Remove SamplingSettings and use hardcoded values for simplification.
1 parent 7831025 commit 6feadbf

2 files changed

Lines changed: 49 additions & 34 deletions

File tree

MCPForUnity/Editor/ActionTrace/Capture/Sampling/SamplingConfig.cs

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,53 @@ namespace MCPForUnity.Editor.ActionTrace.Capture
77
/// <summary>
88
/// Static configuration for sampling strategies.
99
/// Event types can be registered with their desired sampling behavior.
10+
///
11+
/// Sampling intervals are configured via hardcoded constants.
12+
/// To customize sampling behavior, modify InitializeStrategies() directly.
1013
/// </summary>
1114
public static class SamplingConfig
1215
{
16+
// Hardcoded sampling intervals (milliseconds)
17+
private const int HierarchySamplingMs = 1000;
18+
private const int SelectionSamplingMs = 500;
19+
private const int PropertySamplingMs = 200;
20+
1321
/// <summary>
1422
/// Default sampling strategies for common event types.
1523
/// Configured to prevent event floods while preserving important data.
1624
/// Thread-safe: uses ConcurrentDictionary to prevent race conditions
1725
/// when accessed from EditorApplication.update and event emitters simultaneously.
1826
/// </summary>
1927
public static readonly ConcurrentDictionary<string, SamplingStrategy> Strategies = new(
20-
new Dictionary<string, SamplingStrategy>
28+
InitializeStrategies()
29+
);
30+
31+
/// <summary>
32+
/// Initializes sampling strategies with hardcoded values.
33+
/// </summary>
34+
private static Dictionary<string, SamplingStrategy> InitializeStrategies()
35+
{
36+
return new Dictionary<string, SamplingStrategy>
2137
{
2238
// Hierarchy changes: Throttle to 1 event per second
2339
{
2440
EventTypes.HierarchyChanged,
25-
new SamplingStrategy(SamplingMode.Throttle, 1000)
41+
new SamplingStrategy(SamplingMode.Throttle, HierarchySamplingMs)
2642
},
2743

28-
// PropertyModified handling removed here to avoid double-debounce when
29-
// PropertyChangeTracker already implements a dedicated debounce window.
30-
// If desired, SamplingConfig.SetStrategy(EventTypes.PropertyModified, ...) can
31-
// be used at runtime to re-enable middleware-level sampling.
44+
// Selection changes: Throttle to 1 event per 500ms
45+
{
46+
EventTypes.SelectionChanged,
47+
new SamplingStrategy(SamplingMode.Throttle, SelectionSamplingMs)
48+
},
49+
50+
// Property modifications: Debounce by key (200ms window)
51+
// Note: PropertyChangeTracker also implements its own debounce window,
52+
// so this provides additional protection against event storms.
53+
{
54+
EventTypes.PropertyModified,
55+
new SamplingStrategy(SamplingMode.DebounceByKey, PropertySamplingMs)
56+
},
3257

3358
// Component/GameObject events: No sampling (always record)
3459
// ComponentAdded, ComponentRemoved, GameObjectCreated, GameObjectDestroyed
@@ -42,8 +67,8 @@ public static class SamplingConfig
4267

4368
// Build events: No sampling (record all)
4469
// BuildStarted, BuildCompleted, BuildFailed are not in this dictionary
45-
}
46-
);
70+
};
71+
}
4772

4873
/// <summary>
4974
/// Adds or updates a sampling strategy for an event type.

MCPForUnity/Editor/ActionTrace/Core/Settings/ActionTraceSettings.cs

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public sealed class StorageSettings
5959
public int MaxEvents = 800;
6060

6161
[Range(10, 1000)]
62-
[Tooltip("Number of hot events (10-1000) to retain with full payload. Older events will be dehydrated (Payload=null).")]
62+
[Tooltip("Number of hot events (10-1000) to retain with full payload. Events are kept in sequence order; the first N events (oldest) have full payload, while events beyond this limit are dehydrated (Payload=null).")]
6363
public int HotEventCount = 150;
6464

6565
[Tooltip("Minimum number of events to keep when auto-cleaning.")]
@@ -72,28 +72,18 @@ public sealed class StorageSettings
7272
public int AutoSaveIntervalSeconds = 30;
7373
}
7474

75-
/// <summary>
76-
/// Layered settings for sampling and throttling.
77-
/// Controls how high-frequency events are sampled.
78-
/// </summary>
79-
[Serializable]
80-
public sealed class SamplingSettings
81-
{
82-
[Tooltip("Enable global sampling. Events below threshold will be sampled.")]
83-
public bool EnableSampling = true;
84-
85-
[Tooltip("Sampling importance threshold. Events below this value may be sampled.")]
86-
public float SamplingImportanceThreshold = 0.3f;
87-
88-
[Tooltip("HierarchyChanged event sampling interval (milliseconds).")]
89-
public int HierarchySamplingMs = 1000;
90-
91-
[Tooltip("SelectionChanged event sampling interval (milliseconds).")]
92-
public int SelectionSamplingMs = 500;
93-
94-
[Tooltip("PropertyModified event sampling interval (milliseconds).")]
95-
public int PropertySamplingMs = 200;
96-
}
75+
// SamplingSettings is deprecated. Sampling is now configured via SamplingConfig
76+
// with hardcoded values to avoid runtime configuration complexity.
77+
//
78+
// [Serializable]
79+
// public sealed class SamplingSettings
80+
// {
81+
// public bool EnableSampling = true;
82+
// public float SamplingImportanceThreshold = 0.3f;
83+
// public int HierarchySamplingMs = 1000;
84+
// public int SelectionSamplingMs = 500;
85+
// public int PropertySamplingMs = 200;
86+
// }
9787

9888
/// <summary>
9989
/// Persistent settings for the ActionTrace system.
@@ -120,9 +110,9 @@ public sealed class ActionTraceSettings : ScriptableObject
120110
[Tooltip("Controls event storage limits and memory management")]
121111
public StorageSettings Storage = new();
122112

123-
[Header("Event Sampling")]
124-
[Tooltip("Controls high-frequency event sampling to prevent event storms")]
125-
public SamplingSettings Sampling = new();
113+
// Sampling is configured via SamplingConfig with hardcoded values
114+
// To customize, modify SamplingConfig.InitializeStrategies() directly
115+
// public SamplingSettings Sampling = new();
126116

127117
// ========== Runtime State ==========
128118

0 commit comments

Comments
 (0)