CodePaste Logo
New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Language: C#

Simple.Manifest.cs

803 Views
Copy Code Show/Hide Line Numbers
   1:  //---------------------------------------------------------------------
   2:  // <autogenerated>
   3:  //
   4:  //     Generated by Message Compiler (mc.exe)
   5:  //
   6:  //     Copyright (c) Microsoft Corporation. All Rights Reserved.
   7:  //
   8:  //     Changes to this file may cause incorrect behavior and will be lost if
   9:  //     the code is regenerated.
  10:  // </autogenerated>
  11:  //---------------------------------------------------------------------
  12:  namespace ETW
  13:  {
  14:  using System;
  15:  using System.Collections.Generic;
  16:  using System.Text;
  17:  using System.Diagnostics;
  18:  using System.Diagnostics.Eventing;
  19:  using Microsoft.Win32;
  20:  using System.Runtime.InteropServices;
  21:  using System.Security.Principal;
  22:   
  23:      public static class SampleProvider
  24:      {
  25:          //
  26:          // Provider SampleProvider Event Count 1
  27:          //
  28:          static void Main(string[] args)
  29:          {
  30:              for (int i = 0; i < 100; i++)
  31:              {
  32:                  var obj = new object[85001]; 
  33:                  ETW.SampleProvider.EventWriteSampleEvent("Allocating object" , i);
  34:              }
  35:          }
  36:      
  37:          private static EventProviderVersionTwo m_provider = new EventProviderVersionTwo(new Guid("d9b453b9-6230-486c-8dec-c7c5a2230d04"));
  38:          //
  39:          // Task :  eventGUIDs
  40:          //
  41:          private static Guid SampleTaskId = new Guid("9b0655be-219f-439e-9439-b604bd822e22");
  42:   
  43:          //
  44:          // Event Descriptors
  45:          //
  46:          private static EventDescriptor SampleEvent;
  47:   
  48:   
  49:          static SampleProvider()
  50:          {
  51:              unchecked
  52:              {
  53:                  SampleEvent = new EventDescriptor(0x3e9, 0x1, 0x10, 0x4, 0xa, 0x1, (long)0x8000000000000001);
  54:              }
  55:          }
  56:   
  57:   
  58:          //
  59:          // Event method for SampleEvent
  60:          //
  61:          public static bool EventWriteSampleEvent(string StringData, int IntegerData)
  62:          {
  63:   
  64:              if (!m_provider.IsEnabled())
  65:              {
  66:                  return true;
  67:              }
  68:   
  69:              return m_provider.TemplateSimpleTemplate(ref SampleEvent, StringData, IntegerData);
  70:          }
  71:      }
  72:   
  73:      internal class EventProviderVersionTwo : EventProvider
  74:      {
  75:           internal EventProviderVersionTwo(Guid id)
  76:                  : base(id)
  77:           {}
  78:   
  79:   
  80:          [StructLayout(LayoutKind.Explicit, Size = 16)]
  81:          private struct EventData
  82:          {
  83:              [FieldOffset(0)]
  84:              internal UInt64 DataPointer;
  85:              [FieldOffset(8)]
  86:              internal uint Size;
  87:              [FieldOffset(12)]
  88:              internal int Reserved;
  89:          }
  90:   
  91:   
  92:   
  93:          internal unsafe bool TemplateSimpleTemplate(
  94:              ref EventDescriptor eventDescriptor,
  95:              string StringData,
  96:              int IntegerData
  97:              )
  98:          {
  99:              int argumentCount = 2;
 100:              bool status = true;
 101:   
 102:              if (IsEnabled(eventDescriptor.Level, eventDescriptor.Keywords))
 103:              {
 104:                  byte* userData = stackalloc byte[sizeof(EventData) * argumentCount];
 105:                  EventData* userDataPtr = (EventData*)userData;
 106:   
 107:                  userDataPtr[0].Size = (uint)(StringData.Length + 1)*sizeof(char);
 108:   
 109:                  userDataPtr[1].DataPointer = (UInt64)(&IntegerData);
 110:                  userDataPtr[1].Size = (uint)(sizeof(int)  );
 111:   
 112:                  fixed (char* a0 = StringData)
 113:                  {
 114:                      userDataPtr[0].DataPointer = (ulong)a0;
 115:                      status = WriteEvent(ref eventDescriptor, argumentCount, (IntPtr)(userData));
 116:                  }
 117:              }
 118:   
 119:              return status;
 120:   
 121:          }
 122:   
 123:      }
 124:   
 125:  }
by naveensrinivasan
  March 16, 2010 @ 9:45pm
Tags:
Description:
This sample cs file is going to be used to generate custom etw traces.

Add a comment


Report Abuse
brought to you by:
West Wind Techologies



If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate