private bool Match(string attribute, Regex regex, IceMX.MetricsHelper <T> helper, bool reject) { string value; try { value = helper.Resolve(attribute); } catch (Exception) { return(!reject); } return(regex.IsMatch(value)); }
public O getObserver(MetricsHelper <T> helper, object observer) { lock (this) { List <MetricsMap <T> .Entry> metricsObjects = null; O old = null; try { old = (O)observer; } catch (InvalidCastException) { } foreach (MetricsMap <T> m in _maps) { MetricsMap <T> .Entry e = m.getMatching(helper, old != null ? old.getEntry(m) : null); if (e != null) { if (metricsObjects == null) { metricsObjects = new List <MetricsMap <T> .Entry>(_maps.Count); } metricsObjects.Add(e); } } if (metricsObjects == null) { if (old != null) { old.detach(); } return(null); } O obsv; try { obsv = new O(); } catch (Exception) { Debug.Assert(false); return(null); } obsv.init(helper, metricsObjects, old); return(obsv); } }
public string Resolve(MetricsHelper <T> helper, string attribute) { if (!_attributes.TryGetValue(attribute, out MetricsHelper <T> .AttributeResolver.Resolver? resolver)) { if (attribute.Equals("none")) { return(""); } string?v = helper.DefaultResolve(attribute); if (v != null) { return(v); } throw new ArgumentOutOfRangeException(attribute); } return(resolver.ResolveImpl(helper)); }
public void init(MetricsHelper <T> helper, List <MetricsMap <T> .Entry> objects, Observer <T> previous) { _objects = objects; if (previous == null) { return; } _previousDelay = previous._previousDelay + (long)(previous.ElapsedTicks / (Frequency / 1000000.0)); foreach (MetricsMap <T> .Entry e in previous._objects) { if (!_objects.Contains(e)) { e.detach(_previousDelay); } } }
internal MetricsMap <S> .Entry?GetMatching <S>(string mapName, IceMX.MetricsHelper <S> helper) where S : IceMX.Metrics, new() { ISubMap?m; lock (_map) { if (_subMaps == null || !_subMaps.TryGetValue(mapName, out m)) { m = _map.CreateSubMap(mapName); if (m == null) { return(null); } if (_subMaps == null) { _subMaps = new Dictionary <string, ISubMap>(); } _subMaps.Add(mapName, m); } } return(((SubMap <S>)m).GetMatching(helper)); }
public ObserverImpl getObserver <S, ObserverImpl>(string mapName, MetricsHelper <S> helper) where S : Metrics, new() where ObserverImpl : Observer <S>, new() { List <MetricsMap <S> .Entry> metricsObjects = null; foreach (MetricsMap <T> .Entry entry in _objects) { MetricsMap <S> .Entry e = entry.getMatching(mapName, helper); if (e != null) { if (metricsObjects == null) { metricsObjects = new List <MetricsMap <S> .Entry>(_objects.Count); } metricsObjects.Add(e); } } if (metricsObjects == null) { return(null); } try { ObserverImpl obsv = new ObserverImpl(); obsv.init(helper, metricsObjects, null); return(obsv); } catch (Exception) { Debug.Assert(false); return(null); } }
public O getObserver(MetricsHelper <T> helper) { return(getObserver(helper, null)); }
public Entry?GetMatching(IceMX.MetricsHelper <T> helper, Entry?previous) { // // Check the accept and reject filters. // foreach (KeyValuePair <string, Regex> e in _accept) { if (!Match(e.Key, e.Value, helper, false)) { return(null); } } foreach (KeyValuePair <string, Regex> e in _reject) { if (Match(e.Key, e.Value, helper, true)) { return(null); } } // // Compute the key from the GroupBy property. // string key; try { if (_groupByAttributes.Count == 1) { key = helper.Resolve(_groupByAttributes[0]); } else { var os = new StringBuilder(); IEnumerator <string> q = _groupBySeparators.GetEnumerator(); foreach (string p in _groupByAttributes) { os.Append(helper.Resolve(p)); if (q.MoveNext()) { os.Append(q.Current); } } key = os.ToString(); } } catch (Exception) { return(null); } // // Lookup the metrics object. // lock (this) { if (previous != null && previous.GetId().Equals(key)) { Debug.Assert(_objects[key] == previous); return(previous); } if (!_objects.TryGetValue(key, out MetricsMap <T> .Entry? e)) { try { var t = new T(); t.Id = key; e = new Entry(this, t); _objects.Add(key, e); } catch (Exception) { Debug.Assert(false); } } e.Attach(helper); return(e); } }
internal void Attach(IceMX.MetricsHelper <T> helper) { ++_object.Total; ++_object.Current; helper.InitMetrics(_object); }