/* * Copyright (c) 2007 Red Hat, Inc. * All Rights Reserved. * * Written by Eric Sandeen * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ /* * stress & time sequential deep directory creation */ #include #include #include #include #include #include #include #include /* max 32 path components */ /* contains the current, steadily increasing, path components */ int pathvals[32]; /* full path creates we've completed */ unsigned long long pathcounter = 0; /* * depth controls recursion * path gets appended during recursion * max is the max value of any component */ int update_pathvals(int dir_depth, int max_subdirs) { int i; unsigned long long counter = pathcounter; // printf("update_pathvals\n"); for (i = dir_depth - 1; i >= 0; i--) { pathvals[i] = counter % max_subdirs; counter = counter / max_subdirs; // printf("pathvals[%d] is %03x\n", i, pathvals[i]); } pathcounter++; } int makepath(int dir_depth, int max_subdirs) { int i; int dirname_len = 3; char path[4096] = "."; /* MAXPATHLEN? */ char component[128] = ""; /* MAXNAMELEN? */ /* for now hardcode dirname len to 3, i.e. max 4096 subdirs */ for (i = 0; i < dir_depth; i++) { sprintf(component, "/%0*x", dirname_len, pathvals[i]); // printf("component %s\n", component); strcat(path, component); /* would be mkdir */ mkdir(path, 0777); // printf("mkdir %s\n", path); } return 0; } int main(int argc, char *argv[]) { int i, j; int dir_depth = 6; /* maximum dir components */ int max_subdirs = 4096; /* max subdirs of any dir */ int iter_size = 32768; /* how often do we check elapsed time */ int iterations = 100; /* and how many times we do it */ struct timeval start_time, end_time; /* if dir_depth * max_subdirs < batch_size * batches we'll wrap... */ for (i = 0; i < iterations; i++) { double elapsed; gettimeofday(&start_time, NULL); for (j = 0; j < iter_size; j++) { update_pathvals(dir_depth, max_subdirs); makepath(dir_depth, max_subdirs); } gettimeofday(&end_time, NULL); elapsed = 1000000ULL * (end_time.tv_sec - start_time.tv_sec) + (end_time.tv_usec - start_time.tv_usec); printf("iter %d: %lf sec\n", i, elapsed / 1000000); } return 0; }