]>
Commit | Line | Data |
---|---|---|
ef416fc2 | 1 | /* |
c07d5b2d | 2 | * "$Id: testspeed.c 177 2006-06-21 00:20:03Z jlovell $" |
ef416fc2 | 3 | * |
4 | * Scheduler speed test for the Common UNIX Printing System (CUPS). | |
5 | * | |
6 | * Copyright 1997-2005 by Easy Software Products. | |
7 | * | |
8 | * These coded instructions, statements, and computer programs are the | |
9 | * property of Easy Software Products and are protected by Federal | |
10 | * copyright law. Distribution and use rights are outlined in the file | |
11 | * "LICENSE.txt" which should have been included with this file. If this | |
12 | * file is missing or damaged please contact Easy Software Products | |
13 | * at: | |
14 | * | |
15 | * Attn: CUPS Licensing Information | |
16 | * Easy Software Products | |
17 | * 44141 Airport View Drive, Suite 204 | |
18 | * Hollywood, Maryland 20636 USA | |
19 | * | |
20 | * Voice: (301) 373-9600 | |
21 | * EMail: cups-info@cups.org | |
22 | * WWW: http://www.cups.org | |
23 | * | |
24 | * Contents: | |
25 | * | |
e1d6a774 | 26 | * main() - Send multiple IPP requests and report on the average response |
27 | * time. | |
28 | * do_test() - Run a test on a specific host... | |
29 | * usage() - Show program usage... | |
ef416fc2 | 30 | */ |
31 | ||
32 | /* | |
33 | * Include necessary headers... | |
34 | */ | |
35 | ||
36 | #include <stdio.h> | |
37 | #include <stdlib.h> | |
38 | #include <ctype.h> | |
39 | #include <sys/types.h> | |
40 | #include <sys/time.h> | |
41 | #include <sys/wait.h> | |
42 | #include <cups/cups.h> | |
43 | #include <cups/language.h> | |
44 | #include <cups/debug.h> | |
45 | #include <errno.h> | |
46 | ||
47 | ||
48 | /* | |
49 | * Local functions... | |
50 | */ | |
51 | ||
e1d6a774 | 52 | static int do_test(const char *server, http_encryption_t encryption, |
53 | int requests, int verbose); | |
54 | static void usage(void); | |
ef416fc2 | 55 | |
56 | ||
57 | /* | |
58 | * 'main()' - Send multiple IPP requests and report on the average response | |
59 | * time. | |
60 | */ | |
61 | ||
62 | int | |
63 | main(int argc, /* I - Number of command-line arguments */ | |
64 | char *argv[]) /* I - Command-line arguments */ | |
65 | { | |
66 | int i; /* Looping var */ | |
67 | const char *server; /* Server to use */ | |
68 | http_encryption_t encryption; /* Encryption to use */ | |
69 | int requests; /* Number of requests to send */ | |
70 | int children; /* Number of children to fork */ | |
71 | int pid; /* Child PID */ | |
72 | int status; /* Child status */ | |
73 | time_t start, /* Start time */ | |
74 | end; /* End time */ | |
75 | double elapsed; /* Elapsed time */ | |
76 | int verbose; /* Verbosity */ | |
77 | ||
78 | ||
79 | /* | |
80 | * Parse command-line options... | |
81 | */ | |
82 | ||
83 | requests = 100; | |
84 | children = 5; | |
85 | server = cupsServer(); | |
86 | encryption = HTTP_ENCRYPT_IF_REQUESTED; | |
87 | verbose = 0; | |
88 | ||
89 | for (i = 1; i < argc; i ++) | |
90 | if (!strcmp(argv[i], "-c")) | |
91 | { | |
92 | i ++; | |
93 | if (i >= argc) | |
94 | usage(); | |
95 | ||
96 | children = atoi(argv[i]); | |
97 | } | |
98 | else if (!strcmp(argv[i], "-r")) | |
99 | { | |
100 | i ++; | |
101 | if (i >= argc) | |
102 | usage(); | |
103 | ||
104 | requests = atoi(argv[i]); | |
105 | } | |
106 | else if (!strcmp(argv[i], "-E")) | |
107 | encryption = HTTP_ENCRYPT_REQUIRED; | |
108 | else if (!strcmp(argv[i], "-v")) | |
109 | verbose ++; | |
110 | else if (argv[i][0] == '-') | |
111 | usage(); | |
112 | else | |
113 | server = argv[i]; | |
114 | ||
115 | /* | |
116 | * Then create child processes to act as clients... | |
117 | */ | |
118 | ||
119 | printf("testspeed: Simulating %d clients with %d requests to %s with %s encryption...\n", | |
120 | children, requests, server, | |
121 | encryption == HTTP_ENCRYPT_IF_REQUESTED ? "no" : ""); | |
122 | ||
123 | start = time(NULL); | |
124 | ||
125 | if (children == 1) | |
126 | { | |
127 | do_test(server, encryption, requests, verbose); | |
128 | } | |
129 | else | |
130 | { | |
131 | for (i = 0; i < children; i ++) | |
132 | if ((pid = fork()) == 0) | |
133 | { | |
134 | /* | |
135 | * Child goes here... | |
136 | */ | |
137 | ||
138 | exit(do_test(server, encryption, requests, verbose)); | |
139 | } | |
140 | else if (pid < 0) | |
141 | { | |
142 | perror("fork failed"); | |
143 | break; | |
144 | } | |
145 | else | |
146 | printf("testspeed(%d): Started...\n", pid); | |
147 | ||
148 | /* | |
149 | * Wait for children to finish... | |
150 | */ | |
151 | ||
152 | for (;;) | |
153 | { | |
154 | pid = wait(&status); | |
155 | ||
156 | if (pid < 0 && errno != EINTR) | |
157 | break; | |
158 | ||
159 | printf("testspeed(%d): Ended (%d)...\n", pid, status); | |
160 | } | |
161 | } | |
162 | ||
163 | /* | |
164 | * Compute the total run time... | |
165 | */ | |
166 | ||
167 | end = time(NULL); | |
168 | elapsed = end - start; | |
169 | i = children * requests; | |
170 | ||
171 | printf("testspeed: %dx%d=%d requests in %.1fs (%.3fs/r, %.1fr/s)\n", | |
172 | children, requests, i, elapsed, elapsed / i, i / elapsed); | |
173 | ||
174 | /* | |
175 | * Exit with no errors... | |
176 | */ | |
177 | ||
178 | return (status); | |
179 | } | |
180 | ||
181 | ||
182 | /* | |
183 | * 'do_test()' - Run a test on a specific host... | |
184 | */ | |
185 | ||
e1d6a774 | 186 | static int /* O - Exit status */ |
ef416fc2 | 187 | do_test(const char *server, /* I - Server to use */ |
188 | http_encryption_t encryption, /* I - Encryption to use */ | |
189 | int requests, /* I - Number of requests to send */ | |
190 | int verbose) /* I - Verbose output? */ | |
191 | { | |
192 | int i; /* Looping var */ | |
193 | http_t *http; /* Connection to server */ | |
194 | ipp_t *request, /* IPP Request */ | |
195 | *response; /* IPP Response */ | |
196 | cups_lang_t *language; /* Default language */ | |
197 | struct timeval start, /* Start time */ | |
198 | end; /* End time */ | |
199 | double elapsed; /* Elapsed time */ | |
200 | static ipp_op_t ops[4] = /* Operations to test... */ | |
201 | { | |
202 | IPP_PRINT_JOB, | |
203 | CUPS_GET_PRINTERS, | |
204 | CUPS_GET_CLASSES, | |
205 | IPP_GET_JOBS | |
206 | }; | |
207 | ||
208 | ||
209 | /* | |
210 | * Connect to the server... | |
211 | */ | |
212 | ||
213 | http = httpConnectEncrypt(server, ippPort(), encryption); | |
214 | ||
215 | if (http == NULL) | |
216 | { | |
217 | perror("testspeed: unable to connect to server"); | |
218 | return (1); | |
219 | } | |
220 | ||
221 | language = cupsLangDefault(); | |
222 | ||
223 | /* | |
224 | * Do multiple requests... | |
225 | */ | |
226 | ||
227 | for (elapsed = 0.0, i = 0; i < requests; i ++) | |
228 | { | |
229 | if (verbose && (i % 10) == 0) | |
230 | printf("testspeed(%d): %d%% complete...\n", (int)getpid(), | |
231 | i * 100 / requests); | |
232 | ||
233 | /* | |
234 | * Build a request which requires the following attributes: | |
235 | * | |
236 | * attributes-charset | |
237 | * attributes-natural-language | |
238 | * | |
239 | * In addition, IPP_GET_JOBS needs a printer-uri attribute. | |
240 | */ | |
241 | ||
242 | request = ippNew(); | |
243 | ||
244 | request->request.op.operation_id = ops[i & 3]; | |
245 | request->request.op.request_id = 1; | |
246 | ||
247 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET, | |
248 | "attributes-charset", NULL, cupsLangEncoding(language)); | |
249 | ||
250 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE, | |
251 | "attributes-natural-language", NULL, language->language); | |
252 | ||
253 | gettimeofday(&start, NULL); | |
254 | ||
255 | switch (request->request.op.operation_id) | |
256 | { | |
257 | case IPP_GET_JOBS : | |
258 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", | |
259 | NULL, "ipp://localhost/printers/"); | |
260 | ||
261 | default : | |
262 | response = cupsDoRequest(http, request, "/"); | |
263 | break; | |
264 | ||
265 | case IPP_PRINT_JOB : | |
266 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", | |
267 | NULL, "ipp://localhost/printers/test"); | |
268 | response = cupsDoFileRequest(http, request, "/printers/test", | |
269 | "../data/testprint.ps"); | |
270 | break; | |
271 | } | |
272 | ||
273 | gettimeofday(&end, NULL); | |
274 | ||
275 | if (response != NULL) | |
276 | ippDelete(response); | |
277 | ||
278 | elapsed += (end.tv_sec - start.tv_sec) + | |
279 | 0.000001 * (end.tv_usec - start.tv_usec); | |
280 | } | |
281 | ||
282 | cupsLangFree(language); | |
283 | httpClose(http); | |
284 | ||
285 | printf("testspeed(%d): %d requests in %.1fs (%.3fs/r, %.1fr/s)\n", | |
286 | (int)getpid(), i, elapsed, elapsed / i, i / elapsed); | |
287 | ||
288 | return (0); | |
289 | } | |
290 | ||
291 | ||
292 | /* | |
293 | * 'usage()' - Show program usage... | |
294 | */ | |
295 | ||
e1d6a774 | 296 | static void |
ef416fc2 | 297 | usage(void) |
298 | { | |
299 | puts("Usage: testspeed [-c children] [-h] [-r requests] [-v] [-E] hostname"); | |
300 | exit(0); | |
301 | } | |
302 | ||
303 | ||
304 | ||
305 | /* | |
c07d5b2d | 306 | * End of "$Id: testspeed.c 177 2006-06-21 00:20:03Z jlovell $". |
ef416fc2 | 307 | */ |