1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 2000 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/>. */
18 #include <libpspp/pool.h>
19 #include <language/command.h>
26 #define N_ITERATIONS 8192
30 This is not exhaustive, but it can be useful. */
32 cmd_debug_pool (struct lexer *lexer UNUSED, struct dataset *ds UNUSED)
34 int seed = time (0) * 257 % 32768;
39 struct pool_mark m1, m2;
44 printf ("Random number seed: %d\n", seed);
47 printf ("Creating pool...\n");
48 pool = pool_create ();
50 printf ("Marking pool state...\n");
51 pool_mark (pool, &m1);
53 printf (" Populating pool with random-sized small objects...\n");
54 for (i = 0; i < N_ITERATIONS; i++)
56 size_t size = rand () % MAX_SUBALLOC;
57 void *p = pool_alloc (pool, size);
61 printf (" Marking pool state...\n");
62 pool_mark (pool, &m2);
64 printf (" Populating pool with random-sized small "
65 "and large objects...\n");
66 for (i = 0; i < N_ITERATIONS; i++)
68 size_t size = rand () % (2 * MAX_SUBALLOC);
69 void *p = pool_alloc (pool, size);
73 printf (" Releasing pool state...\n");
74 pool_release (pool, &m2);
76 printf (" Populating pool with random objects and gizmos...\n");
77 for (i = 0; i < N_FILES; i++)
80 for (i = 0; i < N_ITERATIONS; i++)
82 int type = rand () % 32;
86 if (files[cur_file] != NULL
87 && EOF == pool_fclose (pool, files[cur_file]))
88 printf ("error on fclose: %s\n", strerror (errno));
90 files[cur_file] = pool_fopen (pool, "/dev/null", "r");
92 if (++cur_file >= N_FILES)
96 pool_create_subpool (pool);
99 size_t size = rand () % (2 * MAX_SUBALLOC);
100 void *p = pool_alloc (pool, size);
105 printf ("Releasing pool state...\n");
106 pool_release (pool, &m1);
108 printf ("Destroying pool...\n");