1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 2000, 2011 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
25 #include "libpspp/pool.h"
26 #include "language/command.h"
28 #define N_ITERATIONS 8192
32 This is not exhaustive, but it can be useful. */
34 cmd_debug_pool (struct lexer *lexer UNUSED, struct dataset *ds UNUSED)
36 int seed = time (0) * 257 % 32768;
41 struct pool_mark m1, m2;
46 printf ("Random number seed: %d\n", seed);
49 printf ("Creating pool...\n");
50 pool = pool_create ();
52 printf ("Marking pool state...\n");
53 pool_mark (pool, &m1);
55 printf (" Populating pool with random-sized small objects...\n");
56 for (i = 0; i < N_ITERATIONS; i++)
58 size_t size = rand () % MAX_SUBALLOC;
59 void *p = pool_alloc (pool, size);
63 printf (" Marking pool state...\n");
64 pool_mark (pool, &m2);
66 printf (" Populating pool with random-sized small "
67 "and large objects...\n");
68 for (i = 0; i < N_ITERATIONS; i++)
70 size_t size = rand () % (2 * MAX_SUBALLOC);
71 void *p = pool_alloc (pool, size);
75 printf (" Releasing pool state...\n");
76 pool_release (pool, &m2);
78 printf (" Populating pool with random objects and gizmos...\n");
79 for (i = 0; i < N_FILES; i++)
82 for (i = 0; i < N_ITERATIONS; i++)
84 int type = rand () % 32;
88 if (files[cur_file] != NULL
89 && EOF == pool_fclose (pool, files[cur_file]))
90 printf ("error on fclose: %s\n", strerror (errno));
92 files[cur_file] = pool_fopen (pool, "/dev/null", "r");
94 if (++cur_file >= N_FILES)
98 pool_create_subpool (pool);
101 size_t size = rand () % (2 * MAX_SUBALLOC);
102 void *p = pool_alloc (pool, size);
107 printf ("Releasing pool state...\n");
108 pool_release (pool, &m1);
110 printf ("Destroying pool...\n");