Amazon CodeGuru
Machine learning service to automate code review and provide performance recommendation
Amazon CodeGuru (generally available since 29th June), a machine learning service for automated code review and application performance profiling. Amazon CodeGuru was trained on its internal projects as well as more than 10,000 open source GitHub projects. With CodeGuru, we can find code issues like resource leaks, potential concurrency race conditions, and wasted CPU cycles and fix same.
There are two components of Amazon CodeGuru
Amazon CodeGuru Reviewer executes automated code reviews and provides code issue detection.
Amazon CodeGuru Profiler searches for ways to improve the application’s performance.
Amazon CodeGuru Reviewer
Amazon CodeGuru not only detects deviation from best practices for using AWS APIs and SDKs, and also identifies concurrency issues, resource leaks, and correct input validation but also provide recommendation to fix same.
Currently it’s in Preview mode and support Java language. We can associate CodeGuru with GitHub and AWS CodeCommit repositories.
Code Guru Reviewer Workflow
Code Guru Reviewer — How it Works
Code Guru Reviewer Demo:
Step 1: Login to AWS Console and search for CodeGuru and click.
Step 2: Click on Associate repository
Step 3: Associate with any existing GitHub or AWS CodeCommit repository
Step 4: Associate repository will be visible
Step 5: Create a pull request
Step 6: Select Source and Destination for pull request
Step 7: Put your comment for pull request
Step 8: Fast and reliable code issue detection
Amazon CodeGuru Profiler
Amazon CodeGuru profiler searches for ways to improve the application’s performance.
It’s an intelligent Profiler trained by many years of performance engineering experience at Amazon
Trained to find methods with high-potential for performance optimization.
— High latency and low throughput.
— High CPU utilization
Recommends how to fix your code
Built for production System
— Lower overhead
— Continuously runs on production
— Continuously analyses performances
CodeGuru Profiler — How it Works
CodeGuru Profiler Demo:
Step 1: Create Profiling group from CodeGuru Services
Step 2: Put the name and click in create button
Step 3: Click on Profiler
Step 4a: To complete profiling group configuration, you must configure agent permissions, add the CodeGuru Profiler agent to your application dependencies, and launch the CodeGuru Profiler agent in your application. Once your application is running, it may take 15 minutes or more for profiling group data to appear.
Agent permissions
Update the IAM role used by the agent
Add this statement to the IAM role used by the agent:
{"Version": "2012-10-17","Statement": [{"Effect": "Allow","Action": ["codeguru-profiler:ConfigureAgent","codeguru-profiler:PostAgentProfile"],"Resource": "arn:aws:codeguru-profiler:us-east-1:<accountID>:profilingGroup/codeguru-profile"}]}
The statement allows the agent to write profile information collected from your application to CodeGuru Profiler.
Step 4b: Configure your build to include the CodeGuru Profiler agent in maven file
Create a custom Maven repository with the URL https://<cloudfronturl.net>
<repositories><repository><id>codeguru-profiler</id><name>codeguru-profiler</name><url>https://<cloudfronturl.net></url></repository></repositories>
Add a dependency on codeguru-profiler-java-agent
:
<dependencies><dependency><groupId>com.amazonaws</groupId><artifactId>codeguru-profiler-java-agent</artifactId><version>0.1.0</version></dependency></dependencies>
Step 4c: Update your Java application to start the CodeGuru Profiler agent
To update your Java application to collect and send data to CodeGuru Profiler:
Open the Java file containing your application main function.
//Add the following import:
import software.amazon.codeguruprofilerjavaagent.Profiler;//Add the following code to the public static void main functionnew Profiler.Builder().profilingGroupName("codeguru-profile").build().start()//Optionally, you can use custom AWS credentials
new Profiler.Builder().profilingGroupName("codeguru-profile").awsCredentialsProvider(myAwsCredentialsProvider).build().start();
An agent can only send data to a single profiling group.
Step 5: Your repository will be available in profiling group
Step 6: Understand the runtime behavior of applications
CodeGuru Profiler analyzes application CPU utilization and latency characteristics to show you where you are spending the most cycles in your application. This analysis is presented in an interactive flame graph that helps you easily understand which paths consume the most resources, verify that your application is performing as expected, and uncover areas that can be optimized further.
Step 7: Intelligent recommendations
CodeGuru Profiler automatically identifies performance issues in your application and provides intelligent recommendations on how to remediate them. These recommendations help you identify and optimize the most expensive or resource intensive methods within your code without you needing to be a performance engineering expert. These optimizations help you reduce the cost of your infrastructure, reduce latency, and improve your overall end user experience.