0N/A/*
0N/A * CDDL HEADER START
0N/A *
0N/A * The contents of this file are subject to the terms
0N/A * of the Common Development and Distribution License
0N/A * (the "License"). You may not use this file except
0N/A * in compliance with the License.
0N/A *
0N/A * You can obtain a copy of the license at
0N/A * src/OPENSOLARIS.LICENSE
0N/A * or http://www.opensolaris.org/os/licensing.
0N/A * See the License for the specific language governing
0N/A * permissions and limitations under the License.
0N/A *
0N/A * When distributing Covered Code, include this CDDL
0N/A * HEADER in each file and include the License file at
0N/A * usr/src/OPENSOLARIS.LICENSE. If applicable,
0N/A * add the following below this CDDL HEADER, with the
0N/A * fields enclosed by brackets "[]" replaced with your
0N/A * own identifying information: Portions Copyright [yyyy]
0N/A * [name of copyright owner]
0N/A *
0N/A * CDDL HEADER END
0N/A */
0N/A
0N/A/*
0N/A * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
0N/A * Use is subject to license terms.
0N/A */
0N/A
0N/A/*
0N/A * change directory benchmark
0N/A */
0N/A
0N/A#include <unistd.h>
0N/A#include <stdio.h>
0N/A#include <stdlib.h>
0N/A
0N/A#include "libmicro.h"
0N/A
0N/A#define DEFAULTDIR "/"
0N/A#define MAXPATHLEN 1024
0N/A
0N/Astatic int optg = 0;
0N/A
0N/Astatic int dircount;
0N/Astatic char ** dirlist;
0N/A
0N/Aint
0N/Abenchmark_init()
0N/A{
0N/A (void) sprintf(lm_optstr, "g");
0N/A lm_tsdsize = 0;
0N/A
0N/A (void) sprintf(lm_usage,
0N/A " [-g] (do getcwd() also)\n"
0N/A " directory ... (default = %s)\n"
0N/A "notes: measures chdir() and (optionally) getcwd()",
0N/A DEFAULTDIR);
0N/A
0N/A (void) sprintf(lm_header, "%5s %5s", "dirs", "gets");
0N/A
0N/A return (0);
0N/A}
0N/A
0N/A/*ARGSUSED*/
0N/Aint
0N/Abenchmark_optswitch(int opt, char *optarg)
0N/A{
0N/A switch (opt) {
0N/A case 'g':
0N/A optg = 1;
0N/A break;
0N/A default:
0N/A return (-1);
0N/A }
0N/A return (0);
0N/A}
0N/A
0N/Aint
0N/Abenchmark_initrun()
0N/A{
0N/A extern int optind;
0N/A int i;
0N/A
0N/A dircount = lm_argc - optind;
0N/A if (dircount <= 0) {
0N/A dirlist = (char **)malloc(sizeof (char *));
0N/A dirlist[0] = DEFAULTDIR;
0N/A dircount = 1;
0N/A } else {
0N/A dirlist = (char **)malloc(dircount * sizeof (char *));
0N/A for (i = 0; i < dircount; i++) {
0N/A dirlist[i] = lm_argv[optind++];
0N/A }
0N/A }
0N/A
0N/A return (0);
0N/A}
0N/A
0N/A/*ARGSUSED*/
0N/Aint
0N/Abenchmark(void *tsd, result_t *res)
0N/A{
0N/A int i, j;
0N/A char buf[MAXPATHLEN];
0N/A
0N/A j = 0;
0N/A for (i = 0; i < lm_optB; i++) {
0N/A if (chdir(dirlist[j]) == -1)
0N/A res->re_errors++;
0N/A j++;
0N/A j %= dircount;
0N/A
0N/A if (optg && (getcwd(buf, MAXPATHLEN) == NULL)) {
0N/A res->re_errors++;
0N/A }
0N/A }
0N/A res->re_count = i;
0N/A
0N/A return (0);
0N/A}
0N/A
0N/Achar *
0N/Abenchmark_result()
0N/A{
0N/A static char result[256];
0N/A
0N/A (void) sprintf(result, "%5d %5s", dircount, optg ? "y" : "n");
0N/A
0N/A return (result);
0N/A}