/// <summary>
 /// Opens on existing circular buffer.
 /// </summary>
 /// <param name="buffer">Position of the circular buffer</param>
 /// <returns>NativeCircularBuffer object representing the circular buffer</returns>
 public static UnmanagedCircularBuffer Open(IntPtr buffer)
 {
     UnmanagedCircularBufferHeader* header = (UnmanagedCircularBufferHeader*)buffer.ToPointer();
     if (header->Magic != 0x7e434231) {
         throw new InvalidDataException("Can not open cicular buffer. Invalid header.");
     }
     int totalLength = header->TotalLength;
     UnmanagedCircularBuffer b = new UnmanagedCircularBuffer(buffer, totalLength);
     b.nonEmptyEvent = EventWaitHandle.OpenExisting(GetEventName(b.header->NonEmptyEventName));
     b.nonFullEvent = EventWaitHandle.OpenExisting(GetEventName(b.header->NonFullEventName));
     return b;
 }
예제 #2
0
		/// <summary>
		/// Creates a new circular buffer.
		/// </summary>
		/// <param name="buffer">Position where the circular buffer should be created</param>
		/// <param name="bufferLength">Length of the circular buffer. Not the whole length is available
		/// for data, some space will be used for synchronization.</param>
		/// <returns>NativeCircularBuffer object representing the circular buffer</returns>
		public static UnmanagedCircularBuffer Create(IntPtr buffer, int bufferLength)
		{
			UnmanagedCircularBuffer b = new UnmanagedCircularBuffer(buffer, bufferLength);
			b.header->Magic = 0x7e434231; // '~CB1'
			b.header->TotalLength = bufferLength;
			b.header->startOffset = 0;
			b.header->endOffset = 0;
			b.nonEmptyEvent = CreateNew(ref b.header->NonEmptyEventName, false);
			b.nonFullEvent = CreateNew(ref b.header->NonFullEventName, true);
			Thread.MemoryBarrier(); // ensure NonEmptyEventName and NonFullEventName are flushed to RAM
			return b;
		}
 /// <summary>
 /// Creates a new circular buffer.
 /// </summary>
 /// <param name="buffer">Position where the circular buffer should be created</param>
 /// <param name="bufferLength">Length of the circular buffer. Not the whole length is available
 /// for data, some space will be used for synchronization.</param>
 /// <returns>NativeCircularBuffer object representing the circular buffer</returns>
 public static UnmanagedCircularBuffer Create(IntPtr buffer, int bufferLength)
 {
     UnmanagedCircularBuffer b = new UnmanagedCircularBuffer(buffer, bufferLength);
     b.header->Magic = 0x7e434231; // '~CB1'
     b.header->TotalLength = bufferLength;
     b.header->startOffset = 0;
     b.header->endOffset = 0;
     b.nonEmptyEvent = CreateNew(ref b.header->NonEmptyEventName, false);
     b.nonFullEvent = CreateNew(ref b.header->NonFullEventName, true);
     Thread.MemoryBarrier(); // ensure NonEmptyEventName and NonFullEventName are flushed to RAM
     return b;
 }
			/// <summary>
			/// Constructs a NativeCircularBufferWritingStream
			/// </summary>
			public WritingStream(UnmanagedCircularBuffer circularBuffer)
				: base(circularBuffer)
			{
				this.WriteTimeout = Timeout.Infinite;
			}
			/// <summary>
			/// Constructs a UnmanagedCircularBufferReadingStream
			/// </summary>
			public ReadingStream(UnmanagedCircularBuffer circularBuffer)
				: base(circularBuffer)
			{
				this.ReadTimeout = Timeout.Infinite;
			}
			public BaseStream(UnmanagedCircularBuffer circularBuffer)
			{
				this.circularBuffer = circularBuffer;
				this.header = circularBuffer.header;
			}
		/// <summary>
		/// Opens on existing circular buffer.
		/// </summary>
		/// <param name="buffer">Position of the circular buffer</param>
		/// <returns>NativeCircularBuffer object representing the circular buffer</returns>
		public static UnmanagedCircularBuffer Open(IntPtr buffer)
		{
			UnmanagedCircularBufferHeader* header = (UnmanagedCircularBufferHeader*)buffer.ToPointer();
			if (header->Magic != 0x7e434231) {
				throw new InvalidDataException("Can not open cicular buffer. Invalid header.");
			}
			int totalLength = header->TotalLength;
			UnmanagedCircularBuffer b = new UnmanagedCircularBuffer(buffer, totalLength);
			b.nonEmptyEvent = EventWaitHandle.OpenExisting(GetEventName(b.header->NonEmptyEventName));
			b.nonFullEvent = EventWaitHandle.OpenExisting(GetEventName(b.header->NonFullEventName));
			return b;
		}
예제 #8
0
		/// <summary>
		/// Starts a new profiling session. Prepares IPC and starts the process and logging.
		/// </summary>
		/// <returns>The process information of the profilee.</returns>
		public Process Start()
		{
			VerifyAccess();
			
			if (is64Bit)
				InitializeHeader64();
			else
				InitializeHeader32();
			
			isRunning = true;
			
			RegisterProfiler();

			if (is64Bit) {
				nativeToManagedBuffer = UnmanagedCircularBuffer.Create(
					new IntPtr(fullView.Pointer + memHeader64->NativeToManagedBufferOffset), bufferSize);
				if ((Int64)(fullView.Pointer + memHeader64->NativeToManagedBufferOffset) % 8 != 0) {
					throw new DataMisalignedException("nativeToManagedBuffer is not properly aligned!");
				}
			} else {
				nativeToManagedBuffer = UnmanagedCircularBuffer.Create(
					new IntPtr(fullView.Pointer + memHeader32->NativeToManagedBufferOffset), bufferSize);
				if ((Int32)(fullView.Pointer + memHeader32->NativeToManagedBufferOffset) % 8 != 0) {
					throw new DataMisalignedException("nativeToManagedBuffer is not properly aligned!");
				}
			}

			if (is64Bit)
				LogString("Using 64-bit hook.");
			LogString("Starting process, waiting for profiler hook...");

			profilee = new Process();

			profilee.EnableRaisingEvents = true;
			profilee.StartInfo = psi;
			profilee.Exited += new EventHandler(ProfileeExited);
			
			enableDC = profilerOptions.EnableDCAtStart;
			isFirstDC = true;
			
			Debug.WriteLine("Launching profiler for " + psi.FileName + "...");
			profilee.Start();
			
			logger.Start(nativeToManagedBuffer.CreateReadingStream());

			// GC references currentSession
			if (profilerOptions.EnableDC) {
				dataCollector.Start();
			}

			OnSessionStarted(EventArgs.Empty);
			return profilee;
		}
 /// <summary>
 /// Constructs a NativeCircularBufferWritingStream
 /// </summary>
 public WritingStream(UnmanagedCircularBuffer circularBuffer)
     : base(circularBuffer)
 {
     this.WriteTimeout = Timeout.Infinite;
 }
 /// <summary>
 /// Constructs a UnmanagedCircularBufferReadingStream
 /// </summary>
 public ReadingStream(UnmanagedCircularBuffer circularBuffer)
     : base(circularBuffer)
 {
     this.ReadTimeout = Timeout.Infinite;
 }
 public BaseStream(UnmanagedCircularBuffer circularBuffer)
 {
     this.circularBuffer = circularBuffer;
     this.header         = circularBuffer.header;
 }