public AbstractCounters(Org.Apache.Hadoop.Mapreduce.Counters.AbstractCounters <C1, G1> counters, CounterGroupFactory <C, G> groupFactory) { this.groupFactory = groupFactory; foreach (G1 group in counters) { string name = group.GetName(); G newGroup = groupFactory.NewGroup(name, group.GetDisplayName(), limits); (CounterGroupFactory.IsFrameworkGroup(name) ? fgroups : groups)[name] = newGroup; foreach (Counter counter in group) { newGroup.AddCounter(counter.GetName(), counter.GetDisplayName(), counter.GetValue ()); } } }
/// <summary>Returns the names of all counter classes.</summary> /// <returns>Set of counter names.</returns> public virtual IEnumerable <string> GetGroupNames() { lock (this) { HashSet <string> deprecated = new HashSet <string>(); foreach (KeyValuePair <string, string> entry in legacyMap) { string newGroup = entry.Value; bool isFGroup = CounterGroupFactory.IsFrameworkGroup(newGroup); if (isFGroup ? fgroups.Contains(newGroup) : groups.Contains(newGroup)) { deprecated.AddItem(entry.Key); } } return(Iterables.Concat(fgroups.Keys, groups.Keys, deprecated)); } }
public virtual G AddGroup(G group) { lock (this) { string name = group.GetName(); if (CounterGroupFactory.IsFrameworkGroup(name)) { fgroups[name] = group; } else { limits.CheckGroups(groups.Count + 1); groups[name] = group; } return(group); } }
/// <summary> /// Increments multiple counters by their amounts in another Counters /// instance. /// </summary> /// <param name="other">the other Counters instance</param> public virtual void IncrAllCounters(Org.Apache.Hadoop.Mapreduce.Counters.AbstractCounters <C, G> other) { lock (this) { foreach (G right in other) { string groupName = right.GetName(); G left = (CounterGroupFactory.IsFrameworkGroup(groupName) ? fgroups : groups)[groupName ]; if (left == null) { left = AddGroup(groupName, right.GetDisplayName()); } left.IncrAllCounters(right); } } }
/// <summary>Write the set of groups.</summary> /// <remarks> /// Write the set of groups. /// Counters ::= version #fgroups (groupId, group)* #groups (group) /// </remarks> /// <exception cref="System.IO.IOException"/> public virtual void Write(DataOutput @out) { lock (this) { WritableUtils.WriteVInt(@out, groupFactory.Version()); WritableUtils.WriteVInt(@out, fgroups.Count); // framework groups first foreach (G group in fgroups.Values) { if (group.GetUnderlyingGroup() is FrameworkCounterGroup <object, object> ) { WritableUtils.WriteVInt(@out, (int)(AbstractCounters.GroupType.Framework)); WritableUtils.WriteVInt(@out, CounterGroupFactory.GetFrameworkGroupId(group.GetName ())); group.Write(@out); } else { if (group.GetUnderlyingGroup() is FileSystemCounterGroup <object> ) { WritableUtils.WriteVInt(@out, (int)(AbstractCounters.GroupType.Filesystem)); group.Write(@out); } } } if (writeAllCounters) { WritableUtils.WriteVInt(@out, groups.Count); foreach (G group_1 in groups.Values) { Text.WriteString(@out, group_1.GetName()); group_1.Write(@out); } } else { WritableUtils.WriteVInt(@out, 0); } } }
/// <summary> /// Returns the named counter group, or an empty group if there is none /// with the specified name. /// </summary> /// <param name="groupName">name of the group</param> /// <returns>the group</returns> public virtual G GetGroup(string groupName) { lock (this) { // filterGroupName bool groupNameInLegacyMap = true; string newGroupName = legacyMap[groupName]; if (newGroupName == null) { groupNameInLegacyMap = false; newGroupName = Org.Apache.Hadoop.Mapreduce.Counters.Limits.FilterGroupName(groupName ); } bool isFGroup = CounterGroupFactory.IsFrameworkGroup(newGroupName); G group = isFGroup ? fgroups[newGroupName] : groups[newGroupName]; if (group == null) { group = groupFactory.NewGroup(newGroupName, limits); if (isFGroup) { fgroups[newGroupName] = group; } else { limits.CheckGroups(groups.Count + 1); groups[newGroupName] = group; } if (groupNameInLegacyMap) { Log.Warn("Group " + groupName + " is deprecated. Use " + newGroupName + " instead" ); } } return(group); } }
public AbstractCounters(CounterGroupFactory <C, G> gf) { groupFactory = gf; }