2 * "$Id: testspeed.c 5305 2006-03-18 03:05:12Z mike $"
4 * Scheduler speed test for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2005 by Easy Software Products.
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
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
26 * main() - Send multiple IPP requests and report on the average response
28 * do_test() - Run a test on a specific host...
29 * usage() - Show program usage...
33 * Include necessary headers...
39 #include <sys/types.h>
42 #include <cups/cups.h>
43 #include <cups/language.h>
44 #include <cups/debug.h>
52 static int do_test(const char *server
, http_encryption_t encryption
,
53 int requests
, int verbose
);
54 static void usage(void);
58 * 'main()' - Send multiple IPP requests and report on the average response
63 main(int argc
, /* I - Number of command-line arguments */
64 char *argv
[]) /* I - Command-line arguments */
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 */
75 double elapsed
; /* Elapsed time */
76 int verbose
; /* Verbosity */
80 * Parse command-line options...
85 server
= cupsServer();
86 encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
89 for (i
= 1; i
< argc
; i
++)
90 if (!strcmp(argv
[i
], "-c"))
96 children
= atoi(argv
[i
]);
98 else if (!strcmp(argv
[i
], "-r"))
104 requests
= atoi(argv
[i
]);
106 else if (!strcmp(argv
[i
], "-E"))
107 encryption
= HTTP_ENCRYPT_REQUIRED
;
108 else if (!strcmp(argv
[i
], "-v"))
110 else if (argv
[i
][0] == '-')
116 * Then create child processes to act as clients...
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" : "");
127 do_test(server
, encryption
, requests
, verbose
);
131 for (i
= 0; i
< children
; i
++)
132 if ((pid
= fork()) == 0)
138 exit(do_test(server
, encryption
, requests
, verbose
));
142 perror("fork failed");
146 printf("testspeed(%d): Started...\n", pid
);
149 * Wait for children to finish...
156 if (pid
< 0 && errno
!= EINTR
)
159 printf("testspeed(%d): Ended (%d)...\n", pid
, status
);
164 * Compute the total run time...
168 elapsed
= end
- start
;
169 i
= children
* requests
;
171 printf("testspeed: %dx%d=%d requests in %.1fs (%.3fs/r, %.1fr/s)\n",
172 children
, requests
, i
, elapsed
, elapsed
/ i
, i
/ elapsed
);
175 * Exit with no errors...
183 * 'do_test()' - Run a test on a specific host...
186 static int /* O - Exit status */
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? */
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 */
199 double elapsed
; /* Elapsed time */
200 static ipp_op_t ops
[4] = /* Operations to test... */
210 * Connect to the server...
213 http
= httpConnectEncrypt(server
, ippPort(), encryption
);
217 perror("testspeed: unable to connect to server");
221 language
= cupsLangDefault();
224 * Do multiple requests...
227 for (elapsed
= 0.0, i
= 0; i
< requests
; i
++)
229 if (verbose
&& (i
% 10) == 0)
230 printf("testspeed(%d): %d%% complete...\n", (int)getpid(),
234 * Build a request which requires the following attributes:
237 * attributes-natural-language
239 * In addition, IPP_GET_JOBS needs a printer-uri attribute.
244 request
->request
.op
.operation_id
= ops
[i
& 3];
245 request
->request
.op
.request_id
= 1;
247 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
248 "attributes-charset", NULL
, cupsLangEncoding(language
));
250 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
251 "attributes-natural-language", NULL
, language
->language
);
253 gettimeofday(&start
, NULL
);
255 switch (request
->request
.op
.operation_id
)
258 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri",
259 NULL
, "ipp://localhost/printers/");
262 response
= cupsDoRequest(http
, request
, "/");
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");
273 gettimeofday(&end
, NULL
);
275 if (response
!= NULL
)
278 elapsed
+= (end
.tv_sec
- start
.tv_sec
) +
279 0.000001 * (end
.tv_usec
- start
.tv_usec
);
282 cupsLangFree(language
);
285 printf("testspeed(%d): %d requests in %.1fs (%.3fs/r, %.1fr/s)\n",
286 (int)getpid(), i
, elapsed
, elapsed
/ i
, i
/ elapsed
);
293 * 'usage()' - Show program usage...
299 puts("Usage: testspeed [-c children] [-h] [-r requests] [-v] [-E] hostname");
306 * End of "$Id: testspeed.c 5305 2006-03-18 03:05:12Z mike $".