Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add telemetry entries for BinaryFormatter callsites #6969

Merged
merged 9 commits into from
Feb 19, 2021
51 changes: 39 additions & 12 deletions src/Microsoft.VisualStudio.AppDesigner/Common/Utils.vb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Imports System.ComponentModel.Design
Imports System.Drawing
Imports System.IO
Imports System.Reflection
Imports System.Runtime.CompilerServices
Imports System.Runtime.InteropServices
Imports System.Text.RegularExpressions
Imports System.Windows.Forms
Expand Down Expand Up @@ -626,6 +627,12 @@ Namespace Microsoft.VisualStudio.Editors.AppDesCommon
Private Const UNKNOWN_PAGE As Byte = &HFF
Private Const DEFAULT_PAGE As Byte = 0

Private Const ProjectSystemEventNamePrefix As String = "vs/projectsystem/"
Private Const AppDesignerEventNamePrefix As String = ProjectSystemEventNamePrefix + "appdesigner/"

Private Const ProjectSystemPropertyNamePrefix As String = "vs.projectsystem."
Private Const AppDesignerPropertyNamePrefix As String = ProjectSystemPropertyNamePrefix + "appdesigner."

''' <summary>
''' Map a known property page or designer id to telemetry display name to log.
''' </summary>
Expand All @@ -648,33 +655,53 @@ Namespace Microsoft.VisualStudio.Editors.AppDesCommon
LogAppDesignerPageOpened(pageId, pageGuid, tabTitle, alreadyOpened)
End Sub

Private Const PageOpenedEventName As String = AppDesignerEventNamePrefix + "page-opened"
Private Const PageOpenedPropertyName As String = AppDesignerPropertyNamePrefix + "page-opened"
Private Const PageOpenedPropertyNamePrefix As String = PageOpenedPropertyName + "."

Private Shared Sub LogAppDesignerPageOpened(pageId As Byte, Optional pageGuid As Guid? = Nothing, Optional tabTitle As String = Nothing, Optional alreadyOpened As Boolean = False)
Dim userTask = New UserTaskEvent("vs/projectsystem/appdesigner/page-opened", TelemetryResult.Success)
userTask.Properties("vs.projectsystem.appdesigner.page-opened") = pageId
Dim userTask = New UserTaskEvent(PageOpenedEventName, TelemetryResult.Success)
userTask.Properties(PageOpenedPropertyName) = pageId

If pageGuid IsNot Nothing Then
userTask.Properties("vs.projectsystem.appdesigner.page-opened.pageguid") = pageGuid.Value.ToString()
userTask.Properties(PageOpenedPropertyNamePrefix + "pageguid") = pageGuid.Value.ToString()
End If

If tabTitle IsNot Nothing Then
userTask.Properties("vs.projectsystem.appdesigner.page-opened.tabtitle") = tabTitle
userTask.Properties(PageOpenedPropertyNamePrefix + "tabtitle") = tabTitle
End If

userTask.Properties("vs.projectsystem.appdesigner.page-opened.alreadyopened") = alreadyOpened
userTask.Properties(PageOpenedPropertyNamePrefix + "alreadyopened") = alreadyOpened

TelemetryService.DefaultSession.PostEvent(userTask)
End Sub

Public Shared Sub LogEditorCreation(useNewEditor As Boolean, fileName As String, physicalView As String)
Dim telemetryEventRootPath As String = "vs/projectsystem/propertiespages/"
Dim telemetryPropertyPrefix As String = "vs.projectsystem.propertiespages."
Private Const EditorCreationEventName As String = ProjectSystemEventNamePrefix + "propertiespages/createEditor"
Private Const EditorCreationPropertyNamePrefix As String = ProjectSystemPropertyNamePrefix + "propertiespages.createEditor."

Dim telemetryEvent As TelemetryEvent = New TelemetryEvent(telemetryEventRootPath + "createEditor")
telemetryEvent.Properties(telemetryPropertyPrefix + "createEditor.UseNewEditor") = useNewEditor
telemetryEvent.Properties(telemetryPropertyPrefix + "createEditor.FileName") = New TelemetryPiiProperty(fileName)
telemetryEvent.Properties(telemetryPropertyPrefix + "createEditor.PhysicalView") = physicalView
Public Shared Sub LogEditorCreation(useNewEditor As Boolean, fileName As String, physicalView As String)
Dim telemetryEvent As TelemetryEvent = New TelemetryEvent(EditorCreationEventName)
telemetryEvent.Properties(EditorCreationPropertyNamePrefix + "UseNewEditor") = useNewEditor
telemetryEvent.Properties(EditorCreationPropertyNamePrefix + "FileName") = New TelemetryPiiProperty(fileName)
telemetryEvent.Properties(EditorCreationPropertyNamePrefix + "PhysicalView") = physicalView
TelemetryService.DefaultSession.PostEvent(telemetryEvent)
End Sub

Private Const BinaryFormatterEventName As String = AppDesignerEventNamePrefix + "binaryformatter"
Private Const BinaryFormatterPropertyNamePrefix As String = AppDesignerPropertyNamePrefix + "binaryformatter."
Public Enum BinaryFormatterOperation
Serialize = 0
Deserialize = 1
End Enum

Public Shared Sub LogBinaryFormatterEvent(className As String, operation As BinaryFormatterOperation, <CallerMemberName> Optional functionName As String = Nothing)
Dim userTask = New UserTaskEvent(BinaryFormatterEventName, TelemetryResult.Success)
userTask.Properties(BinaryFormatterPropertyNamePrefix + "functionname") = functionName
userTask.Properties(BinaryFormatterPropertyNamePrefix + "classname") = className
userTask.Properties(BinaryFormatterPropertyNamePrefix + "operation") = operation
TelemetryService.DefaultSession.PostEvent(userTask)
End Sub

End Class
#End Region

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Imports System.ComponentModel.Design
Imports System.IO
Imports System.Runtime.Serialization
Imports System.Runtime.Serialization.Formatters.Binary
Imports Microsoft.VisualStudio.Editors.AppDesCommon

Namespace Microsoft.VisualStudio.Editors.PropPageDesigner

Expand Down Expand Up @@ -130,8 +131,9 @@ Namespace Microsoft.VisualStudio.Editors.PropPageDesigner
''' </summary>
''' <param name="Stream">The stream to load from</param>
Public Shared Function Load(Stream As Stream) As PropertyPageSerializationStore
Dim f As New BinaryFormatter
Return DirectCast(f.Deserialize(Stream), PropertyPageSerializationStore)
TelemetryLogger.LogBinaryFormatterEvent(NameOf(PropertyPageSerializationStore), TelemetryLogger.BinaryFormatterOperation.Deserialize)

Return DirectCast((New BinaryFormatter).Deserialize(Stream), PropertyPageSerializationStore)
End Function

''' <summary>
Expand All @@ -144,8 +146,9 @@ Namespace Microsoft.VisualStudio.Editors.PropPageDesigner
Public Overrides Sub Save(Stream As Stream)
Close()

Dim f As New BinaryFormatter
f.Serialize(Stream, Me)
TelemetryLogger.LogBinaryFormatterEvent(NameOf(PropertyPageSerializationStore), TelemetryLogger.BinaryFormatterOperation.Serialize)

Call (New BinaryFormatter).Serialize(Stream, Me)
End Sub

#End Region
Expand Down Expand Up @@ -507,6 +510,8 @@ Namespace Microsoft.VisualStudio.Editors.PropPageDesigner
''' <param name="Object">The object to serialize</param>
''' <returns>The binary serialized object.</returns>
Private Shared Function SerializeObject([Object] As Object) As Byte()
TelemetryLogger.LogBinaryFormatterEvent(NameOf(SerializedProperty), TelemetryLogger.BinaryFormatterOperation.Serialize)

Dim MemoryStream As New MemoryStream
Call (New BinaryFormatter).Serialize(MemoryStream, [Object])
Return MemoryStream.ToArray()
Expand All @@ -521,6 +526,8 @@ Namespace Microsoft.VisualStudio.Editors.PropPageDesigner
Throw New Package.InternalException
End If

TelemetryLogger.LogBinaryFormatterEvent(NameOf(SerializedProperty), TelemetryLogger.BinaryFormatterOperation.Deserialize)

Dim MemoryStream As New MemoryStream(_serializedValue)
Return DirectCast((New BinaryFormatter).Deserialize(MemoryStream), PropPageDesignerRootComponent)
End Function
Expand All @@ -538,6 +545,8 @@ Namespace Microsoft.VisualStudio.Editors.PropPageDesigner
Return Nothing
End If

TelemetryLogger.LogBinaryFormatterEvent(NameOf(SerializedProperty), TelemetryLogger.BinaryFormatterOperation.Deserialize)

Dim MemoryStream As New MemoryStream(_serializedValue)
Return (New BinaryFormatter).Deserialize(MemoryStream)
End Function
Expand Down
30 changes: 26 additions & 4 deletions src/Microsoft.VisualStudio.Editors/Common/Utils.vb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Imports System.ComponentModel.Design
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.IO
Imports System.Runtime.CompilerServices
Imports System.Runtime.InteropServices
Imports System.Runtime.Versioning
Imports System.Text
Expand Down Expand Up @@ -1611,7 +1612,13 @@ Namespace Microsoft.VisualStudio.Editors.Common
#Region "Telemetry"
Public Class TelemetryLogger

Private Const InputXmlFormEventName As String = "vs/projectsystem/editors/inputxmlform"
Private Const ProjectSystemEventNamePrefix As String = "vs/projectsystem/"
Private Const EditorsEventNamePrefix As String = ProjectSystemEventNamePrefix + "editors/"

Private Const ProjectSystemPropertyNamePrefix As String = "vs.projectsystem."
Private Const EditorsPropertyNamePrefix As String = ProjectSystemPropertyNamePrefix + "editors."

Private Const InputXmlFormEventName As String = EditorsEventNamePrefix + "inputxmlform"
Public Enum InputXmlFormEvent
FormOpened
FromFileButtonClicked
Expand All @@ -1621,23 +1628,38 @@ Namespace Microsoft.VisualStudio.Editors.Common

Public Shared Sub LogInputXmlFormEvent(eventValue As InputXmlFormEvent)
Dim userTask = New UserTaskEvent(InputXmlFormEventName, TelemetryResult.Success)
userTask.Properties("vs.projectsystem.editors.inputxmlform") = eventValue
userTask.Properties(EditorsPropertyNamePrefix + "inputxmlform") = eventValue
TelemetryService.DefaultSession.PostEvent(userTask)
End Sub

Public Shared Sub LogInputXmlFormException(ex As Exception)
TelemetryService.DefaultSession.PostFault(InputXmlFormEventName, "Exception encountered during Xml Schema Inference", ex)
End Sub

Private Const AdvBuildSettingsPropPageEventName As String = "vs/projectsystem/appdesigner/advbuildsettingsproppage"
Private Const AdvBuildSettingsPropPageEventName As String = ProjectSystemEventNamePrefix + "appdesigner/advbuildsettingsproppage"
Public Enum AdvBuildSettingsPropPageEvent
FormOpened = 0
LangVersionMoreInfoLinkClicked = 1
End Enum

Public Shared Sub LogAdvBuildSettingsPropPageEvent(eventValue As AdvBuildSettingsPropPageEvent)
Dim userTask = New UserTaskEvent(AdvBuildSettingsPropPageEventName, TelemetryResult.Success)
userTask.Properties("vs.projectsystem.appdesigner.advbuildsettingsproppage") = eventValue
userTask.Properties(ProjectSystemPropertyNamePrefix + "appdesigner.advbuildsettingsproppage") = eventValue
TelemetryService.DefaultSession.PostEvent(userTask)
End Sub

Private Const BinaryFormatterEventName As String = EditorsEventNamePrefix + "binaryformatter"
Private Const BinaryFormatterPropertyNamePrefix As String = EditorsPropertyNamePrefix + "binaryformatter."
Public Enum BinaryFormatterOperation
Serialize = 0
Deserialize = 1
End Enum

Public Shared Sub LogBinaryFormatterEvent(className As String, operation As BinaryFormatterOperation, <CallerMemberName> Optional functionName As String = Nothing)
Dim userTask = New UserTaskEvent(BinaryFormatterEventName, TelemetryResult.Success)
userTask.Properties(BinaryFormatterPropertyNamePrefix + "functionname") = functionName
userTask.Properties(BinaryFormatterPropertyNamePrefix + "classname") = className
userTask.Properties(BinaryFormatterPropertyNamePrefix + "operation") = operation
TelemetryService.DefaultSession.PostEvent(userTask)
End Sub

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Imports System.ComponentModel.Design.Serialization
Imports System.IO
Imports System.Runtime.Serialization
Imports System.Runtime.Serialization.Formatters.Binary
Imports Microsoft.VisualStudio.Editors.Common

Namespace Microsoft.VisualStudio.Editors.DesignerFramework

Expand Down Expand Up @@ -110,8 +111,9 @@ Namespace Microsoft.VisualStudio.Editors.DesignerFramework
''' </summary>
''' <param name="Stream">The stream to load from</param>
Public Shared Function Load(Stream As Stream) As GenericComponentSerializationStore
Dim f As New BinaryFormatter
Return DirectCast(f.Deserialize(Stream), GenericComponentSerializationStore)
TelemetryLogger.LogBinaryFormatterEvent(NameOf(GenericComponentSerializationStore), TelemetryLogger.BinaryFormatterOperation.Deserialize)

Return DirectCast((New BinaryFormatter).Deserialize(Stream), GenericComponentSerializationStore)
End Function

''' <summary>
Expand All @@ -124,8 +126,9 @@ Namespace Microsoft.VisualStudio.Editors.DesignerFramework
Public Overrides Sub Save(Stream As Stream)
Close()

Dim f As New BinaryFormatter
f.Serialize(Stream, Me)
TelemetryLogger.LogBinaryFormatterEvent(NameOf(GenericComponentSerializationStore), TelemetryLogger.BinaryFormatterOperation.Serialize)

Call (New BinaryFormatter).Serialize(Stream, Me)
End Sub

#End Region
Expand Down Expand Up @@ -468,8 +471,10 @@ Namespace Microsoft.VisualStudio.Editors.DesignerFramework
If [Object] Is Nothing Then
Return Array.Empty(Of Byte)
Else
TelemetryLogger.LogBinaryFormatterEvent(NameOf(SerializedObjectData), TelemetryLogger.BinaryFormatterOperation.Serialize)

Dim MemoryStream As New MemoryStream
Call New BinaryFormatter().Serialize(MemoryStream, [Object])
Call (New BinaryFormatter).Serialize(MemoryStream, [Object])
Return MemoryStream.ToArray()
End If
End Function
Expand All @@ -478,6 +483,8 @@ Namespace Microsoft.VisualStudio.Editors.DesignerFramework
If _serializedValue.Length = 0 Then
Return Nothing
Else
TelemetryLogger.LogBinaryFormatterEvent(NameOf(SerializedObjectData), TelemetryLogger.BinaryFormatterOperation.Deserialize)

Dim MemoryStream As New MemoryStream(_serializedValue)
Return (New BinaryFormatter).Deserialize(MemoryStream)
End If
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Imports System.Globalization
Imports System.IO
Imports System.Reflection
Imports System.Runtime.InteropServices
Imports System.Runtime.Serialization.Formatters.Binary
Imports System.Text
Imports System.Windows.Forms
Imports System.Windows.Forms.Design
Expand Down Expand Up @@ -2491,10 +2492,11 @@ Namespace Microsoft.VisualStudio.Editors.ResourceEditor
'1) Create a structure with our raw resources data (our preferred format)
Dim ResourcesData As New ResourcesDataFormat(Resources)

TelemetryLogger.LogBinaryFormatterEvent(NameOf(ResourceEditorView), TelemetryLogger.BinaryFormatterOperation.Serialize)

'... then package it into a serialized blob
Dim Formatter As New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
Dim Stream As New MemoryStream
Formatter.Serialize(Stream, ResourcesData)
Call (New BinaryFormatter).Serialize(Stream, ResourcesData)

'... and stuff into a DataObject
Stream.Seek(0, SeekOrigin.Begin)
Expand Down Expand Up @@ -2989,11 +2991,12 @@ Namespace Microsoft.VisualStudio.Editors.ResourceEditor
Return
End If

TelemetryLogger.LogBinaryFormatterEvent(NameOf(ResourceEditorView), TelemetryLogger.BinaryFormatterOperation.Deserialize)

'Decode the data format
Dim RawBytes() As Byte = DirectCast(Data.GetData(_CF_RESOURCES), Byte())
Dim MemoryStream As New MemoryStream(RawBytes)
Dim Formatter As New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
Dim ResourcesData As ResourcesDataFormat = DirectCast(Formatter.Deserialize(MemoryStream), ResourcesDataFormat)
Dim ResourcesData As ResourcesDataFormat = DirectCast((New BinaryFormatter).Deserialize(MemoryStream), ResourcesDataFormat)

'Okay, we have our copied resources, let's add them
AddResources(ResourcesData.Resources, CopyFileIfExists, AddToProject:=True)
Expand Down
Loading