Skip to content

Commit 10ed0ec

Browse files
authored
[xaprepare] Add Disk information to output (#6711)
Sometimes a CI build will fail due to insufficient disk space: System.IO.IOException: No space left on device at System.IO.FileStream.WriteNative(ReadOnlySpan`1 source) at System.IO.FileStream.FlushWriteBuffer() … What we *don't* know is how much free space there was in the first place, or how much space we've consumed during the build. Update `xaprepare` to print out the current disk space usage at the beginning of the build. This output will be visible from the **make jenkins** step output. macOS will print out `df -h` output: =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Detecting operating system =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= OS type: Darwin OS flavor: macOS OS name: Mac OS X OS release: 10.15.7 (19H2) OS bits: x86_64 CPU count: 12 Disk Info: Filesystem Size Used Avail Capacity iused ifree %iused Mounted on /dev/disk1s1 466Gi 10Gi 267Gi 4% 488254 4881964626 0% / devfs 186Ki 186Ki 0Bi 100% 642 0 100% /dev /dev/disk1s6 466Gi 178Gi 267Gi 40% 2099549 4880353331 0% /System/Volumes/Data /dev/disk1s4 466Gi 2.0Gi 267Gi 1% 2 4882452878 0% /private/var/vm /dev/disk1s5 9.3Gi 7.8Gi 1.5Gi 84% 346 97655934 0% /Volumes/BotDeploy map auto_home 0Bi 0Bi 0Bi 100% 0 0 100% /System/Volumes/Data/home /dev/disk1s3 466Gi 504Mi 267Gi 1% 50 4882452830 0% /Volumes/Recovery Linux will print out `df -h` output: =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Detecting operating system =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= OS type: Linux OS flavor: Debian OS name: Ubuntu OS release: 20.04 OS bits: x86_64 CPU count: 8 Disk Info: Filesystem Size Used Avail Use% Mounted on /dev/root 84G 55G 29G 66% / devtmpfs 16G 0 16G 0% /dev tmpfs 16G 12K 16G 1% /dev/shm tmpfs 3.2G 1.1M 3.2G 1% /run tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 16G 0 16G 0% /sys/fs/cgroup /dev/loop0 62M 62M 0 100% /snap/core20/1328 /dev/sda15 105M 5.2M 100M 5% /boot/efi /dev/loop2 68M 68M 0 100% /snap/lxd/21835 /dev/loop1 44M 44M 0 100% /snap/snapd/14549 Windows will use the values from [`System.IO.DriveInfo`][0]: =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Detecting operating system =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Visual Studio detected in C:\Program Files\Microsoft Visual Studio\2022\Enterprise MSBuild detected at C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\MSBuild.exe OS type: Windows OS flavor: Windows 10 OS name: Microsoft Windows 10 [Version 10.0.20348] OS release: 10.0.20348 OS bits: x86 CPU count: 8 Disk Info: Drive TotalSize AvailableFreeSpace C:\ 256GB 105GB [0]: https://docs.microsoft.com/en-us/dotnet/api/system.io.driveinfo?view=net-6.0
1 parent 9f038d8 commit 10ed0ec

File tree

5 files changed

+33
-6
lines changed

5 files changed

+33
-6
lines changed

build-tools/xaprepare/xaprepare/Application/Context.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -763,12 +763,14 @@ public async Task<bool> Init (string? scenarioName = null)
763763
InitOS ();
764764

765765
Log.StatusLine ();
766-
Log.StatusLine (" OS type: ", OS.Type, tailColor: Log.InfoColor);
767-
Log.StatusLine (" OS flavor: ", OS.Flavor, tailColor: Log.InfoColor);
768-
Log.StatusLine (" OS name: ", OS.Name, tailColor: Log.InfoColor);
769-
Log.StatusLine ("OS release: ", OS.Release, tailColor: Log.InfoColor);
770-
Log.StatusLine (" OS bits: ", OS.Architecture, tailColor: Log.InfoColor);
771-
Log.StatusLine (" CPU count: ", OS.CPUCount.ToString (), tailColor: Log.InfoColor);
766+
Log.StatusLine (" OS type: ", OS.Type, tailColor: Log.InfoColor);
767+
Log.StatusLine (" OS flavor: ", OS.Flavor, tailColor: Log.InfoColor);
768+
Log.StatusLine (" OS name: ", OS.Name, tailColor: Log.InfoColor);
769+
Log.StatusLine (" OS release: ", OS.Release, tailColor: Log.InfoColor);
770+
Log.StatusLine (" OS bits: ", OS.Architecture, tailColor: Log.InfoColor);
771+
Log.StatusLine (" CPU count: ", OS.CPUCount.ToString (), tailColor: Log.InfoColor);
772+
Log.StatusLine (" Disk Info: ", string.Empty, tailColor: Log.InfoColor);
773+
Log.StatusLine (string.Empty, OS.DiskInformation, tailColor: Log.InfoColor);
772774
Log.StatusLine ();
773775

774776
if (EnableAllTargets) {
@@ -784,6 +786,8 @@ public async Task<bool> Init (string? scenarioName = null)
784786
return false;
785787
}
786788

789+
Log.StatusLine ();
790+
787791
Tools.Init (this);
788792

789793
if (SelectedScenario.NeedsGitSubmodules) {

build-tools/xaprepare/xaprepare/Application/Utilities.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,12 @@ public static void FormatSize (ulong dSize, out decimal value, out string unit)
446446
value = SignificantDigits (value, 3);
447447
}
448448

449+
public static string SizeToString (long dSize)
450+
{
451+
Utilities.FormatSize ((ulong)dSize, out decimal value, out string unit);
452+
return $"{value}{unit}";
453+
}
454+
449455
// Creates numbers with maxDigitCount significant digits or less
450456
static decimal SignificantDigits (decimal number, int maxDigitCount)
451457
{

build-tools/xaprepare/xaprepare/OperatingSystems/OS.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ abstract class OS : AppObject
3636
/// </summary>
3737
public uint CPUCount => (uint)Environment.ProcessorCount;
3838

39+
public string DiskInformation { get; protected set; } = string.Empty;
40+
3941
/// <summary>
4042
/// A dictionary of variables to export in environment of all the executed programs, scripts etc.
4143
/// </summary>

build-tools/xaprepare/xaprepare/OperatingSystems/Unix.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ abstract partial class Unix : OS
1818
protected Unix (Context context) : base (context)
1919
{
2020
Architecture = Utilities.GetStringFromStdout ("uname", "-m").Trim ();
21+
DiskInformation = Utilities.GetStringFromStdout ("df", "-h").Trim ();
2122
}
2223

2324
string GetCompiler (string fromEnv, string defaultName)

build-tools/xaprepare/xaprepare/OperatingSystems/Windows.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.IO;
44
using System.Linq;
5+
using System.Text;
56

67
using Xamarin.Android.Tools.VSWhere;
78

@@ -47,6 +48,7 @@ public Windows (Context context) : base (context)
4748
Name = osinfo.FullName;
4849
Architecture = Is64Bit ? "x86" : "x86_64"; // Not good enough! (ARM)
4950
Release = $"{osinfo.Major}.{osinfo.Minor}.{osinfo.Build}";
51+
DiskInformation = DiskInfo ();
5052
}
5153

5254
public override string Which (string programPath, bool required = true)
@@ -128,5 +130,17 @@ string GetHomeDir ()
128130

129131
return $"{homeDrive}{homeDir}";
130132
}
133+
134+
string DiskInfo ()
135+
{
136+
var sb = new StringBuilder ();
137+
sb.AppendLine ("Drive\tTotalSize\tAvailableFreeSpace");
138+
foreach (DriveInfo d in DriveInfo.GetDrives ()) {
139+
if (!d.IsReady)
140+
continue;
141+
sb.AppendLine ($"{d.Name}\t{Utilities.SizeToString (d.TotalSize)}\t{Utilities.SizeToString (d.AvailableFreeSpace)}");
142+
}
143+
return sb.ToString ();
144+
}
131145
};
132146
}

0 commit comments

Comments
 (0)