Ejemplo n.º 1
0
        private static string PickDrive(long freeSpace)
        {
            var i = 0;
            var k = 0;

            var drives       = RamDiskUtil.GetEligibleDrives();
            var driveIndexes = new int[drives.Length];

            foreach (var d in drives)
            {
                var flag = false;

                if (d.TotalFreeSpace < freeSpace)
                {
                    flag = true;
                }
                else
                {
                    driveIndexes[i] = k;
                    i++;
                }

                Console.WriteLine(
                    "[{0}] {1} {2:0.00} Gb free {3}",
                    flag ? " " : i.ToString(),
                    d.Name,
                    (double)d.TotalFreeSpace / 1024 / 1024 / 1024,
                    flag ? "- insufficient free space" : ""
                    );

                k++;
            }

            Console.Write("- please pick drive to test: ");

            int index;

            do
            {
                if (Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.Escape)
                {
                    return(null);
                }

                var input = Console.ReadLine();

                if (!Int32.TryParse(input, out index))
                {
                    index = -1;
                }
            } while ((index < 1) || (index > i));

            return(drives[driveIndexes[--index]].Name);
        }
Ejemplo n.º 2
0
        List <BenchmarkPartialResult> DoInternalBenchmark()
        {
            List <BenchmarkPartialResult> result = new List <BenchmarkPartialResult>();

            base.WriteMessage("STORAGE SPEED TEST\n");

            //Console.ForegroundColor = ConsoleColor.DarkGray;
            //base.WriteMessage("Total RAM: {0:0.00}Gb, Available RAM: {1:0.00}Gb\n", (double)RamDiskUtil.TotalRam / 1024 / 1024 / 1024, (double)RamDiskUtil.FreeRam / 1024 / 1024 / 1024);
            WriteLineWordWrap("The test uses standrd OS's file API (WinAPI on Windows and POSIX on Mac/Linux) to measure the speed of transfers between storage device and system memory.\nWrite buffering and mem cahce are disabled\n");
            //Console.ResetColor();

            const long fileSize = 1024 * 1024 * 1024;

            //var drivePath = PickDrive(fileSize);

            //if (drivePath == null) return result;

            var drivers = RamDiskUtil.GetEligibleDrives();

            foreach (var driver in drivers)
            {
                try
                {
                    if (driver.TotalFreeSpace < fileSize)
                    {
                        base.WriteMessage($"CANNOT BENCHMARK LOCAL STORAGE SPEED FOR DRIVER [{driver.Name}] - Not enough space");
                    }
                    else
                    {
                        var testSuite = new BigTest(driver.Name, fileSize, false);
                        result.AddRange(DoDiskBenchmark(testSuite, driver.Name));
                    }
                }
                catch (Exception ex)
                {
                    string message = $"Error while test disk [{driver.Name}]";
                    base.WriteMessage(message + ex.ToString());
                }
            }

            return(result);
        }
Ejemplo n.º 3
0
        private void InitDrives()
        {
            Action <DriveDetailed, int> setAvailableAndIndex = (DriveDetailed d, int i) =>
            {
                const int extraSpace = 512 * 1024 * 1024;
                d.AvailableForTest = d.BytesFree > FileSize + extraSpace;
                d.DisplayIndex     = d.BytesFree > FileSize + extraSpace ? (i < 9 ? (i + 1).ToString()[0] : '.') : ' ';
            };

            try
            {
                if (Device.RuntimePlatform == Device.Android)
                {
                    androidDrives = DependencyService.Get <IAndroidDrives>()?.GetDrives();

                    var  i        = 0;
                    long prevSize = -1;

                    foreach (var ad in androidDrives)
                    {
                        setAvailableAndIndex(ad, i);
                        i++;
                        if (ad.BytesFree == prevSize)
                        {
                            ad.ShowDiveIsSameMessage = true;
                        }
                        prevSize = ad.BytesFree;
                    }
                }
                else
                {
                    var drives = new List <DriveDetailed>();

                    var i = 0;

                    foreach (var d in RamDiskUtil.GetEligibleDrives())
                    {
                        var dd = new DriveDetailed();

                        dd.Name = d.Name;

                        long size = -1;

                        try
                        {
                            size = d.TotalFreeSpace; // requesting disk size might throw access exceptions
                        }
                        catch { }


                        dd.BytesFree = size;

                        setAvailableAndIndex(dd, i);
                        i++;

                        drives.Add(dd);

                        this.drives = drives;
                    }
                }
            }
            catch (Exception ex)
            {
                ViewModelContainer.ErrorViewModel.DoShow(ex);
            }
        }
        private void InitDrives()
        {
            Action <DriveDetailed, int> setEnoughSpaceAndIndex = (DriveDetailed d, int i) =>
            {
                const int extraSpace = 512 * 1024 * 1024;
                d.EnoughSpace  = d.BytesFree > FileSize + extraSpace;
                d.DisplayIndex = d.BytesFree > FileSize + extraSpace ? (i < 9 ? (i + 1).ToString()[0] : '.') : ' ';

                if (!d.EnoughSpace)
                {
                    AtLeastOneDriveWithNotEnoughSpace = true;
                }
            };

            try
            {
                availbleDrivesCount = 0;
                AtLeastOneDriveWithNotEnoughSpace = false;
                var i = 0;
                firstAvailableDrive = null;

                if (Device.RuntimePlatform == Device.Android || Device.RuntimePlatform == Device.iOS)
                {
                    platformDrives = DependencyService.Get <IPlatformDrives>()?.GetDrives();

                    string prevDrive = "";

                    const string d1 = "/data/user";
                    const string d2 = "/storage/emulated/0";

                    foreach (var ad in platformDrives)
                    {
                        setEnoughSpaceAndIndex(ad, i);

                        if (ad.AvailableForTest)
                        {
                            availbleDrivesCount++;
                            if (firstAvailableDrive == null)
                            {
                                firstAvailableDrive = ad.Name;
                            }
                        }

                        i++;

                        if ((prevDrive.Contains(d1) && ad.Name.Contains(d2)) || (prevDrive.Contains(d2) && ad.Name.Contains(d1)))
                        {
                            ad.ShowDiveIsSameMessage = true;
                        }

                        prevDrive = ad.Name;
                    }
                }
                else
                {
                    var drives = new List <DriveDetailed>();

                    foreach (var d in RamDiskUtil.GetEligibleDrives())
                    {
                        var dd = new DriveDetailed();

                        dd.Name = d.Name;

                        long size = -1;
                        long free = -1;

                        try
                        {
                            free = d.TotalFreeSpace; // requesting disk size might throw access exceptions
                            size = d.TotalSize;
                        }
                        catch { dd.Accessible = false; }


                        dd.BytesFree  = free;
                        dd.TotalBytes = size;

                        setEnoughSpaceAndIndex(dd, i);

                        if (dd.AvailableForTest)
                        {
                            availbleDrivesCount++;
                            if (firstAvailableDrive == null)
                            {
                                firstAvailableDrive = dd.Name;
                            }
                        }

                        i++;

                        drives.Add(dd);

                        this.posixDrives = drives;
                    }
                }
            }
            catch (Exception ex)
            {
                ViewModelContainer.ErrorViewModel.DoShow(ViewModelContainer.L11n.InitDrivesError, ex);
            }
        }