1 /* PSPP - computes sample statistics.
2 Copyright (C) 2000 Free Software Foundation, Inc.
3 Written by Ben Pfaff <blp@gnu.org>.
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 #include <libpspp/pool.h>
22 #include <language/command.h>
29 #define N_ITERATIONS 8192
33 This is not exhaustive, but it can be useful. */
35 cmd_debug_pool (struct lexer *lexer UNUSED, struct dataset *ds UNUSED)
37 int seed = time (0) * 257 % 32768;
42 struct pool_mark m1, m2;
47 printf ("Random number seed: %d\n", seed);
50 printf ("Creating pool...\n");
51 pool = pool_create ();
53 printf ("Marking pool state...\n");
54 pool_mark (pool, &m1);
56 printf (" Populating pool with random-sized small objects...\n");
57 for (i = 0; i < N_ITERATIONS; i++)
59 size_t size = rand () % MAX_SUBALLOC;
60 void *p = pool_alloc (pool, size);
64 printf (" Marking pool state...\n");
65 pool_mark (pool, &m2);
67 printf (" Populating pool with random-sized small "
68 "and large objects...\n");
69 for (i = 0; i < N_ITERATIONS; i++)
71 size_t size = rand () % (2 * MAX_SUBALLOC);
72 void *p = pool_alloc (pool, size);
76 printf (" Releasing pool state...\n");
77 pool_release (pool, &m2);
79 printf (" Populating pool with random objects and gizmos...\n");
80 for (i = 0; i < N_FILES; i++)
83 for (i = 0; i < N_ITERATIONS; i++)
85 int type = rand () % 32;
89 if (files[cur_file] != NULL
90 && EOF == pool_fclose (pool, files[cur_file]))
91 printf ("error on fclose: %s\n", strerror (errno));
93 files[cur_file] = pool_fopen (pool, "/dev/null", "r");
95 if (++cur_file >= N_FILES)
99 pool_create_subpool (pool);
102 size_t size = rand () % (2 * MAX_SUBALLOC);
103 void *p = pool_alloc (pool, size);
108 printf ("Releasing pool state...\n");
109 pool_release (pool, &m1);
111 printf ("Destroying pool...\n");