Next-Level Debugging with GitHub Copilot in Visual Studio

Microsoft Visual Studio8,584 words

Full Transcript

In this session, I will be showing you more of Visual Studio 2026, but I will be focusing more on the diagnostics part. I'll be sharing more of the improvements we have been doing around the debugger and profiling workspaces with the copilot experiences. So to start with, my name is Harsha Hole. I'm a product manager in Visual Studios debugging and profiling team. from last few months. I've been focusing on the co-pilot experiences, but I've been in the team for almost four plus years now. So, super excited to be here and share all the new improvements we have been doing. I have a lot of demos packed today. So hopefully if the internet works fine and copilot works fine I should be able to share everything to just to give you a precap um I'm going to be sharing some of the basics debugging features like break points trace points and how you can use copilot to make that experience a little better. Then we'll also see some of the data visualization while you debug and again some of the copilot assistance there to see how you can actually make that data visualization more easier. Then I will be sharing one of our newest experience around inline variable values with copilot assistance. And uh I will also talk a little bit about some of the newer capabilities we added in the exception helper. So exception helper has been one of our very first feature where we added uh copilot assistance and since then we have been adding a lot of new capabilities there. So we added a deep analysis for uh complex exceptions as well as some repository context. So we'll see the demo around that. We'll also see a demo on how you can actually uh figure out when you have a deadlock or a hang situation when you're working with multi-threaded programming. And then finally, I will show you a debugger agent which will actually help you fix your failed test. And then we will also try to see a copilot profiler agent to see how you can optimize the code which unfortunately we couldn't see in the keynote due to the internet issues. So I'll try to show you how I use the profiler agent to make my code faster or optimized. Okay. So let's get into the demo. So as I said I will be starting from the basic features like pro uh like break points and trace points. For my very first demo I'm going to be using this simple application called car list. It's just an uh application that gets the different details about the car and at the end it gives me all the details with uh discounted prices and adjusted prices. Now if you notice here in the line 12 I am actually generating 300 cars. So I'm expecting that when I run this application I should be able to see the details for all the 300 cars. So let's try to see that if it's working or not. Now if you notice here I have quite a few code here in the uh in this application and couple break points too. So if I run this application I'm going to stop at each of those break points which I don't want to do. What I can do is I can use something called force run to cursor. So what force run to cursor does it actually runs your cursor at a particular line but it skips all your break points without you deleting or disabling them. And it also skips all of your first task exceptions if anything occurs like that. All you need to do if you're not in a debug mode, right click and do force run to cursor and then it will run the cursor at that particular location which for me this is my application run and it's showing me that the number of cards displayed is 266. So clearly there is a bug. I was expecting 300 cards there. So let's try to figure out what is going on here. I'm going to stop my debugging again here. Now I want to take your attention to this break points window I have. So if you notice I have these break points arranged in certain types of groups. So this is using the breakpoint groups. Again um breakpoint groups can be really handy when you are working with multiple bugs and you just wanted to focus on one particular section. You can disable enable those break points in a group with just single click. For me, my scenario is different types of demos. So right now I have a breakpoint group for a visualizer enabled here. Um let me go to the code here. So if you notice I have this break point on line 42. This is where a generate car function is actually getting all the details and adding it to the list. So I'm going to go ahead and start my debugging and stop or break at this line 42 here. The reason I broke uh a break here is I wanted to see what all the data this list is creating. So to visualize the data while you're debugging, there are multiple ways you can do that. You can hover over this function. You can use this data tip which you all might know already. You can expand and see all the data inside it. Or what you can do is you can also hover over this view here and use something called innumerable visualizer if you don't know. So inable visualizer will actually show you a better way to visualize your data. Any type of innumerable you can actually filter your data, sort your data, even export your data if you want to. Now I only have 300 rows here, but imagine when you have a larger set, this could be really handy to uh filter, sort, and you can even do custom filtration using link queries here. So you can write your own link query in this expression text box and that will actually do a custom filtration for you. Now if you need a little bit help with writing the link queries, what you can do is you can go to this generate expression button here. If you need a little bit help with writing your link queries, you can actually click on this uh I already clicked but you can click on this text box above the expression text box and actually describe your link query. So right now um if you notice in this data I am seeing some of the cars which has negative num uh price. My hypothesis is that might be an issue why I'm not seeing all the cars. So I want to know all the cars which have a negative price. I'm just going to go here and say give all cars with negative price. And um what copilot will do is it will not just create a link expression here but it will also filter out. So this was a super simple example but you get an idea that when you have a complex data set you can write some complex query using that as well and do some custom filtration. So now we know we have some negative uh car price here that might be an issue why we are not seeing all the cars. So let's continue our investigation further. What I'm going to do is I'm going to go here disable my breakbook uh deb debugging and I'm going to go ahead and use my different break points for a different demo. I want to start my investigation from this adjust car price function. I I'm actually adjusting the car price based on some discount and everything. So I want to start it here. I placed a break point here on line 51. Now if you notice I if I this particular function is called from the generate car as well. So I might be hitting this breakpoint 300 times which I don't want to do. What I can do is I can convert this breakpoint to a conditional breakpoint. So with conditional breakpoint this breakpoint will only hit at particular condition. For me I want to see that the car price is negative. So what I can do is I can go right click on settings, go to conditions and I can write my condition here. Again you can write your own condition but if you need a little bit help writing your conditions or just want to get some ideas around what other conditions might work or if you're like me you just forget about the syntax and you wanted to remember about the syntax. What you can do is you can just um click here and copilot will actually come up with some of the suggestions that might work here. Now, it's not exactly giving me the condition I wanted, but I'm just going to go ahead and do zero because I want a price which is negative and I want this break point to head to wherever the price is negative. Now, my breakpoint here is a conditional breakpoint. Now, this um copilot suggestions also works great with trace points or some people call it lock points. So trace points are something you can actually use to lock certain type of information while you're debugging or while you're coding. And the best part, you don't have to remove that when you're pushing your changes to code. So you don't have any log messages or anything. So what I'm going to do is I'm going to convert this break point on line 81. This is where all the prices like uh the discounted prices I'm adding like discount price, uh the age discount, very old discount price is added. So I want to see all those prices. So I'm going to log this particular uh information here using trace point. So again go to settings and to do a trace point you go to actions and then as soon as you place your cursor here copilot can actually come up with suggestions. For now I'm just going to use my own statement here because I want all of the prices. So you'll see I have a trace point which is going to give me all the prices uh so I can quickly see what's going on. Now I'm going to start my debugging again and what I'm expecting is that the break point on line 51 will only hit if the price is negative and this lock point will actually tell me which particular price uh which particular discounted price have an issue. So let's try to see that. Okay. So you'll see the break point on line 51 is it. I'm expecting that the price is negative which is right. I'm going to go in the output here and you will see it also locked certain information about all the prices and you will see this very car very old car discounted price is negative and that might be the reason why we are getting our car price negative as well. My hypothesis is that I am actually doing some uh discounting uh logic here at the bottom. I'm adding some percentage discount to uh all these prices to adjust it. And maybe for the very card or discount, I'm actually not using percentage and the whole dollar amount and that might be an issue. But this was just a simple example to show you how you can use breakpoint, trace points or even data visualizers to come up with or find your bugs a little easier. Now before I um go to the next demo, I want to show one thing quickly. I'm going to go back to my break points again. Okay. Uh so we saw a little bit around link query. Uh a lot of times we also have link query in our code. Uh so for example I have again a super simple example to show you around a link query which inside in my code. So we recently added something called a link hover or a link visualizer. So whenever you have a link expression in your code with the link hover what you can do is uh you can hover over that link expression and you will see the filter data right there in the editor. Again you have all the options. You can actually just view the data using innumerable visualizer and then make sure your data is correct or when you hover over the last part of the link query like the full link query you have an option to see the data filter by the whole link query. The best part you can actually use the visualizers but you also have an option to analyze with copilot. So in case if your link query is not working correctly or you are seeing in result which is unexpected, you can analyze that with the copilot and copilot should be able to provide you some details around what's going on. So I'm not going to go there but just wanted to show you that quick option where you can actually also analyze link queries. So these were some of the examples around like basic features like breakpoint trace points. Now I wanted to show you something which we recently added and that is inline variable values. So for this I'm going to be using let me go back to program here. Okay I am going to be using another application. It is called an IoT monitoring system. It is a simple application that actually monitors the sensor temperature to check if it's right and if it's on the right location. Now this is my output. You will see I have an average temperature of 22.76 and then some of my sensors which actually has a correct temperature range like around 22 23 and are in a light in a correct location as well are flagged as anomaly while my test sensors are flagged as normal. So another clear bug here. So let's try to figure out what's going on. Before I go to the demo, I want to ask you how many of you actually create or have created temporary variables to track down the return values or the functions which the return values which are creating. So I used to do that too but now with the inline values you don't need to do it. So let's go back to the code here. Start my debugging again. So before I go to the bug I want to show you I have this break point on line 13. you'll see uh it has a function call for get sensor reading. I don't have any break points in there. Now if I want to see a returning value for this function, all I want to do is start my debugging, break on that line, step over and you should be able to see what that particular function is returning right there in the editor. The best part uh if this a complex object, you will have all the capabilities for the data types. So you can expand it, visualize your data and see if the data is correct or not. And it also has analyze with copilot again in case if you need to. Now coming to our bug you we saw like some of my correct sensors were flagged as anomaly and the test sensors were flagged as normal. I have this break point on line 21 here. This is an if statement where it's checking if the temperature is correct or the location is correct. I'm going to go ahead and enable it and continue my debugging here. And I want to take your attention here again for this for each loop. You will now see the data here in the editor again. And because it's an complex subject again, you should be able to pin your data which you wanted to see or like which you're interested. For me, the location and temperature is something which I was interested. So, I pin my data here. So, it's super easy to see when you're going through that loop. You don't need to hover your uh cursor anywhere. You should just able to see the data right there in the editor as you're debugging. Another thing I want to take your attention is this if statement. You will also see an if condition evaluation right there in the editor as well. So you'll see for me for this particular scenario the server room A with temperature 22 is giving true which is again a bug. But with uh with this you actually can just see the what the if statement is returning right there in the editor. You don't have to hover over or uh go um and figure out what's what's the evaluation is. Now um we saw that this is giving true that means something is going either in the is anomaly function or is location. I'm going to start my investigation with this is anomaly. Just going to go to the definition here. I'm going to enable my breakpoint here. Continuing my debugging. One more thing I wanted to show you is that you can also see the inline values for your function parameters. Again, we were able to see that this particular uh is anomaly has the temperature the the value of the temperature and the baseline. Again, a super handy way to see your data while you're debugging. Now if I step over it, you will see you are also seeing the return value here in the inline. So you don't have to create those temporary variables anymore and delete them later or forget to delete them later. And you will not just see the return value, but you'll also see a returning value here. Now for the temperature 22, I am getting the is anomaly true. That means something is wrong here. As I gave you a little bit hint there that all of these inline variable values has copilot assistance with it. What you can do is for me this particular uh value is not something I'm expecting. So I'm going to go ahead and actually click on analyze with copilot here and actually copilot will tell me why I'm seeing the value I'm seeing or why it is uh coming up true. So just going to confirm here. Also I forgot to give a uh warning before sometimes copilot work I as expect or sometimes it just have its own mind. So it's a live demo. I I'm expecting that it should work however I um I practice with my demos but if not that's copallet's fault. Um but you'll see here it's actually telling me that I am using this um comparison state comparison uh wrong. I should be using it greater than baseline uh while I'm using the less than baseline. So super simple example super simple mistake here but you saw with copilot you were able to find that pretty quickly again. Now, if you are one of those who actually likes to use your autos windows or locals windows or watch windows, you also have a copilot assistance in there as well. So, um in case if you're seeing any value in your autosatch windows which is unexpected, you can actually use this analyze with copilot button from those windows or even data tips to see why you're seeing the value you're seeing. or if you're just going in going in a newer code or a code you haven't touched in a while and you wanted to understand the code in that scenarios as well this is super helpful to know why you're seeing those variable values so this was in line variable values um now I'm going to go to my next demo going to stop my debugging so as I said in the starting that exception assistance is one of our very first feature which where we added copilot's assistant But you all know exceptions can be various types. It can be a simple exception, nested exception, very complex exception as well. So we have been adding a lot of improvements and adding and providing a lot of context to the exception assistant to make sure we get accurate responses and it works on its own whenever it needs to do a deeper analysis or just wanted to provide you a quick immediate fix. I'm going to be showing you three examples today. One is a very simple example where a c-pilot comes up with an immediate fix. We'll see another example where a co-pilot takes a little bit more time does a deeper analysis and then come up with a fix. And then the third example is where we are actually providing a repository context. So the repository you have open in your visual studio while you are working with exception helper and then it come ups with some context related to that. So my very first demo um I'm going to be using this serialization example. Just going to go ahead and execute this particular program here. And you will notice the very first thing I get is this exception. It is telling me that response status code does not indicate which is something else which I wasn't expecting but that's fine. This was copilot. Uh but okay. So this is a simple example here which is telling me something is wrong with my HTTP request exception. So what I can do is I'm going to go ahead and okay is click on analyze with copilot and with co uh what copilot will do here is gather all the necessary information and because we are actually directly clicking analyze with copilot from the exception helper we don't need to provide any additional context. It has all the context it needs to. If it needs to, it gathers more context and then come ups with a immediate fix or deeper analysis. So this one particularly I'm going to execute that again to see if it works as expect. So okay, this is perfect. I don't know what happened there, but this is the ex expect exception I was expecting. D serialization resulted in an empty object. So this is a simple exception. We get it a lot of time when you're doing d serialization. Again I'm using a default model here and going to go with analyze with copilot. As I was saying because we're clicking directly from here it has all the context related to it and it might gather more context as needed. for a simple exceptions it a lot of times what copilot does it it comes up with a lot of confirmations but it comes up with comes up with an immediate fix as well so it's telling me that the root cause here is um it's the API has a root object property which is an array and I'm actually assigning it to a list so this just wanted to give you a quick example like this was a very simple um exception and copilot was able to come up with an immediate fix. Sometimes there are exceptions which are not that simple as it is and even copilot needs a little bit time or more analysis to do that. I'm not going to go ahead and apply this change but this was just a quick show. And now let's go to another exception where we'll see how copilot actually comes up or needs a deeper analysis. So I'm going to execute another exception here. So you'll see I have an exception that is saying nullable object must have a value. Now my object is funk one here. If you notice in my autos window, I'm actually assigning a null to an integer type of funk one. That might be an issue as well because it's an integer type and I'm assigning null. To be very honest, I know this code. So I know that this particular uh funk one does not need to have null. It's actually having more than like it has has a value and the result is more than 10. So I'm just going to go ahead and try to investigate what is happening. I'm going to go into this funk one and see from where this is called. So go to definition and you'll see this funk one is actually called from funk two and I'm guessing the funk two must be called from funk three and then so on. This is a very common structure we can have in our production level code as well like one function is called from another and if there is an exception in one of those deeper function chain it might take a long time to investigate that I'm going to try this investigation using copilot here uh we saw that for previous exception helper example I used the default model we actually implemented uh some improvements recently so you can actually also use other model not just the premium model by or not just the standard model but premium model or whatever favorite model you have for your exception helper as well. So I'm going to go ahead with sonet 4 here and click on analyze with copilot. So as I said copilot has all the context from here and it will try to gather all the context and try to do some investigation at the start. >> [clears throat] >> We do need to ask a confirmation a lot of times to make sure that users know what copilot is doing and we are not changing anything without your permission. So a lot of times you'll see in some cases it's more confirmation, some cases it doesn't need that many. Okay. So it came up with a hypothesis and it's trying to find why the system the label value we are seeing and it's still doing its investigation there. And you'll see it is also trying some other approaches to find out the root cause. So this is what I wanted to show you that copilot did its initial investigation. and it came up with the hypothesis that funk one is an internal class. Um, and then it also asked me if I wanted to go deeper down to see the So, this is an immediate fix, but it also asked me that if I want to go deeper down to see what might be causing it. I'm just going to go ahead and do yes and see what copilot comes up with here. So it's going down to the whole chain. Uh I think I only showed till funk two or funk three but it has it's more nested than those two three functions. It's at funk 9 right now. It's okay. Okay. And then after going to the 15th iteration, it actually came up with a root cause uh that in funk 15 there is an issue. So as I said I just wanted to show you an example where like I think the 15th not a number is an a problem here but just wanted to show you an example that copilot actually or exception helper figured it out where it needs to do a deeper analysis or where it needs to just come up with an immediate fix. So uh this deeper analysis is actually very helpful when you have these nested kind of uh exceptions. You have a question. >> When it's doing all the analysis to try and go and figure out what's going on, is that is that co-pilot piece privatized to the code base that you have or is that something that's now publicly accessible? >> No, it is something it is related to the codebase I have. So the fun the exception I had is that nested. I had 15 functions there which is having an issue. Is that your question? Well, no. I'm just saying like >> co-pilot analyzes it does that make your source code then accessible to co-pilot to learn? >> Yes, we are providing the context to that. So the third example I wanted to show you is um we saw two examples like a simple exception and the nested ex exception. Uh this might be related to your question too like we added something called a repository context to the exception helper. So the repository you have open it will act the copilot will actually use the context related to that your open pull request your bugs similar types of bugs the issue you're seeing or similar bugs or issues which are fixed related to that and then it will come up with a solution related to the exception you're seeing. It might be little closer to what your team structure is because it's using a repository context but it is this is uh even with that it is not publicly available. It is still within the visual studio or the context related needed for the uh the copilot will be still for that particular session only. This demo I'm going to be showing a recorded version. It's a little difficult to show the demo with a repository context with PII issue. So hopefully we should get the audio. >> Today I'm going to demonstrate some improvements we've made to the debugger's exception analysis with copilot feature in Visual Studio. To start, I have a solution open and I've run into an exception. I've been doing some development in VS and I'm working on persisting options for some new features and I've noticed that it's not working. So I've run into this exception and I'm not really sure what's going on other than the call to save package user options seems to be failing. To start, let's run through the automated analysis. I haven't enabled our new features yet, so we can see what it looks like in the current state. Let's start the analysis and let Copilot start thinking. This will go through and use many of the tools it already has, like accessing files, evaluating variables, or checking the debug output to come up with some idea of what might be wrong. Now, we can see that this is providing us with some ideas of what to look at, but it's not providing an exact solution. We'd need to do a little bit more investigation to figure out what the root cause could be. We could continue in this conversation, but I'm going to change options now to show the new features would allow us to do. We go to our options for Visual Studio and we can enable this, which would be on by default, but was off for this demo. And we can turn on our new feature, which allows adding repo context to the exception analysis. And if we rerun the analysis now, we can see what differences we get. While this runs, I'll note that what this is going to end up doing is looking at the repo we currently have open and use that as a way to search for existing bugs, issues, pull requests, and incorporate them into the context of what we use to analyze this exception. So, this will run through. It'll ask permission to ask for a access content, and it will start looking for anything relevant. It's decided it wants to ask with different search terms. So, I'm going to always allow, so it doesn't need to ask again. Now it's come to a conclusion and we can see that it's giving a very different answer. We can see it's provided some specific information about what this H result is and what the likely problem is. Our name seems to be too long and if we look closely we can see it's referencing some bugs that have data about this. We can also use those to find more information about what other folks have run into and how they've fixed this or similar issues. So we saw like how when we provide more context copilot with the repository it can actually come up with a solution which is more closer to your repository or your team structures or your team styles of uh writing code. It also provides you similar issues which are fixed recently. So you have the code which is not completely different but it is related to what you have been fixing before as well. So these were some of the examples uh related to uh exception helper. Now I want to show you how you can actually investigate uh when you have a hang situation or you have a deadlock situation when you're dealing with multi-thread application. So let me go to a different project here. For this I'm going to be using a application called stock market where different cats for some reason are trying to do some trading. So let's try to I'm going to start this application and see what happens. You'll see they're just trying to sell and buy some stuff here and at some point this particular application is going to hang and nothing is going to happen. So I think we at that situation now we not going further. It's just hanged here and it's not working. What I'm going to do is I'm going to do break all. So I break on all the threads and that will help me find out what's going on. As soon as I do break all, you will see similar to exception helper, I actually see a dialogue which is telling me that a deadlock is detected and it provides me some little information here. It has couple ways you can actually go ahead from this dialogue and try to investigate. It has an analyze with copilot option and also a show parallel stack option. I'm going to go to the show parallel stacks option first. So if you have never used parallel stacks before, this is super handy tool when you deal with multi-threaded programming. It gives you this graphical view of your threads. So it's easy to see what's going on and easy to understand. Now in this thread, there are a couple ways that could be helpful to find out what is going on. First of all, you'll see these icons which actually right away telling me that which particular threads are deadlocked. Uh it gives me the warning as well. At each of the thread you will also notice that this uh sparkle button which is actually a co-pilot insight it actually gives me a summary of that thread. So again this isn't a simple example when you have a huge thread um it will actually give this the the summary of all the stacks. You don't have to go manually do and find out what is going on. For example for this worker thread it is telling me that deadlock is waiting for a lock. Let me go and see another example. for this particular thread it is telling me that waiting for the data from the network pride. So it's easy to see this summary and understand what that particular stack is doing. Another way here could be helpful to understand this particular hang situation is this generate inside button. So what this generate inside button does when I click on it copilot actually gives me a summary of what's going on why I'm seeing this hang or what I'm seeing this in particular diagram it gives me the details on what particular thread is deadlocked or who's waiting on which particular log and it also gives me some steps to investigate further. So again it is very easy way to understand or understand this diagram if you're not very familiar with it to see what is going on particularly in that diagram. Now going back to the I'm going to close this to this deadlock detected here. U similar to our previous example we also have this analyze with copilot option here. Once I click it, Copilot Hall has all the context of this hang situation or the deadlock situation and then it actually comes up with a summary of what's going on. Gives you an initial in uh data on like or initial information of what is happening and then actually it's asking me if I want if you want to suggest a lock ordering strategy to prevent the deadlock. I'm just going to go ahead and do yes and then copilot will work with you to figure out what is happening or how you can resolve this particular deadlock. It is actually it actually came up with a code uh which is helping me to resolve this lock situation. I'm not going to apply this but just wanted to show you that when you have these logs or hang situation having an a little bit of assistant could really help you move it a little faster because uh even with the parallel stacks diagram it can be sometime overwhelming to understand when you have lot of threads. So this was parallel stacks and multi-threaded programming and how you can use copilot to understand it a little better. So we saw a lot of examples so far where we saw I'm going to go ahead I'm clicking I'm going to give more instructions to copilot or I'm actually confirming a lot of stuff. So I am actually working with copilot in that particular scenarios. I wanted to show you two scenarios here with one is the debugger agent and another is the profiler agent where the agent takes a driver's seat. It still asks you for the confirmations where needed but it actually does everything. So you actually just have to wait and analyze and actually just review what the the the agent is doing. So for the first uh debugger agent, we recently added this functionality where you can use an agent to fix your failed test which is single click. So fail test is again very common. Uh most of us or a lot of everyone of us has a fail test. I'm going to go ahead to go and set up my startup project and going to go here in the text explorer. Just going to run it again. And you'll see all of my tests here are failed. Um, so I'm going to try to see if I can actually fix one of those using copilot. So what you need to do is uh on your fail test, you just need to do right click and do debug with copilot. When I say debug with copilot, it is not just going to go and fix it and give me the solution. It will actually show me detailed steps in the chat. It will actually start a new debugging session, place some break points if needed, and give me the step-by-step instructions in the chat too. So I know what the debugger agent is doing too. So I can even learn from that as well. When I click on the debug copilot, you will see in this chat here, it is getting the context it needs to and then it starts working. Um you'll see it's actually setting some temporary break points and starting a new debugging session here and it will come up with a initial hypothesis and propose a fix. It will go ahead and apply the fix as well as it's an agent and then rerun the test. Sometimes as even when we work you know like sometimes we apply a fix apply a fix and then it still does not work in case if it happens in this scenario like copilot come up with that immediate fix applied it and it actually failed um that particular uh fix is failed and the test does not pass the agent will actually make sure that it comes comes up to the root cause until and unless the test is passed. So it will go ahead uh come up with a correct fix and make sure that the test is passing. So it's come up with another hypothesis and it's actually validating. And let me go back to my text explorer and you'll see it also reran the test to show you that the test is passed. I'm just going to go ahead and rerun it again to make sure it passed correctly. And you saw just with just with single click we were able to fix this test using the debugger agent. Now as I said it just did not give me the fix or it just did not give the correct test. It gave me all the details in this chat. It is telling me how that the the break points are set. The debugger uh session is started. It removes all the break points after it is done uh fixing the test as well and as well. So it's a pretty good experience to work with your failed test. You're just not just getting the fix but you're also learning how to fix it. So this was the debugger agent on how you can actually fix your fail test using the debugger agent. Now I wanted to show you something called performance profiling agent. So lot of people or lot not everyone is a performance expert and that is exactly why we actually created a performance profiler agent. We wanted to make sure that anyone can actually optimize their code not just when you see a clo code is slow. You can actually optimize your code anytime when you have a newer feature completed or you're just test touching a code which is super old or your code is really slow. And to make that easy, we created a performance profiler agent. So it's super easy uh for anyone to just go and point the agent to the code and ask help me optimize this code. So uh unfortunately we couldn't show the demo in the keynote today with the internet issue but we have been actually using our performance profiler agent on the top 100 u opensource libraries to make sure the agent doesn't work on the toy application like I have but it also works on all the production level application as well and we were able to actually come up with the fixes on many libraries and actually submitted the PRs and all those insights were completely driven using the performance profiler agent for the demo. Today I'm going to be showing a application which I just created a couple days back and I want to make sure that it is working fine and just wanted to show you how the profiler agent work. I have this application called grocery store which is just uh managing some inventory in the grocery. There are a couple of ways actually you can invoke a performance profiler agent. You can just go to a copilot chart. So as I was saying there are multiple ways you can actually invoke a performance profiler agent. You can go to your co-pilot chat and you can just do add the rate profiler and ask a specific question related to profiler agent uh pro sorry ask a specific question related to your performance or your optimization or memory allocation or um related to your code or if you don't have a specific question you can just go to an agent mode and start asking any questions related to optimization as well. Now there is another way you can actually invoke a performance profiler. So if you are a regular user of uh uh profiling tools you if you have used our existing performing uh performance profiling tools in visual studio you also have I just want to show you this new experience here that this launch page actually gives you all the details about what particular tool you can use and you can see you have some flexible tools parallel tool and you also have this recommendation here where you can actually use a particular tool if you don't know which one to use it will actually give you a recommendation condition as well. I'm using a different version, but what I wanted to show you is that if you're a regular user of this particular launch page, you also have an option to invoke a performance profiler from here, which you can't see it, but you should be able to see that very soon in Visual Studios latest version. So, you have couple ways there. Or if you don't know anything about your performance profiling, you just wanted to try it out. Another super easy way is to just go to this icebreaker here and say suggest how how I can optimize my code. So just before before I click on this I wanted to tell you how the profiler agent work is we just not going and fixing your code and making it faster. We're also making sure that we are actually measuring it using benchmark.net benchmarks. So the profiler agent will actually have make sure your code has a performance uh benchmark.net benchmark. If it doesn't have that it will create a new suit for you and it will create related benchmark. Then it will make sure it runs the CPU uh profiling tool, CPU profiling tool or net allocation tool based on the question you ask and actually run those benchmark for that particular um insights which the tools give you to make to have a baseline. Then the profiler agent will actually come up with a solution and run those benchmark again to see how much we improved. So we are not just getting the the code fix there or the performance improvement there but we are also seeing the improvement right there in the in the editor or in your visual studio. So right now I'm just going to go ahead and ask a very generic question to the agent that suggests how I can optimize my code. I don't know anything about performance profiling and here what the agent will actually guide me through it. So what the agent is telling me here that I'm going to go ahead and run the profiler um analyze your code CPU usage and then summarize the profiler results by suggesting targeted optimization based on your findings. And it's asking me should I go ahead I'm just going to go say yes and then the profiler agent will run the profiler first to come up with some of the insights. This uses the existing profiling tool we have. So the agent uses the existing tools like CPU usage tool, a net allocation tool or memory usage tool to come up with the insights. So uh I have a very small application here but if you have a larger application you need to go ahead and stop your collection after you execute the particular performance issue because this is a super simple application. It just ran completely here and I didn't need to stop it. You'll see here it actually came up with some top functions top inside which this is a very generic view which you normally get even without a profiler agent and in the chat here it is telling me that uh it gathered some insights based and actually identified some of the issues which are there in the store management program main function and it is actually providing me two options actually optimize the program main uh for the better startup performance or investigate and optimize the loops for now. I'm just going to go ahead with the first one and see what the profiler Asian gives me. So, it is u gathering all the necessary context it needs to uh yes it's asking me if I can create the benchmarks which we can surely do. So as I said if it will try to find the benchmark if your code has it uh if if it has existingly if it doesn't have it will actually go ahead and create a new benchmark what it hasn't created yet. So it's going to the step one was to locate the issue or the insight and then the step two is to create a benchmark for the program. I'm just going to go ahead and do yes. So it will create a new benchmark suit as my current application doesn't have and you'll see right here in the solution explorer it create a benchmark suit it added needed dependencies it will resolve if there are any issue make sure the build is correct and the build is successful to go further so um it's creating the benchmark running benchmark sometimes can take a couple seconds. I think that's the only step. Normally that takes a little while. You'll also see the code the agent changed in the editor here. You don't have to click. Uh I think it does on its own but you still have an option in case if you wanted to revise it. Okay. So it is it ran the benchmark based on the existing code and it is telling me that the mean is 1.2 uh and now what it is telling me that next I will proceed with the optimization. So the insights which we saw in the start with the CPU usage tool, it will apply that insight and run this benchmark again to see how much improvement we have been doing in this create store method. So I'm going to go ahead and do yes here to apply the optimizations. So it's going to go ahead and apply uh fixes or the optimization to make sure the code is faster. Okay. And now the mean is uh 874.8 milliseconds. Uh that means it actually improved a little bit 1.2 microsconds which is not a great improvement yet but still we have something. uh a lot of times the improvement which we see with the profiler agent also depends on certain scenarios like I'm like it can get affected by some some external factors as well if I'm connected to my uh power card if I'm running multiple programs because it's a CPU usage but this gives you an idea on how you can actually use a profiler agent to just understand more about your code's performance or if you don't know anything about performance it just gives you a way to learn more about your performance and actually just optimize your code. Again, you don't have to be an expert to run the profiler agent and you don't have to wait for a particular scenario when the code is really really slow and then go and run it. You can run it anytime it's because it's super simple to run it. You can run it when you have a new code where you can run it when you just finished your feature and or just whenever you're trying to push your changes to the PR. Those were all the demos I had today. Uh, thank you so much. >> [music]

Need a transcript for another video?

Get free YouTube transcripts with timestamps, translation, and download options.

Transcript content is sourced from YouTube's auto-generated captions or AI transcription. All video content belongs to the original creators. Terms of Service · DMCA Contact

Next-Level Debugging with GitHub Copilot in Visual Studio...