2 * "$Id: testspeed.c 6649 2007-07-11 21:46:42Z mike $"
4 * Scheduler speed test for the Common UNIX Printing System (CUPS).
6 * Copyright 2007 by Apple Inc.
7 * Copyright 1997-2005 by Easy Software Products.
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
17 * main() - Send multiple IPP requests and report on the average response
19 * do_test() - Run a test on a specific host...
20 * usage() - Show program usage...
24 * Include necessary headers...
30 #include <sys/types.h>
33 #include <cups/cups.h>
34 #include <cups/language.h>
35 #include <cups/debug.h>
43 static int do_test(const char *server
, http_encryption_t encryption
,
44 int requests
, int verbose
);
45 static void usage(void);
49 * 'main()' - Send multiple IPP requests and report on the average response
54 main(int argc
, /* I - Number of command-line arguments */
55 char *argv
[]) /* I - Command-line arguments */
57 int i
; /* Looping var */
58 const char *server
; /* Server to use */
59 http_encryption_t encryption
; /* Encryption to use */
60 int requests
; /* Number of requests to send */
61 int children
; /* Number of children to fork */
62 int pid
; /* Child PID */
63 int status
; /* Child status */
64 time_t start
, /* Start time */
66 double elapsed
; /* Elapsed time */
67 int verbose
; /* Verbosity */
71 * Parse command-line options...
76 server
= cupsServer();
77 encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
80 for (i
= 1; i
< argc
; i
++)
81 if (!strcmp(argv
[i
], "-c"))
87 children
= atoi(argv
[i
]);
89 else if (!strcmp(argv
[i
], "-r"))
95 requests
= atoi(argv
[i
]);
97 else if (!strcmp(argv
[i
], "-E"))
98 encryption
= HTTP_ENCRYPT_REQUIRED
;
99 else if (!strcmp(argv
[i
], "-v"))
101 else if (argv
[i
][0] == '-')
107 * Then create child processes to act as clients...
110 printf("testspeed: Simulating %d clients with %d requests to %s with %s encryption...\n",
111 children
, requests
, server
,
112 encryption
== HTTP_ENCRYPT_IF_REQUESTED
? "no" : "");
118 do_test(server
, encryption
, requests
, verbose
);
122 for (i
= 0; i
< children
; i
++)
123 if ((pid
= fork()) == 0)
129 exit(do_test(server
, encryption
, requests
, verbose
));
133 perror("fork failed");
137 printf("testspeed(%d): Started...\n", pid
);
140 * Wait for children to finish...
147 if (pid
< 0 && errno
!= EINTR
)
150 printf("testspeed(%d): Ended (%d)...\n", pid
, status
);
155 * Compute the total run time...
159 elapsed
= end
- start
;
160 i
= children
* requests
;
162 printf("testspeed: %dx%d=%d requests in %.1fs (%.3fs/r, %.1fr/s)\n",
163 children
, requests
, i
, elapsed
, elapsed
/ i
, i
/ elapsed
);
166 * Exit with no errors...
174 * 'do_test()' - Run a test on a specific host...
177 static int /* O - Exit status */
178 do_test(const char *server
, /* I - Server to use */
179 http_encryption_t encryption
, /* I - Encryption to use */
180 int requests
, /* I - Number of requests to send */
181 int verbose
) /* I - Verbose output? */
183 int i
; /* Looping var */
184 http_t
*http
; /* Connection to server */
185 ipp_t
*request
, /* IPP Request */
186 *response
; /* IPP Response */
187 cups_lang_t
*language
; /* Default language */
188 struct timeval start
, /* Start time */
190 double elapsed
; /* Elapsed time */
191 static ipp_op_t ops
[4] = /* Operations to test... */
201 * Connect to the server...
204 http
= httpConnectEncrypt(server
, ippPort(), encryption
);
208 perror("testspeed: unable to connect to server");
212 language
= cupsLangDefault();
215 * Do multiple requests...
218 for (elapsed
= 0.0, i
= 0; i
< requests
; i
++)
220 if (verbose
&& (i
% 10) == 0)
221 printf("testspeed(%d): %d%% complete...\n", (int)getpid(),
225 * Build a request which requires the following attributes:
228 * attributes-natural-language
230 * In addition, IPP_GET_JOBS needs a printer-uri attribute.
235 request
->request
.op
.operation_id
= ops
[i
& 3];
236 request
->request
.op
.request_id
= 1;
238 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
239 "attributes-charset", NULL
, cupsLangEncoding(language
));
241 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
242 "attributes-natural-language", NULL
, language
->language
);
244 gettimeofday(&start
, NULL
);
246 switch (request
->request
.op
.operation_id
)
249 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri",
250 NULL
, "ipp://localhost/printers/");
253 response
= cupsDoRequest(http
, request
, "/");
257 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri",
258 NULL
, "ipp://localhost/printers/test");
259 response
= cupsDoFileRequest(http
, request
, "/printers/test",
260 "../data/testprint.ps");
264 gettimeofday(&end
, NULL
);
266 if (response
!= NULL
)
269 elapsed
+= (end
.tv_sec
- start
.tv_sec
) +
270 0.000001 * (end
.tv_usec
- start
.tv_usec
);
273 cupsLangFree(language
);
276 printf("testspeed(%d): %d requests in %.1fs (%.3fs/r, %.1fr/s)\n",
277 (int)getpid(), i
, elapsed
, elapsed
/ i
, i
/ elapsed
);
284 * 'usage()' - Show program usage...
290 puts("Usage: testspeed [-c children] [-h] [-r requests] [-v] [-E] hostname");
297 * End of "$Id: testspeed.c 6649 2007-07-11 21:46:42Z mike $".