Skip to content

Commit

Permalink
add examples to README
Browse files Browse the repository at this point in the history
  • Loading branch information
arvidn committed Dec 7, 2013
1 parent de33ec8 commit 1c0f933
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 29 deletions.
45 changes: 45 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,48 @@ To combine this information with the debug information for
more user-friendly output, use the struct_layout tool and
use the profile as input.

example usage
-------------

::
#include "access_profiler.hpp"
#include <stdio.h>
struct test : access_profiler::instrument_type<test>
{
test() : a(0), b(0) {}
char array[50];
int a;
int b;
};
int main(int argc, char* argv[])
{
test* t1 = new test;
for (int i = 0; i < 10; ++i)
{
++t1->a;
t1->b += t1->a;
}
printf("%d\n", t1->b);
delete t1;
}

example output
--------------

output from a debug build::

test
52: 31
56: 22

output from a release build::

test
52: 1

38 changes: 9 additions & 29 deletions test.cpp
Original file line number Diff line number Diff line change
@@ -1,46 +1,26 @@
#include "access_profiler.hpp"
#include <stdio.h>

using namespace access_profiler;

namespace foo
struct test : access_profiler::instrument_type<test>
{
struct test : instrument_type<test>
{
test() : a(0), b(0) {}
char array[50];
int a;
int b;
};
}

namespace bar
{
struct test2 : instrument_type<test2>
{
test2() : a(0), b(0) {}
char array[5000];
int a;
int b;
};
}
test() : a(0), b(0) {}
char array[50];
int a;
int b;
};

int main(int argc, char* argv[])
{
foo::test* t1 = new foo::test;
bar::test2* t2 = new bar::test2;
bar::test2* t3 = new bar::test2;
test* t1 = new test;

for (int i = 0; i < 10; ++i)
{
++t1->a;
t2->a += t1->a;
t3->b = t2->a;
t1->b += t1->a;
}

printf("%d\n", t1->b);

delete t1;
delete t2;
delete t3;
}

0 comments on commit 1c0f933

Please sign in to comment.