Example #1
0
        public static string OnDiskMerge(string covFilesdir, string[] covFiles)
        {
            var resultedFile = Path.Combine(Path.GetDirectoryName(covFilesdir), "OnDisk-" + covFiles.Length + "-" + Guid.NewGuid().ToString().Substring(0, 5) + ".coverage");

            if (covFiles.Length < 2)
            {
                Console.WriteLine("To merge give atleast two cov files");
                return("");
            }
            string first = covFiles[0], second = covFiles[1];

            for (int i = 1; i < covFiles.Length; i++)
            {
                var tmpFile = Path.Combine(Path.GetDirectoryName(resultedFile), Path.GetFileNameWithoutExtension(resultedFile) + "-" + i + Path.GetExtension(resultedFile));
                if (i == covFiles.Length - 1)
                {
                    tmpFile = resultedFile;
                }
                Console.WriteLine("Creating merge file: " + tmpFile);
                CoverageInfo.MergeCoverageFiles(first, second, tmpFile, true);
                first = tmpFile;
                if (i != covFiles.Length - 1)
                {
                    second = covFiles[i + 1];
                }
            }
            CoverageSummary.PrintCoverageInfo(resultedFile);
            return(resultedFile);
        }
Example #2
0
        public static string OnDiskMergeInParallel(string covFilesdir, string[] covFiles)
        {
            ConcurrentQueue <string> covFilesQueue = new ConcurrentQueue <string>(covFiles);
            var resultedFile  = Path.Combine(Path.GetDirectoryName(covFilesdir), "OnDisk-" + covFiles.Length + "-result-" + Guid.NewGuid().ToString().Substring(0, 5) + ".coverage");
            var parallelLevel = GetNumOfCores();

            Task[] tasks = new Task[parallelLevel];
            for (int i = 0; i < parallelLevel; i++)
            {
                Console.WriteLine("Creating task: " + i);
                tasks[i] = Task.Run(() => OnDiskWork(covFilesQueue, covFilesdir, covFiles.Length));
            }
            Task.WaitAll(tasks);
            if (covFilesQueue.Count > 1)
            {
                Console.WriteLine("Number remaining files in queue:" + covFilesQueue.Count);
                OnDiskWork(covFilesQueue, covFilesdir, covFiles.Length);
            }

            Debug.Assert(covFilesQueue.Count == 1, "Only one cov file should be there");
            string finalFile;

            covFilesQueue.TryDequeue(out finalFile);
            File.Move(finalFile, resultedFile);
            CoverageSummary.PrintCoverageInfo(resultedFile);
            return(resultedFile);
        }
Example #3
0
        public static string InMemoryMerge(string covFilesdir, string[] covFiles, bool parallel)
        {
            CoverageInfo _covinfo = null;

            if (!parallel)
            {
                _covinfo = CoverageInfo.CreateFromFile(covFiles[0], null, null);
                int batchmergefiles = covFiles.Length - 1;
                for (int i = 0; i < batchmergefiles; i++)
                {
                    Console.WriteLine("Merging file " + covFiles[i + 1]);
                    CoverageInfo covinfo2 = CoverageInfo.CreateFromFile(covFiles[i + 1], null, null);
                    CoverageInfo cs3      = CoverageInfo.Join(_covinfo, covinfo2);
                    _covinfo.Dispose();
                    covinfo2.Dispose();
                    _covinfo = cs3;
                }
            }
            else
            {
                _covinfo = InMemoryParallel(covFiles);
            }
            CoverageSummary.PrintCoverageInfo(_covinfo);
            var resultedFile = Path.Combine(Path.GetDirectoryName(covFilesdir), "InMem-" + covFiles.Length + "-" + Guid.NewGuid().ToString().Substring(0, 5) + "-is-paralel-" + parallel);

            return(resultedFile);
        }