public void PumpLargeDataSetThroughTinyBuffer()
 {
     using (UnmanagedCircularBuffer ncb = UnmanagedCircularBuffer.Create(memoryStart, UnmanagedCircularBuffer.SynchronizationOverheadSize + 3)) {
         byte[] data  = new byte[10000];
         byte[] data2 = new byte[10000];
         for (int i = 0; i < data.Length; i++)
         {
             data[i] = unchecked ((byte)(i + 1));
         }
         DoParallel(
             delegate {
             using (Stream w = ncb.CreateWritingStream()) {
                 w.Write(data, 0, data.Length);
             }
         },
             delegate {
             using (Stream r = ncb.CreateReadingStream()) {
                 int count = 0;
                 while (count < data2.Length)
                 {
                     count += r.Read(data2, count, data2.Length - count);
                 }
             }
         });
         Assert.AreEqual(data, data2);
     }
 }
 public void ReadFromEmptyBufferCausesTimeout()
 {
     using (UnmanagedCircularBuffer ncb = UnmanagedCircularBuffer.Create(memoryStart, memoryLength)) {
         using (Stream s = ncb.CreateReadingStream()) {
             s.ReadTimeout = 100;
             s.ReadByte();
         }
     }
 }
 public void WriteAndReadFromBuffer()
 {
     using (UnmanagedCircularBuffer ncb = UnmanagedCircularBuffer.Create(memoryStart, memoryLength)) {
         using (Stream ws = ncb.CreateWritingStream()) {
             using (Stream rs = ncb.CreateReadingStream()) {
                 ws.WriteByte(0x42);
                 Assert.AreEqual(0x42, rs.ReadByte());
             }
         }
     }
 }
 public void WriteToFullBufferCausesTimeout()
 {
     using (UnmanagedCircularBuffer ncb = UnmanagedCircularBuffer.Create(memoryStart, UnmanagedCircularBuffer.SynchronizationOverheadSize + 3)) {
         using (Stream s = ncb.CreateWritingStream()) {
             s.WriteTimeout = 100;
             try {
                 s.WriteByte(1);
                 s.WriteByte(2);
             } catch (TimeoutException) {
                 Assert.Fail("The first two calls should work");
             }
             s.WriteByte(3);
         }
     }
 }
        public void WriteAndReadFromBufferUsingMemoryMappedFile()
        {
            using (MemoryMappedFile mmf1 = MemoryMappedFile.CreateSharedMemory("Local\\TestMemory", 1024)) {
                using (UnmanagedMemory view1 = mmf1.MapView(0, 1024)) {
                    using (UnmanagedCircularBuffer ncb = UnmanagedCircularBuffer.Create(view1.Start, (int)view1.Length)) {
                        using (Stream ws = ncb.CreateWritingStream()) {
                            ws.WriteByte(0x42);
                        }

                        using (MemoryMappedFile mmf2 = MemoryMappedFile.Open("Local\\TestMemory")) {
                            using (UnmanagedMemory view2 = mmf1.MapView(0, 1024)) {
                                Assert.AreNotEqual(view1.Start, view2.Start);
                                using (UnmanagedCircularBuffer ncb2 = UnmanagedCircularBuffer.Open(view2.Start)) {
                                    using (Stream rs = ncb2.CreateReadingStream()) {
                                        Assert.AreEqual(0x42, rs.ReadByte());
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
예제 #6
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...");

            this.profilee = new Process();

            this.profilee.EnableRaisingEvents = true;
            this.profilee.StartInfo           = this.psi;
            this.profilee.Exited += new EventHandler(ProfileeExited);

            this.enableDC  = this.profilerOptions.EnableDCAtStart;
            this.isFirstDC = true;

            Debug.WriteLine("Launching profiler for " + this.psi.FileName + "...");
            this.profilee.Start();

            this.logger.Start(nativeToManagedBuffer.CreateReadingStream());

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

            OnSessionStarted(EventArgs.Empty);
            return(profilee);
        }