示例#1
0
 private static void WriteResultToFile(HypervisorManager manager, string filename)
 {
     try
     {
         File.WriteAllText(filename, manager.GetJsonResultString());
     }
     catch (Exception e)
     {
         Console.WriteLine($"Error writing profiling result to file {filename}: ", e);
     }
 }
示例#2
0
        public static void Profile(int numTestRuns, int numHypervisors = 250, int numVms = 1000, bool writeResultToFile = false)
        {
            double avgTimeAll = 0;
            double avgDevAll  = 0;

            Console.WriteLine($"Starting {numTestRuns} test runs with {numVms} VMs and {numHypervisors} Hypervisors.");

            HypervisorManager hvManager = null;

            for (int tr = 0; tr < numTestRuns; tr++)
            {
                var hypervisors = GenerateHypervisors(numHypervisors);
                var vms         = GenerateVms(numVms);

                hvManager = new HypervisorManager(hypervisors);

                double avgTime = 0;
                int    i       = 0;

                Console.Write($"\rRun {tr+1} ({((tr+1) * 100) / numTestRuns}%)    ");

                Stopwatch stopwatch = new Stopwatch();

                foreach (var vm in vms)
                {
                    stopwatch.Reset();
                    stopwatch.Start();
                    hvManager.AddVm(vm);
                    stopwatch.Stop();

                    var ts = stopwatch.Elapsed;
                    avgTime += ts.TotalMilliseconds;
                    i++;
                }

                avgTimeAll += (avgTime / i);
                avgDevAll  += hvManager.GetAverageDeviation();
            }

            Console.WriteLine("");
            Console.WriteLine($"Average time per Vm: {avgTimeAll / numTestRuns}ms Average deviation: {avgDevAll / numTestRuns}%");

            if (writeResultToFile)
            {
                var filename = Path.Combine("./", RESULT_FILENAME);
                Console.WriteLine($"Writing result of last test run to file {filename}");

                if (hvManager != null)
                {
                    WriteResultToFile(hvManager, filename);
                }
            }
        }
        static void Main(string[] args)
        {
            // Get default path and filenames from the .config file
            _path = ConfigurationManager.AppSettings[CONF_KEY_DEFAULTPATH] ?? "./";
            string filenameHypervisor = ConfigurationManager.AppSettings[CONF_KEY_FILENAME_HYPERVISOR] ?? "hypervisor.json";
            string filenameVms        = ConfigurationManager.AppSettings[CONF_KEY_FILENAME_VMS] ?? "vms.json";

            // Read the configuration settings for the profiling mode.
            ReadProfilerConfiguration();

            if (_isProfilingActive)
            {
                Profiler.Profile(_numProfilingRuns, _numProfilingHypervisors, _numProfilingVms, _saveProfilingResults);
                return;
            }

            // Process Command-Line arguments
            if (!ProcessArgs(args))
            {
                return;
            }

            // Import the VMs and Hypervisors from the json files
            List <Hypervisor> hypervisors = ReadHypervisors(Path.Combine(_path, filenameHypervisor));

            if (hypervisors == null)
            {
                return;
            }

            List <Vm> vms = ReadVms(Path.Combine(_path, filenameVms));

            if (vms == null)
            {
                return;
            }

            var hvManager = new HypervisorManager(hypervisors);

            // Distribute the Vms one after another to the Hypervisors.
            // If intermediate Results should be logged to the Console, move the 'Console.WriteLine' statement into the foreach-block.
            foreach (var vm in vms)
            {
                hvManager.AddVm(vm);
            }

            Console.WriteLine("\r\nResult:");
            // Log the result to the Console.
            Console.WriteLine(hvManager.GetJsonResultString());
        }