Project

General

Profile

Bug #1243 » xyiterate.c

simple program testing out tracef - Matthew Khouzam, 03/06/2020 09:35 PM

 
/*
* Copyright 2020 Ericsson
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#include <lttng/tracef.h>

const int X_SIZE = 3197;
const int Y_SIZE = 3197;
const int INIT_VALUE = 7;
const int MULT_VALUE = 62;

/*
* Make an array and iterate over it in both axes. Observe the memory effects
*/
int main()
{
int **picture;
picture = malloc(X_SIZE * sizeof(int *));
tracef("creating array");
for (int x = 0; x < X_SIZE; x++)
{
picture[x] = malloc(Y_SIZE * sizeof(int));
}
tracef("init");
for (int x = 0; x < X_SIZE; x++)
{
tracef("row");
for (int y = 0; y < Y_SIZE; y++)
{
picture[x][y] = INIT_VALUE;
}
}
tracef("traverse");
for (int x = 0; x < X_SIZE; x++)
{
tracef("row");
for (int y = 0; y < Y_SIZE; y++)
{
picture[x][y] *= MULT_VALUE;
}
}
tracef("delete");
for (int x = 0; x < X_SIZE; x++)
{
free(picture[x]);
}
free(picture);
tracef("done first array");
picture = malloc(X_SIZE * sizeof(int *));
tracef("creating second array");
for (int x = 0; x < X_SIZE; x++)
{
picture[x] = malloc(Y_SIZE * sizeof(int));
}
tracef("init second array");
for (int y = 0; y < Y_SIZE; y++)
{
tracef("row");
for (int x = 0; x < X_SIZE; x++)
{
picture[x][y] = INIT_VALUE;
}
}
tracef("traverse");
for (int y = 0; y < Y_SIZE; y++)
{
tracef("row");
for (int x = 0; x < X_SIZE; x++)
{
picture[x][y] *= MULT_VALUE;
}
}
tracef("delete");
for (int x = 0; x < X_SIZE; x++)
{
free(picture[x]);
}
free(picture);
tracef("done second array");
}
(6-6/7)