編集

次の方法で共有


Monitor and analyze runtime behavior with Code Optimizations

Diagnosing your application's performance issues can be difficult, especially when running on a production environment in the dynamic cloud. Slow responses in your application could be caused by infrastructure, framework, or application code handling the request in the pipeline.

Code Optimizations, an AI-based service in Azure Application Insights, works in tandem with the Application Insights Profiler for .NET to detect CPU and memory usage performance issues at a code level and provide recommendations on how to fix them.

Make informed decisions and optimize your code using real-time performance data and insights gathered from your production environment.

You can review your Code Optimizations in the Azure portal.

Code Optimizations and Application Insights Profiler for .NET

The .NET Profiler and Code Optimizations work together to provide a holistic approach to performance issue detection.

Code Optimizations

Code Optimizations analyzes the profiling data collected by the Application Insights Profiler for .NET. As the .NET Profiler uploads data to Application Insights, our machine learning model analyzes some of the data to find where the application's code can be optimized. Code Optimizations:

  • Displays aggregated data gathered over time.
  • Connects data with the methods and functions in your application code.
  • Narrows down the culprit by finding bottlenecks within the code.

Demo video

Application Insights Profiler for .NET

The .NET Profiler focuses on tracing specific requests, down to the millisecond. It provides an excellent "big picture" view of issues within your application and general best practices to address them.

With Application Insights Profiler for .NET, you can capture, identify, and view performance traces for your application running in Azure, regardless of the scenario. The .NET Profiler trace process occurs automatically, at scale, and doesn't negatively affect your users. The .NET Profiler identifies:

  • The median, fastest, and slowest response times for each web request made by your customers.
  • The "hot" code path spending the most time handling a particular web request.

Enable the Profiler for .NET on all your Azure applications to gather data with the following triggers:

  • Sampling trigger: Starts Profiler randomly about once an hour for two minutes.
  • CPU trigger: Starts Profiler when the CPU usage percentage is over 80 percent.
  • Memory trigger: Starts Profiler when memory usage is above 80 percent.

Each of these triggers can be configured, enabled, or disabled.

Cost and overhead

Code Optimizations are generated automatically after Application Insights Profiler for .NET is enabled. By default, Profiler actively collects traces every hour for 30 seconds or during periods of high CPU or memory usage for 30 seconds. The hourly traces (called sampling) are great for proactive tuning, while the high CPU and memory traces (called triggers) are useful for reactive troubleshooting.

Note

When the Application Insights Profiler for .NET is actively running and collecting traces, it typically adds between 5% to 15% of CPU and memory overhead to your server.

There is no additional cost for storing data captured by .NET Profiler. The data is automatically deleted after 15 days.

Some Code Optimization features (such as code-level fix suggestions) require Copilot for GitHub and/or Copilot for Azure.

Supported services

The Profiler and Code Optimizations work with .NET applications deployed on the following Azure services. View specific instructions for enabling Profiler for each service type in the following links.

Compute platform .NET (>= 4.6) .NET Core
Azure App Service - .NET app on Windows Yes Yes
Azure App Service - .NET app on Linux No Yes
Azure Virtual Machines and Virtual Machine Scale Sets for Windows Yes Yes
Azure Cloud Services Yes Yes
Azure Container Instances for Windows No Yes
Azure Container Instances for Linux No Yes
Kubernetes No Yes
Azure Functions Yes Yes
Azure Service Fabric Yes Yes

Note

You can also use the Java Profiler for Azure Monitor Application Insights, currently in preview.

Supported regions

Code Optimizations is available in the same regions as Application Insights. You can check the available regions using the following command:

az account list-locations -o table

You can set an explicit region using connection strings. Learn more about connection strings with examples.

Limitations

Profiling web apps:

  • Although you can use the .NET Profiler at no extra cost, your web app must be hosted in the basic tier of the Web Apps feature of Azure App Service, at minimum.
  • You can attach only one profiler to each web app.

Troubleshooting

Next steps

Learn how to enable the .NET Profiler with Code Optimizations on your Azure service: