Reputation: 436
I am using Visual Studio Entreprise 2015.
I want to profile a simple program (basically revisiting What every programmer should know about memory on my processor).
So I created the little program below :
#include <iostream>
#include "Header.h"
using namespace std;
void simpleReadWalk(l* start, int nb) {
struct l* c = start;
for (int i = 0; i < nb; i++) {
c = c->n;
}
}
int main() {
int size = sizeof(struct l);
int wsSize = 1 << 25; // working set size 2^10
int nb = wsSize / size;
struct l* start = new struct l;
struct l* current = start;
for (int i = 0; i < nb - 1; i++) {
struct l* nextone = new struct l;
current->n = nextone;
current = nextone;
}
simpleReadWalk(start, nb);
}
When I launch a instrument profiling, let's say for observing the number of cycles to run the instructions (to be chosen in the performance profiling option), I have the following :
In this picture, I expected to have the function simpleReadWalk where i added a red question mark: I want the CPU counters values for this function and not the entire main !
I must add : I ticked : "add small functions" in the profiler options (which can be seen in the figure below).
What did I miss please ?
Thank you in advance.
Note : in order to have the profiler working I had to run the following as taken here, don't think this is a problem but who knows, and at worse this may help other people ending on that question:
vsperfcmd /admin:driver,install
vsperfcmd /admin:driver,start /admin:service,start
vsperfcmd /admin:security,allow,FullAccess,<myusernamegoeshere>
vsperfcmd /admin:driver,autostart,on
===================================
EDIT 1 :
@norisknofun made a very good remark : the simpleReadWalk method may simply not be linked.
Unfortunately, debug mode is not allowed in instrumentation mode. So it comes down to force the inclusion of the file in release using another trick.
I tried using the trick based on a double pragma instructions as per force visual studio to link all symbols in a lib file
The source code is as follows :
#include <iostream>
#include "Header.h"
#include <stdio.h>
using namespace std;
/**
* Access values in a sequential fashion but using their pointer.
*/
void simpleReadWalk(l start, int nb) {
#define FORCE_LINK_THIS(x) int force_link_##x = 0;
struct l c = start;
for (int i = 0; i < nb; i++) {
c = *(c.n);
}
}
/**
* Pack values in a array.
*/
void init(l* tab, int nb) {
#define FORCE_LINK_THAT(x) { extern int force_link_##x; force_link_##x = 1; }
for (int i = 0; i < nb; i++) {
struct l nextone;
tab[i] = nextone;
if (i > 0) {
tab[i - 1].n = &tab[i];
}
}
}
int main() {
const int k = 25; // k like in 2^k
const int size = sizeof(struct l);
const int wsSize = 1 << k; // working set size 2^25
const int nb = wsSize / size;
struct l * tab = new struct l[nb];
init(tab, nb);
simpleReadWalk(tab[0], nb);
}
Unfortunately, this leads to the same results. main and init function are seen, but not the simpleReadWalk function :
Maybe this is not surprising since that tread relates to excluded functions from libraries (and not core source code ?).
Therefore, following https://msdn.microsoft.com/en-us/library/bxwfs976(v=vs.140).aspx I tried to add the following option as follows in VS 2015 :
And this gives the same result : no trace of simpleReadWalk.
At this point :
/OPT:NOREF
does not work in release
.Upvotes: 0
Views: 633
Reputation: 879
You can :
std::cout << "hello\n";
at the end of simpleReadWalkAs you mentionned yourlself, desactivate optimisation (from O2to /Od : no optimation) can have impact on linkage.
Upvotes: 0