2 * "$Id: testspeed.c 4800 2005-10-18 18:06:20Z 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
31 * Include necessary headers...
37 #include <sys/types.h>
40 #include <cups/cups.h>
41 #include <cups/language.h>
42 #include <cups/debug.h>
50 int do_test(const char *server
, http_encryption_t encryption
,
51 int requests
, int verbose
);
56 * 'main()' - Send multiple IPP requests and report on the average response
61 main(int argc
, /* I - Number of command-line arguments */
62 char *argv
[]) /* I - Command-line arguments */
64 int i
; /* Looping var */
65 const char *server
; /* Server to use */
66 http_encryption_t encryption
; /* Encryption to use */
67 int requests
; /* Number of requests to send */
68 int children
; /* Number of children to fork */
69 int pid
; /* Child PID */
70 int status
; /* Child status */
71 time_t start
, /* Start time */
73 double elapsed
; /* Elapsed time */
74 int verbose
; /* Verbosity */
78 * Parse command-line options...
83 server
= cupsServer();
84 encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
87 for (i
= 1; i
< argc
; i
++)
88 if (!strcmp(argv
[i
], "-c"))
94 children
= atoi(argv
[i
]);
96 else if (!strcmp(argv
[i
], "-r"))
102 requests
= atoi(argv
[i
]);
104 else if (!strcmp(argv
[i
], "-E"))
105 encryption
= HTTP_ENCRYPT_REQUIRED
;
106 else if (!strcmp(argv
[i
], "-v"))
108 else if (argv
[i
][0] == '-')
114 * Then create child processes to act as clients...
117 printf("testspeed: Simulating %d clients with %d requests to %s with %s encryption...\n",
118 children
, requests
, server
,
119 encryption
== HTTP_ENCRYPT_IF_REQUESTED
? "no" : "");
125 do_test(server
, encryption
, requests
, verbose
);
129 for (i
= 0; i
< children
; i
++)
130 if ((pid
= fork()) == 0)
136 exit(do_test(server
, encryption
, requests
, verbose
));
140 perror("fork failed");
144 printf("testspeed(%d): Started...\n", pid
);
147 * Wait for children to finish...
154 if (pid
< 0 && errno
!= EINTR
)
157 printf("testspeed(%d): Ended (%d)...\n", pid
, status
);
162 * Compute the total run time...
166 elapsed
= end
- start
;
167 i
= children
* requests
;
169 printf("testspeed: %dx%d=%d requests in %.1fs (%.3fs/r, %.1fr/s)\n",
170 children
, requests
, i
, elapsed
, elapsed
/ i
, i
/ elapsed
);
173 * Exit with no errors...
181 * 'do_test()' - Run a test on a specific host...
184 int /* O - Exit status */
185 do_test(const char *server
, /* I - Server to use */
186 http_encryption_t encryption
, /* I - Encryption to use */
187 int requests
, /* I - Number of requests to send */
188 int verbose
) /* I - Verbose output? */
190 int i
; /* Looping var */
191 http_t
*http
; /* Connection to server */
192 ipp_t
*request
, /* IPP Request */
193 *response
; /* IPP Response */
194 cups_lang_t
*language
; /* Default language */
195 struct timeval start
, /* Start time */
197 double elapsed
; /* Elapsed time */
198 static ipp_op_t ops
[4] = /* Operations to test... */
208 * Connect to the server...
211 http
= httpConnectEncrypt(server
, ippPort(), encryption
);
215 perror("testspeed: unable to connect to server");
219 language
= cupsLangDefault();
222 * Do multiple requests...
225 for (elapsed
= 0.0, i
= 0; i
< requests
; i
++)
227 if (verbose
&& (i
% 10) == 0)
228 printf("testspeed(%d): %d%% complete...\n", (int)getpid(),
232 * Build a request which requires the following attributes:
235 * attributes-natural-language
237 * In addition, IPP_GET_JOBS needs a printer-uri attribute.
242 request
->request
.op
.operation_id
= ops
[i
& 3];
243 request
->request
.op
.request_id
= 1;
245 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
246 "attributes-charset", NULL
, cupsLangEncoding(language
));
248 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
249 "attributes-natural-language", NULL
, language
->language
);
251 gettimeofday(&start
, NULL
);
253 switch (request
->request
.op
.operation_id
)
256 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri",
257 NULL
, "ipp://localhost/printers/");
260 response
= cupsDoRequest(http
, request
, "/");
264 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri",
265 NULL
, "ipp://localhost/printers/test");
266 response
= cupsDoFileRequest(http
, request
, "/printers/test",
267 "../data/testprint.ps");
271 gettimeofday(&end
, NULL
);
273 if (response
!= NULL
)
276 elapsed
+= (end
.tv_sec
- start
.tv_sec
) +
277 0.000001 * (end
.tv_usec
- start
.tv_usec
);
280 cupsLangFree(language
);
283 printf("testspeed(%d): %d requests in %.1fs (%.3fs/r, %.1fr/s)\n",
284 (int)getpid(), i
, elapsed
, elapsed
/ i
, i
/ elapsed
);
291 * 'usage()' - Show program usage...
297 puts("Usage: testspeed [-c children] [-h] [-r requests] [-v] [-E] hostname");
304 * End of "$Id: testspeed.c 4800 2005-10-18 18:06:20Z mike $".