LogicalOperationStack PropertyReader

Jun 17, 2010 at 9:38 PM

I put together a couple of PropertyReaders for the LogicalOperationStack.  The first reader creates a string from the contents of the TraceEventCache.LogicalOperationStack.  It is created in reverse order so that the bottom of the stack appears at the beginning of the string while the top of the stack appears at the end of the string.  The stack entries are delimited by ">".  Could probably specify that as a configuration property.  The second reader gets the topmost value on the stack via the Peek() method.  Could possibly be modified to return the topmost N elements via a configuration property.

Obviously these could be used to log the LogicalOperationStack information as directly set on the Trace object.  Even better, they could be used in conjunction with the ExtendedSource.  The MethodProfiler could add the message parameter to the Trace.LogicalOperationStack.  With either of these property readers in place, each log entry during the scop of the profiler would be tagged with the profile "name" (or whatever the message represents).

Feel free to add these (or not).

  public class LogicalOperationStackReader : StringPropertyReader
  {
    public override bool TryGetValue(out object value, TraceEventCache cache, string source, TraceEventType eventType, int id, string formatOrMessage, object[] data)
    {
      if (cache == null || cache.LogicalOperationStack.Count == 0)
      {
        value = string.Empty;
        return true;
      }

      value = string.Join(">",cache.LogicalOperationStack.ToArray().Reverse());

      return true;
    }
  }

  public class LogicalOperationStackPeekReader : StringPropertyReader
  {
    public override bool TryGetValue(out object value, TraceEventCache cache, string source, TraceEventType eventType, int id, string formatOrMessage, object[] data)
    {
      if (cache == null || cache.LogicalOperationStack.Count == 0)
      {
        value = string.Empty;
        return true;
      }

      value = cache.LogicalOperationStack.Peek().ToString();

      return true;
    }
  }

Coordinator
Jun 18, 2010 at 4:57 PM

Thanks  and nice suggestions. I'll hopefully find some time to play with these and approve and add them to the source.

Regards

Josh