Пример #1
0
        /// <summary>
        /// Start the target process
        /// </summary>
        /// <param name="process"></param>
        /// <param name="servicePrincipal"></param>
        public void RunProcess(Action <Action <StringDictionary> > process, string[] servicePrincipal)
        {
            var    key        = Guid.NewGuid().GetHashCode().ToString("X");
            string @namespace = servicePrincipal.Any() ? "Global" : "Local";

            _memoryManager.Initialise(@namespace, key, servicePrincipal);
            _messageQueue = new ConcurrentQueue <byte[]>();

            using (_mcb = new MemoryManager.ManagedCommunicationBlock(@namespace, key, MaxMsgSize, -1, servicePrincipal)
                   )
                using (var processMgmt = new AutoResetEvent(false))
                    using (var queueMgmt = new AutoResetEvent(false))
                        using (var environmentKeyRead = new AutoResetEvent(false))
                        {
                            var handles = new List <WaitHandle> {
                                processMgmt, _mcb.ProfilerRequestsInformation
                            };

                            ThreadPool.QueueUserWorkItem(
                                SetProfilerAttributes(process, key, @namespace, environmentKeyRead, processMgmt));
                            ThreadPool.QueueUserWorkItem(SaveVisitData(queueMgmt));

                            // wait for the environment key to be read
                            if (WaitHandle.WaitAny(new WaitHandle[] { environmentKeyRead }, new TimeSpan(0, 0, 0, 10)) != -1)
                            {
                                ProcessMessages(handles.ToArray());
                                queueMgmt.WaitOne();
                            }
                        }
        }
Пример #2
0
        public void RunProcess(Action<Action<StringDictionary>> process, string[] servicePrincipal)
        {
            var key = Guid.NewGuid().GetHashCode().ToString("X");
            string @namespace = servicePrincipal.Any() ? "Global" : "Local";

            _memoryManager.Initialise(@namespace, key, servicePrincipal);
            _messageQueue = new ConcurrentQueue<byte[]>();

            using (_mcb = new MemoryManager.ManagedCommunicationBlock(@namespace, key, MaxMsgSize, -1, servicePrincipal))
            using (var processMgmt = new AutoResetEvent(false))
            using (var queueMgmt = new AutoResetEvent(false))
            using (var environmentKeyRead = new AutoResetEvent(false))
            {
                var handles = new List<WaitHandle> { processMgmt, _mcb.ProfilerRequestsInformation };

                ThreadPool.QueueUserWorkItem(
                    SetProfilerAttributes(process, key, @namespace, environmentKeyRead, processMgmt));
                ThreadPool.QueueUserWorkItem(SaveVisitData(queueMgmt));

                // wait for the environment key to be read
                if (WaitHandle.WaitAny(new WaitHandle[] {environmentKeyRead}, new TimeSpan(0, 0, 0, 10)) != -1)
                {
                    ProcessMessages(handles.ToArray());
                    queueMgmt.WaitOne();
                }
            }
        }
Пример #3
0
        public void RunProcess(Action <Action <StringDictionary> > process, bool isService)
        {
            var key                = Guid.NewGuid().GetHashCode().ToString("X");
            var processMgmt        = new AutoResetEvent(false);
            var queueMgmt          = new AutoResetEvent(false);
            var environmentKeyRead = new AutoResetEvent(false);
            var handles            = new List <WaitHandle> {
                processMgmt
            };

            string @namespace = isService ? "Global" : "Local";

            _memoryManager.Initialise(@namespace, key);

            _messageQueue = new ConcurrentQueue <byte[]>();

            using (_mcb = new MemoryManager.ManagedCommunicationBlock(@namespace, key, maxMsgSize, -1))
            {
                handles.Add(_mcb.ProfilerRequestsInformation);

                ThreadPool.QueueUserWorkItem((state) =>
                {
                    try
                    {
                        process(dictionary =>
                        {
                            if (dictionary == null)
                            {
                                return;
                            }
                            dictionary[@"OpenCover_Profiler_Key"]       = key;
                            dictionary[@"OpenCover_Profiler_Namespace"] = @namespace;
                            dictionary[@"OpenCover_Profiler_Threshold"] = _commandLine.Threshold.ToString(CultureInfo.InvariantCulture);

                            if (_commandLine.TraceByTest)
                            {
                                dictionary[@"OpenCover_Profiler_TraceByTest"] = "1";
                            }

                            dictionary["Cor_Profiler"]             = "{1542C21D-80C3-45E6-A56C-A9C1E4BEB7B8}";
                            dictionary["Cor_Enable_Profiling"]     = "1";
                            dictionary["CoreClr_Profiler"]         = "{1542C21D-80C3-45E6-A56C-A9C1E4BEB7B8}";
                            dictionary["CoreClr_Enable_Profiling"] = "1";

                            if (_commandLine.Registration == Registration.Path32)
                            {
                                dictionary["Cor_Profiler_Path"] = ProfilerRegistration.GetProfilerPath(false);
                            }
                            if (_commandLine.Registration == Registration.Path64)
                            {
                                dictionary["Cor_Profiler_Path"] = ProfilerRegistration.GetProfilerPath(true);
                            }

                            environmentKeyRead.Set();
                        });
                    }
                    finally
                    {
                        processMgmt.Set();
                    }
                });

                ThreadPool.QueueUserWorkItem((state) =>
                {
                    while (true)
                    {
                        //// use this block to introduce a delay in to the queue processing
                        //if (_messageQueue.Count < 100)
                        //  Thread.Sleep(10);

                        byte[] data;
                        while (!_messageQueue.TryDequeue(out data))
                        {
                            Thread.Yield();
                        }

                        _perfCounters.CurrentMemoryQueueSize = _messageQueue.Count;
                        _perfCounters.IncrementBlocksReceived();

                        if (data.Length == 0)
                        {
                            _communicationManager.Complete();
                            queueMgmt.Set();
                            return;
                        }
                        _persistance.SaveVisitData(data);
                    }
                });

                // wait for the environment key to be read
                if (WaitHandle.WaitAny(new WaitHandle[] { environmentKeyRead }, new TimeSpan(0, 0, 0, 10)) != -1)
                {
                    ProcessMessages(handles);
                    queueMgmt.WaitOne();
                }
            }
        }
Пример #4
0
        public void RunProcess(Action<Action<StringDictionary>> process, bool isService)
        {
            var key = Guid.NewGuid().GetHashCode().ToString("X");
            var processMgmt = new AutoResetEvent(false);
            var queueMgmt = new AutoResetEvent(false);
            var environmentKeyRead = new AutoResetEvent(false);
            var handles = new List<WaitHandle> { processMgmt };

            string @namespace = isService ? "Global" : "Local";

            _memoryManager.Initialise(@namespace, key);

            _messageQueue = new ConcurrentQueue<byte[]>();

            using (_mcb = new MemoryManager.ManagedCommunicationBlock(@namespace, key, maxMsgSize, -1))
            {
                handles.Add(_mcb.ProfilerRequestsInformation);

                ThreadPool.QueueUserWorkItem((state) =>
                {
                    try
                    {
                        process(dictionary =>
                        {
                            if (dictionary == null) return;
                            dictionary[@"OpenCover_Profiler_Key"] = key;
                            dictionary[@"OpenCover_Profiler_Namespace"] = @namespace;
                            dictionary[@"OpenCover_Profiler_Threshold"] = _commandLine.Threshold.ToString(CultureInfo.InvariantCulture);

                            if (_commandLine.TraceByTest)
                                dictionary[@"OpenCover_Profiler_TraceByTest"] = "1";

                            dictionary["Cor_Profiler"] = "{1542C21D-80C3-45E6-A56C-A9C1E4BEB7B8}";
                            dictionary["Cor_Enable_Profiling"] = "1";
                            dictionary["CoreClr_Profiler"] = "{1542C21D-80C3-45E6-A56C-A9C1E4BEB7B8}";
                            dictionary["CoreClr_Enable_Profiling"] = "1";
                            environmentKeyRead.Set();
                        });
                    }
                    finally
                    {
                        processMgmt.Set();
                    }
                });

                ThreadPool.QueueUserWorkItem((state) =>
                {
                    while (true)
                    {
                        //// use this block to introduce a delay in to the queue processing
                        //if (_messageQueue.Count < 100)
                        //  Thread.Sleep(10);

                        byte[] data;
                        while (!_messageQueue.TryDequeue(out data))
                            Thread.Yield();

                        _perfCounters.CurrentMemoryQueueSize = _messageQueue.Count;
                        _perfCounters.IncrementBlocksReceived();

                        if (data.Length == 0)
                        {
                            _communicationManager.Complete();
                            queueMgmt.Set();
                            return;
                        }
                        _persistance.SaveVisitData(data);
                    }
                });

                // wait for the environment key to be read
                if (WaitHandle.WaitAny(new WaitHandle[] {environmentKeyRead}, new TimeSpan(0, 0, 0, 10)) != -1)
                {
                    ProcessMessages(handles);
                    queueMgmt.WaitOne();
                }
            }
        }