Skip to content

Commit 78a6957

Browse files
authored
Merge pull request #536 from jeschu1/enlistmentinfo
Add DiskInfo to HeartBeat
2 parents 617956e + 77c27aa commit 78a6957

8 files changed

Lines changed: 68 additions & 46 deletions

File tree

GVFS/GVFS.Common/GVFSPlatform.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public static void Register(GVFSPlatform platform)
5353

5454
public abstract InProcEventListener CreateTelemetryListenerIfEnabled(string providerName, string enlistmentId, string mountId);
5555

56-
public abstract Dictionary<string, string> GetPhysicalDiskInfo(string path);
56+
public abstract Dictionary<string, string> GetPhysicalDiskInfo(string path, bool sizeStatsOnly);
5757

5858
public abstract bool IsConsoleOutputRedirectedToFile();
5959
public abstract bool TryGetGVFSEnlistmentRoot(string directory, out string enlistmentRoot, out string errorMessage);

GVFS/GVFS.Platform.Mac/MacPlatform.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public override string GetOSVersionInformation()
9797
return string.IsNullOrWhiteSpace(result.Output) ? result.Errors : result.Output;
9898
}
9999

100-
public override Dictionary<string, string> GetPhysicalDiskInfo(string path)
100+
public override Dictionary<string, string> GetPhysicalDiskInfo(string path, bool sizeStatsOnly)
101101
{
102102
// TODO(Mac): Collect disk information
103103
Dictionary<string, string> result = new Dictionary<string, string>();

GVFS/GVFS.Platform.Windows/WindowsPhysicalDiskInfo.cs

Lines changed: 53 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public class WindowsPhysicalDiskInfo
5454
/// the given pathname. For example, whether the drive is an SSD or HDD.
5555
/// </summary>
5656
/// <returns>A dictionary of platform-specific keywords and values.</returns>
57-
public static Dictionary<string, string> GetPhysicalDiskInfo(string path)
57+
public static Dictionary<string, string> GetPhysicalDiskInfo(string path, bool sizeStatsOnly)
5858
{
5959
// Use the WMI APIs to get details about the physical disk associated with the given path.
6060
// Some of these fields are avilable using normal classes, such as System.IO.DriveInfo:
@@ -96,46 +96,14 @@ public static Dictionary<string, string> GetPhysicalDiskInfo(string path)
9696
ManagementScope scope = new ManagementScope(@"\\.\root\microsoft\windows\storage");
9797
scope.Connect();
9898

99-
string queryVolumeString = $"SELECT DriveType,FileSystem,FileSystemLabel,Size,SizeRemaining FROM MSFT_Volume WHERE DriveLetter=\"{driveLetter}\"";
100-
ManagementBaseObject mbo = GetFirstRecord(scope, queryVolumeString);
101-
if (mbo != null)
102-
{
103-
result.Add("VolumeDriveType", GetMapValue(MapDriveType, FetchValue(mbo, "DriveType")));
104-
result.Add("VolumeFileSystem", FetchValue(mbo, "FileSystem"));
105-
result.Add("VolumeFileSystemLabel", FetchValue(mbo, "FileSystemLabel"));
106-
result.Add("VolumeSize", FetchValue(mbo, "Size"));
107-
result.Add("VolumeSizeRemaining", FetchValue(mbo, "SizeRemaining"));
108-
}
99+
DiskSizeStatistics(scope, driveLetter, ref result);
109100

110-
string queryPartitionString = $"SELECT DiskNumber FROM MSFT_Partition WHERE DriveLetter=\"{driveLetter}\"";
111-
mbo = GetFirstRecord(scope, queryPartitionString);
112-
if (mbo != null)
101+
if (sizeStatsOnly)
113102
{
114-
string diskNumber = FetchValue(mbo, "DiskNumber");
115-
result.Add("DiskNumber", diskNumber);
116-
117-
if (diskNumber.Length > 0)
118-
{
119-
string queryDiskString = $"SELECT Model,IsBoot,IsSystem,SerialNumber FROM MSFT_Disk WHERE Number=\"{diskNumber}\"";
120-
mbo = GetFirstRecord(scope, queryDiskString);
121-
if (mbo != null)
122-
{
123-
result.Add("DiskModel", FetchValue(mbo, "Model"));
124-
result.Add("DiskIsSystem", FetchValue(mbo, "IsSystem"));
125-
result.Add("DiskIsBoot", FetchValue(mbo, "IsBoot"));
126-
result.Add("DiskSerialNumber", FetchValue(mbo, "SerialNumber"));
127-
}
128-
129-
string queryPhysicalDiskString = $"SELECT MediaType,BusType,SpindleSpeed FROM MSFT_PhysicalDisk WHERE DeviceId=\"{diskNumber}\"";
130-
mbo = GetFirstRecord(scope, queryPhysicalDiskString);
131-
if (mbo != null)
132-
{
133-
result.Add("PhysicalMediaType", GetMapValue(MapMediaType, FetchValue(mbo, "MediaType")));
134-
result.Add("PhysicalBusType", GetMapValue(MapBusType, FetchValue(mbo, "BusType")));
135-
result.Add("PhysicalSpindleSpeed", FetchValue(mbo, "SpindleSpeed"));
136-
}
137-
}
103+
return result;
138104
}
105+
106+
DiskTypeInfo(scope, driveLetter, ref result);
139107
}
140108
catch (Exception e)
141109
{
@@ -145,6 +113,53 @@ public static Dictionary<string, string> GetPhysicalDiskInfo(string path)
145113
return result;
146114
}
147115

116+
private static void DiskSizeStatistics(ManagementScope scope, char driveLetter, ref Dictionary<string, string> result)
117+
{
118+
string queryVolumeString = $"SELECT DriveType,FileSystem,FileSystemLabel,Size,SizeRemaining FROM MSFT_Volume WHERE DriveLetter=\"{driveLetter}\"";
119+
ManagementBaseObject mbo = GetFirstRecord(scope, queryVolumeString);
120+
if (mbo != null)
121+
{
122+
result.Add("VolumeDriveType", GetMapValue(MapDriveType, FetchValue(mbo, "DriveType")));
123+
result.Add("VolumeFileSystem", FetchValue(mbo, "FileSystem"));
124+
result.Add("VolumeFileSystemLabel", FetchValue(mbo, "FileSystemLabel"));
125+
result.Add("VolumeSize", FetchValue(mbo, "Size"));
126+
result.Add("VolumeSizeRemaining", FetchValue(mbo, "SizeRemaining"));
127+
}
128+
}
129+
130+
private static void DiskTypeInfo(ManagementScope scope, char driveLetter, ref Dictionary<string, string> result)
131+
{
132+
string queryPartitionString = $"SELECT DiskNumber FROM MSFT_Partition WHERE DriveLetter=\"{driveLetter}\"";
133+
ManagementBaseObject mbo = GetFirstRecord(scope, queryPartitionString);
134+
if (mbo != null)
135+
{
136+
string diskNumber = FetchValue(mbo, "DiskNumber");
137+
result.Add("DiskNumber", diskNumber);
138+
139+
if (diskNumber.Length > 0)
140+
{
141+
string queryDiskString = $"SELECT Model,IsBoot,IsSystem,SerialNumber FROM MSFT_Disk WHERE Number=\"{diskNumber}\"";
142+
mbo = GetFirstRecord(scope, queryDiskString);
143+
if (mbo != null)
144+
{
145+
result.Add("DiskModel", FetchValue(mbo, "Model"));
146+
result.Add("DiskIsSystem", FetchValue(mbo, "IsSystem"));
147+
result.Add("DiskIsBoot", FetchValue(mbo, "IsBoot"));
148+
result.Add("DiskSerialNumber", FetchValue(mbo, "SerialNumber"));
149+
}
150+
151+
string queryPhysicalDiskString = $"SELECT MediaType,BusType,SpindleSpeed FROM MSFT_PhysicalDisk WHERE DeviceId=\"{diskNumber}\"";
152+
mbo = GetFirstRecord(scope, queryPhysicalDiskString);
153+
if (mbo != null)
154+
{
155+
result.Add("PhysicalMediaType", GetMapValue(MapMediaType, FetchValue(mbo, "MediaType")));
156+
result.Add("PhysicalBusType", GetMapValue(MapBusType, FetchValue(mbo, "BusType")));
157+
result.Add("PhysicalSpindleSpeed", FetchValue(mbo, "SpindleSpeed"));
158+
}
159+
}
160+
}
161+
}
162+
148163
private static string FetchValue(ManagementBaseObject mbo, string key)
149164
{
150165
return (mbo[key] != null) ? mbo[key].ToString().Trim() : string.Empty;

GVFS/GVFS.Platform.Windows/WindowsPlatform.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ public override string GetCurrentUser()
252252
return identity.User.Value;
253253
}
254254

255-
public override Dictionary<string, string> GetPhysicalDiskInfo(string path) => WindowsPhysicalDiskInfo.GetPhysicalDiskInfo(path);
255+
public override Dictionary<string, string> GetPhysicalDiskInfo(string path, bool sizeStatsOnly) => WindowsPhysicalDiskInfo.GetPhysicalDiskInfo(path, sizeStatsOnly);
256256

257257
public override bool IsConsoleOutputRedirectedToFile()
258258
{

GVFS/GVFS.UnitTests/Mock/Common/MockPlatform.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ public override string GetOSVersionInformation()
6666
throw new NotSupportedException();
6767
}
6868

69-
public override Dictionary<string, string> GetPhysicalDiskInfo(string path)
69+
public override Dictionary<string, string> GetPhysicalDiskInfo(string path, bool sizeStatsOnly)
7070
{
71-
throw new NotSupportedException();
71+
return new Dictionary<string, string>();
7272
}
7373

7474
public override void InitializeEnlistmentACLs(string enlistmentPath)

GVFS/GVFS.UnitTests/Virtualization/FileSystemCallbacksTests.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,13 @@ public void GetMetadataForHeartBeatDoesSetsEventLevelWToInformationalWhenPlaceho
141141
eventLevel.ShouldEqual(EventLevel.Informational);
142142

143143
// "ModifiedPathsCount" should be 1 because ".gitattributes" is always present
144-
metadata.Count.ShouldEqual(5);
144+
metadata.Count.ShouldEqual(6);
145145
metadata.ShouldContain("ProcessName1", "GVFS.UnitTests.exe");
146146
metadata.ShouldContain("ProcessCount1", 1);
147147
metadata.ShouldContain("ModifiedPathsCount", 1);
148148
metadata.ShouldContain("PlaceholderCount", 1);
149149
metadata.ShouldContain(nameof(RepoMetadata.Instance.EnlistmentId), RepoMetadata.Instance.EnlistmentId);
150+
metadata.ContainsKey("PhysicalDiskInfo").ShouldBeTrue();
150151

151152
// Create more placeholders
152153
fileSystemCallbacks.OnPlaceholderFileCreated("test.txt", "2222233333444445555566666777778888899999", "GVFS.UnitTests.exe2");
@@ -156,14 +157,15 @@ public void GetMetadataForHeartBeatDoesSetsEventLevelWToInformationalWhenPlaceho
156157
metadata = fileSystemCallbacks.GetMetadataForHeartBeat(ref eventLevel);
157158
eventLevel.ShouldEqual(EventLevel.Informational);
158159

159-
metadata.Count.ShouldEqual(5);
160+
metadata.Count.ShouldEqual(6);
160161

161162
// Only processes that have created placeholders since the last heartbeat should be named
162163
metadata.ShouldContain("ProcessName1", "GVFS.UnitTests.exe2");
163164
metadata.ShouldContain("ProcessCount1", 2);
164165
metadata.ShouldContain("ModifiedPathsCount", 1);
165166
metadata.ShouldContain("PlaceholderCount", 3);
166167
metadata.ShouldContain(nameof(RepoMetadata.Instance.EnlistmentId), RepoMetadata.Instance.EnlistmentId);
168+
metadata.ContainsKey("PhysicalDiskInfo").ShouldBeTrue();
167169
}
168170
}
169171

GVFS/GVFS.Virtualization/FileSystemCallbacks.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,11 @@ public EventMetadata GetMetadataForHeartBeat(ref EventLevel eventLevel)
344344
}
345345

346346
metadata.Add(nameof(RepoMetadata.Instance.EnlistmentId), RepoMetadata.Instance.EnlistmentId);
347+
metadata.Add(
348+
"PhysicalDiskInfo",
349+
GVFSPlatform.Instance.GetPhysicalDiskInfo(
350+
this.context.Enlistment.WorkingDirectoryRoot,
351+
sizeStatsOnly: true));
347352

348353
return metadata;
349354
}

GVFS/GVFS/CommandLine/GVFSVerb.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ protected void LogEnlistmentInfoAndSetConfigValues(ITracer tracer, GitProcess gi
560560
metadata.Add(nameof(RepoMetadata.Instance.EnlistmentId), RepoMetadata.Instance.EnlistmentId);
561561
metadata.Add(nameof(mountId), mountId);
562562
metadata.Add("Enlistment", enlistment);
563-
metadata.Add("PhysicalDiskInfo", GVFSPlatform.Instance.GetPhysicalDiskInfo(enlistment.WorkingDirectoryRoot));
563+
metadata.Add("PhysicalDiskInfo", GVFSPlatform.Instance.GetPhysicalDiskInfo(enlistment.WorkingDirectoryRoot, sizeStatsOnly: false));
564564
tracer.RelatedEvent(EventLevel.Informational, "EnlistmentInfo", metadata, Keywords.Telemetry);
565565

566566
GitProcess.Result configResult = git.SetInLocalConfig(GVFSConstants.GitConfig.EnlistmentId, RepoMetadata.Instance.EnlistmentId, replaceAll: true);

0 commit comments

Comments
 (0)