Visual studio help

Apr 20, 2020 at 2:13pm
Sorry to ask this here as its not really a c++ question, I only know of this site and stack overflow, and i hate asking questions there. I need to do performance testing and metrics testing of a piece of code, and I have never done this before. I have looked up metric testing in visual studio and found the site below, which tells me how to do it, but it says "results are generated and the Code Metrics Results window is displayed" but I do not see any results and have no idea where I would find this results window, it says in the hierarchy, but im not sure where that is either. I am using vs17, could someone possibly help me out, where I should be looking to find these results?

https://docs.microsoft.com/en-us/visualstudio/code-quality/how-to-generate-code-metrics-data?view=vs-2019#calculate-code-metrics-menu-command

Apr 20, 2020 at 2:22pm
I have never used it but on View->Other windows there is sth. called Code Metrics Result.
Maybe that's what you are looking for.
Apr 20, 2020 at 2:31pm
Thank you, I dont seem to have any results there, but I'm guessing that's something I done wrong, and that is the correct window. Thanks again.
Apr 20, 2020 at 2:42pm
Did you enable Code Analysis on Bild on the project settings ?
Apr 20, 2020 at 2:44pm
Is your code managed code? If it isn't code metrics probably won't do a thing for you.

A higher level link might be more helpful than where you landed.
https://docs.microsoft.com/en-us/visualstudio/code-quality/?view=vs-2019
Apr 20, 2020 at 2:45pm
uh, I guess I didnt, I am not sure how i would do that
Apr 20, 2020 at 2:52pm
Without sounding like a complete idiot, im not completely sure what you mean by manged code, Its written in c++ and all runs? :/
Apr 20, 2020 at 2:56pm
Managed code is code that runs on .NET or .Net Core
Code written in C, C++ or Pascal is considered unmanaged code.
Apr 20, 2020 at 3:04pm
C++ code can be managed. CAN BE.

https://www.developer.com/net/cplus/article.php/2197621/Managed-Unmanaged-Native-What-Kind-of-Code-Is-This.htm

If you don't know if your code is managed, it probably isn't.

I know I don't bother with doing managed code, I avoid it like the plague.

FYI, this is more a Windows or Lounge type topic, not something for the Beginners forum.
Apr 20, 2020 at 3:05pm
Oh ok, I wonder how I was expected to do metrics on it then. Oh well
Apr 20, 2020 at 3:13pm
Code ANALYSIS, finding code defects, can be done on unmanaged C++ code. Code Metrics is a Managed Code feature from what I can suss out.

VS 2017 and 2019 analyze C++ code for errors without doing anything other than creating the code and trying to compile it.
Apr 20, 2020 at 3:30pm
I was meant to do metrics and performance testing, I guess I will just need to do the performance testing if i can figure it out, and obviously leave out the metrics. thanks for the help though.
Apr 20, 2020 at 3:56pm
CppCheck might be option: http://cppcheck.sourceforge.net/
Apr 20, 2020 at 4:27pm
thank you, i will check that
Apr 20, 2020 at 5:17pm
if its not gigantic you can do your own if you want metrics. I mean, all you usually want is # of calls made to a function, average time, longest time, and maybe 'was longest time the first call' (so you can know to ignore cache or setup or other one-offs that are not an indication of an issue). If you tie it with macros you can get the function name, cpp file name, etc on some platforms (most?) and just have one generic line at the start and stop of every function.
Last edited on Apr 20, 2020 at 5:19pm
Apr 21, 2020 at 11:16am
I got the static code analysis work.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int add(const int num1, const int num2)
{
  return num1 + num2;
}

int main()
{

}

Output:

Warning	C26440	Function 'add' can be declared 'noexcept' (f.6).	
Warning	C26497	The function 'add' could be marked constexpr 
Warning	C26440	Function 'main' can be declared 'noexcept' (f.6).	


https://www.youtube.com/watch?v=1FAcPvb0ZjU
Topic archived. No new replies allowed.