]>
git.saurik.com Git - apple/xnu.git/blob - tools/tests/libMicro/apple/getaddrinfo_host.c
a7041753fbd1b1c14fc2f16b974b000615656ee8
2 * Copyright (c) 2006 Apple Inc. All Rights Reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
37 // add additional headers needed here.
39 #include "../libmicro.h"
42 # define debug(fmt, args...) (void) fprintf(stderr, fmt "\n" , ##args)
44 # define debug(fmt, args...)
51 // getaddrinfo_host -E -L -S -W -B 200 -C 100 -s "server%d"
53 // libMicro default benchmark run options are "-E -L -S -W -C 200"
55 // -B is batch size: loop iteration per each benchmark run. Needs to match # of
56 // real lookups. This is total number of lookups to issue.
57 // -C is min sample number: how many benchmark needs to run to get proper sample
58 // 1 is mimumum, but you get at least 3 benchmark run
59 // samples. Do not set to zero. Default is 200 for most
61 // -h is hostname format: for example, "server-%d.performance.rack"
62 // this is C language string format that can include %d
63 // -r hostname digit range in the form of "min-max". For example, -r 100-112
64 // With -h and -r, resulting hostnames are
65 // server-100.performance.rack - server-112.performance.rack
68 extern int gL1CacheEnabled
;
71 * Your state variables should live in the tsd_t struct below
76 #define HOSTNAME_LEN 125
77 static int host_min
=-1, host_range
=0;
78 static char *hostname_format
=NULL
;
79 static char *hostname_list
=NULL
;
84 debug("benchmark_init");
85 (void) sprintf(lm_optstr
, "l:h:r:");
87 lm_tsdsize
= sizeof (tsd_t
);
90 (void) sprintf(lm_usage
,
91 "\n ------- getaddrinfo_host specific options (default: *)\n"
92 " [-h \"hostname format\"]. ie. \"server-%%d.perf\"\n"
101 parse_range(int *min
, int *offset
, char *buf
)
103 char *value
, *tmp_ptr
= strdup(buf
);
105 debug("parse_range");
107 value
= strsep(&tmp_ptr
, "-");
109 debug("min = %d", *min
);
111 value
= strsep(&tmp_ptr
, "-");
114 printf("max id should be larger than min id\n");
117 *offset
= range
- *min
+ 1; // 1-based
118 debug("range = %d", *offset
);
121 printf("argument should be in the form of min-max\n");
130 * This is where you parse your lower-case arguments.
133 benchmark_optswitch(int opt
, char *optarg
)
135 debug("benchmark_optswitch");
138 case 'h': // hostname string format
139 hostname_format
= strdup(optarg
);
140 debug ("hostname format: %s", hostname_format
);
144 gL1CacheEnabled
= atoi(optarg
);
147 case 'r': // UID range
148 return parse_range( &host_min
, &host_range
, optarg
);
161 // Initialize all structures that will be used in benchmark()
168 debug("\nbenchmark_initrun");
170 if (host_min
== -1) {
171 printf("-r min-max needs to be specified\n");
175 if (!hostname_format
) {
176 printf("-h hostname_format needs to be specified\n");
180 hostname_list
= malloc ( host_range
* HOSTNAME_LEN
);
181 if (!hostname_list
) {
182 debug("malloc error");
186 for (i
= 0; i
< host_range
; i
++) {
187 sprintf( &hostname_list
[i
*HOSTNAME_LEN
], hostname_format
, i
+host_min
);
188 // debug("hostname: %s", &hostname_list[i*HOSTNAME_LEN]);
195 benchmark(void *tsd
, result_t
*res
)
198 struct addrinfo
*addi
;
202 debug("in to benchmark - optB = %i", lm_optB
);
205 for (i
= 0; i
< lm_optB
; i
++) {
206 index
= HOSTNAME_LEN
* (random() % host_range
);
208 err
= getaddrinfo( &hostname_list
[index
], NULL
, NULL
, &addi
);
211 debug("%s: error: %s", &hostname_list
[index
], gai_strerror(err
));
215 debug("host %s done", &hostname_list
[index
]);
225 // We need to release all the structures we allocated in benchmark_initrun()
227 benchmark_finirun(void *tsd
)
229 // tsd_t *ts = (tsd_t *)tsd;
230 debug("benchmark_finirun ");
240 static char result
= '\0';
241 debug("benchmark_result");