2 * "$Id: testspeed.c,v 1.10 2004/10/04 19:40:35 mike Exp $"
4 * Scheduler speed test for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2004 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
,
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 */
77 * Parse command-line options...
82 server
= cupsServer();
83 encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
85 for (i
= 1; i
< argc
; i
++)
86 if (!strcmp(argv
[i
], "-c"))
92 children
= atoi(argv
[i
]);
94 else if (!strcmp(argv
[i
], "-r"))
100 requests
= atoi(argv
[i
]);
102 else if (!strcmp(argv
[i
], "-E"))
103 encryption
= HTTP_ENCRYPT_REQUIRED
;
104 else if (argv
[i
][0] == '-')
110 * Then create child processes to act as clients...
113 printf("testspeed: Simulating %d clients with %d requests to %s with %s encryption...\n",
114 children
, requests
, server
,
115 encryption
== HTTP_ENCRYPT_IF_REQUESTED
? "no" : "");
119 for (i
= 0; i
< children
; i
++)
120 if ((pid
= fork()) == 0)
126 exit(do_test(server
, encryption
, requests
));
130 perror("fork failed");
134 printf("testspeed(%d): Started...\n", pid
);
137 * Wait for children to finish...
144 if (pid
< 0 && errno
!= EINTR
)
147 printf("testspeed(%d): Ended (%d)...\n", pid
, status
);
151 * Compute the total run time...
155 elapsed
= end
- start
;
156 i
= children
* requests
;
158 printf("testspeed: %dx%d=%d requests in %.1fs (%.3fs/r, %.1fr/s)\n",
159 children
, requests
, i
, elapsed
, elapsed
/ i
, i
/ elapsed
);
162 * Exit with no errors...
170 * 'do_test()' - Run a test on a specific host...
173 int /* O - Exit status */
174 do_test(const char *server
, /* I - Server to use */
175 http_encryption_t encryption
, /* I - Encryption to use */
176 int requests
) /* I - Number of requests to send */
178 int i
; /* Looping var */
179 http_t
*http
; /* Connection to server */
180 ipp_t
*request
, /* IPP Request */
181 *response
; /* IPP Response */
182 cups_lang_t
*language
; /* Default language */
183 struct timeval start
, /* Start time */
185 double elapsed
; /* Elapsed time */
186 static ipp_op_t ops
[4] = /* Operations to test... */
196 * Connect to the server...
199 http
= httpConnectEncrypt(server
, ippPort(), encryption
);
203 perror("testspeed: unable to connect to server");
207 language
= cupsLangDefault();
210 * Do multiple requests...
213 for (elapsed
= 0.0, i
= 0; i
< requests
; i
++)
216 printf("testspeed(%d): %d%% complete...\n", getpid(), i
* 100 / requests
);
219 * Build a request which requires the following attributes:
222 * attributes-natural-language
224 * In addition, IPP_GET_JOBS needs a printer-uri attribute.
229 request
->request
.op
.operation_id
= ops
[i
& 3];
230 request
->request
.op
.request_id
= 1;
232 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
233 "attributes-charset", NULL
, cupsLangEncoding(language
));
235 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
236 "attributes-natural-language", NULL
, language
->language
);
238 gettimeofday(&start
, NULL
);
240 switch (request
->request
.op
.operation_id
)
243 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri",
244 NULL
, "ipp://localhost/printers/");
247 response
= cupsDoRequest(http
, request
, "/");
251 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri",
252 NULL
, "ipp://localhost/printers/test");
253 response
= cupsDoFileRequest(http
, request
, "/printers/test",
254 "../data/testprint.ps");
258 gettimeofday(&end
, NULL
);
260 if (response
!= NULL
)
263 elapsed
+= (end
.tv_sec
- start
.tv_sec
) +
264 0.000001 * (end
.tv_usec
- start
.tv_usec
);
267 cupsLangFree(language
);
270 printf("testspeed(%d): %d requests in %.1fs (%.3fs/r, %.1fr/s)\n",
271 getpid(), i
, elapsed
, elapsed
/ i
, i
/ elapsed
);
278 * 'usage()' - Show program usage...
284 puts("Usage: testspeed [-c children] [-h] [-r requests] [-E] hostname");
291 * End of "$Id: testspeed.c,v 1.10 2004/10/04 19:40:35 mike Exp $".