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

SetPixels Analyzer #56

Merged
merged 7 commits into from
May 20, 2020
Merged

SetPixels Analyzer #56

merged 7 commits into from
May 20, 2020

Conversation

sailro
Copy link
Member

@sailro sailro commented Apr 10, 2020

Fixes #55

Checklist

  • I have read the Contribution Guide ;
  • There is an approved issue describing the change when contributing a new analyzer or suppressor ;
  • I have added tests that prove my fix is effective or that my feature works ;
  • I have added necessary documentation (if appropriate) ;

Declare a simple attribute and a rule:

public class SetPixelsMethodUsageAttribute : MethodUsageAttribute
{
}

public class SetPixelsMethodUsageAnalyzer : BaseMethodUsageAnalyzer<SetPixelsMethodUsageAttribute> 
{
	internal static readonly DiagnosticDescriptor Rule = new DiagnosticDescriptor(
		id: "UNT0017",
		title: Strings.SetPixelsMethodUsageDiagnosticTitle,
		messageFormat: Strings.SetPixelsMethodUsageDiagnosticMessageFormat,
		category: DiagnosticCategory.Performance,
		defaultSeverity: DiagnosticSeverity.Info,
		isEnabledByDefault: true,
		description: Strings.SetPixelsMethodUsageDiagnosticDescription);

	public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray.Create(Rule);
}

Then decorate stubs to trigger analysis:

class Texture2D
{
	[SetPixelsMethodUsage] void SetPixels(int x, int y, int blockWidth, int blockHeight, Color[] colors, int miplevel) { }
	[SetPixelsMethodUsage] void SetPixels(int x, int y, int blockWidth, int blockHeight, Color[] colors) { }
	[SetPixelsMethodUsage] void SetPixels(Color[] colors, int miplevel) { }
	[SetPixelsMethodUsage] void SetPixels(Color[] colors) { }
}

Should be very easy to reuse to flag method that allocates.

@sailro sailro requested a review from jbevain April 10, 2020 15:54
@sailro sailro changed the title Declarative Audit Prototype SetPixels Analyzer May 20, 2020
@sailro sailro marked this pull request as ready for review May 20, 2020 20:15
@sailro sailro requested a review from a team as a code owner May 20, 2020 20:15
@sailro sailro requested a review from jbevain May 20, 2020 22:38
@sailro sailro merged commit e1efba6 into master May 20, 2020
@sailro sailro deleted the audit-infrastructure branch May 20, 2020 23:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Performance] Analyzer for SetPixels -> SetPixels32
2 participants