예제 #1
0
        private void SetProfilerAttributesOnDictionary(string profilerKey, string profilerNamespace, StringDictionary dictionary)
        {
            dictionary[@"OpenCover_Profiler_Key"]       = profilerKey;
            dictionary[@"OpenCover_Profiler_Namespace"] = profilerNamespace;
            dictionary[@"OpenCover_Profiler_Threshold"] = _commandLine.Threshold.ToString(CultureInfo.InvariantCulture);

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

            dictionary["Cor_Profiler"]             = ProfilerGuid;
            dictionary["Cor_Enable_Profiling"]     = "1";
            dictionary["CoreClr_Profiler"]         = ProfilerGuid;
            dictionary["CoreClr_Enable_Profiling"] = "1";

            switch (_commandLine.Registration)
            {
            case Registration.Path32:
                string profilerPath32 = ProfilerRegistration.GetProfilerPath(false);
                dictionary["Cor_Profiler_Path"]    = profilerPath32;
                dictionary["CorClr_Profiler_Path"] = profilerPath32;
                break;

            case Registration.Path64:
                string profilerPath64 = ProfilerRegistration.GetProfilerPath(true);
                dictionary["Cor_Profiler_Path"]    = profilerPath64;
                dictionary["CorClr_Profiler_Path"] = profilerPath64;
                break;
            }
        }
예제 #2
0
        private void SetProfilerAttributesOnDictionary(string profilerKey, string profilerNamespace,
                                                       StringDictionary dictionary)
        {
            dictionary[@"OpenCover_Profiler_Key"]       = profilerKey;
            dictionary[@"OpenCover_Profiler_Namespace"] = profilerNamespace;
            dictionary[@"OpenCover_Profiler_Threshold"] = _commandLine.Threshold.ToString(CultureInfo.InvariantCulture);

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

            dictionary["Cor_Profiler"]             = ProfilerGuid;
            dictionary["Cor_Enable_Profiling"]     = "1";
            dictionary["CoreClr_Profiler"]         = ProfilerGuid;
            dictionary["CoreClr_Enable_Profiling"] = "1";
            dictionary["Cor_Profiler_Path"]        = string.Empty;
            dictionary["CorClr_Profiler_Path"]     = string.Empty;

            if (_commandLine.CommunicationTimeout > 0)
            {
                dictionary["OpenCover_Profiler_ShortWait"] = _commandLine.CommunicationTimeout.ToString();
            }

            var profilerPath = ProfilerRegistration.GetProfilerPath(_commandLine.Registration);

            if (profilerPath != null)
            {
                dictionary["Cor_Profiler_Path"]    = profilerPath;
                dictionary["CorClr_Profiler_Path"] = profilerPath;
            }

            // new versions of clr and coreclr don't need us to "guess" the profiler bitness : we might as well include these
            dictionary["Cor_Profiler_Path_32"]     = ProfilerRegistration.GetProfilerPath(Registration.Path32);
            dictionary["Cor_Profiler_Path_64"]     = ProfilerRegistration.GetProfilerPath(Registration.Path64);
            dictionary["CoreClr_Profiler_Path_32"] = ProfilerRegistration.GetProfilerPath(Registration.Path32);
            dictionary["CoreClr_Profiler_Path_64"] = ProfilerRegistration.GetProfilerPath(Registration.Path64);

            dictionary["OpenCover_SendVisitPointsTimerInterval"] = _commandLine.SendVisitPointsTimerInterval.ToString();
        }
예제 #3
0
        private void SetProfilerAttributesOnDictionary(string profilerKey, string profilerNamespace,
                                                       StringDictionary dictionary)
        {
            dictionary[@"OpenCover_Profiler_Key"]       = profilerKey;
            dictionary[@"OpenCover_Profiler_Namespace"] = profilerNamespace;
            dictionary[@"OpenCover_Profiler_Threshold"] = _commandLine.Threshold.ToString(CultureInfo.InvariantCulture);

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

            dictionary["Cor_Profiler"]             = ProfilerGuid;
            dictionary["Cor_Enable_Profiling"]     = "1";
            dictionary["CoreClr_Profiler"]         = ProfilerGuid;
            dictionary["CoreClr_Enable_Profiling"] = "1";
            dictionary["Cor_Profiler_Path"]        = string.Empty;
            dictionary["CorClr_Profiler_Path"]     = string.Empty;

            if (_commandLine.CommunicationTimeout > 0)
            {
                dictionary["OpenCover_Profiler_ShortWait"] = _commandLine.CommunicationTimeout.ToString();
            }

            var profilerPath = ProfilerRegistration.GetProfilerPath(_commandLine.Registration);

            if (profilerPath != null)
            {
                dictionary["Cor_Profiler_Path"]    = profilerPath;
                dictionary["CorClr_Profiler_Path"] = profilerPath;
            }
            dictionary["OpenCover_SendVisitPointsTimerInterval"] = _commandLine.SendVisitPointsTimerInterval.ToString();
        }
예제 #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";

                            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();
                }
            }
        }