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
2 changes: 1 addition & 1 deletion build/import/Packages.targets
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
https://pkgs.dev.azure.com/dnceng/public/_packaging/myget-legacy/nuget/v3/index.json;
https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/index.json;
https://dotnetfeed.blob.core.windows.net/dotnet-core/index.json;
https://api.nuget.org/v3/index.json;
https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-public/nuget/v3/index.json;
</RestoreSources>
</PropertyGroup>

Expand Down
37 changes: 32 additions & 5 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,22 +655,42 @@ 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

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
31 changes: 27 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,39 @@ 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"
' TODO: Not sure why this is using "appdesigner" in the editors project
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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,9 @@
<data name="&gt;&gt;AnalysisLevelLabel.ZOrder" xml:space="preserve">
<value>5</value>
</data>
<data name="AnalysisLevelComboBox.AccessibleName" xml:space="preserve">
<value>Analysis level value</value>
</data>
<data name="AnalysisLevelComboBox.AutoCompleteCustomSource" xml:space="preserve">
<value>preview</value>
</data>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading