Skip to content

Commit

Permalink
Use correct format specifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
rigtorp committed Jul 26, 2021
1 parent a522235 commit 332f02e
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 32 deletions.
6 changes: 4 additions & 2 deletions src/pipe_lat.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
OTHER DEALINGS IN THE SOFTWARE.
*/

#define __STDC_FORMAT_MACROS
#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -67,7 +69,7 @@ int main(int argc, char *argv[]) {
}

printf("message size: %i octets\n", size);
printf("roundtrip count: %li\n", count);
printf("roundtrip count: %" PRId64 "\n", count);

if (pipe(ofds) == -1) {
perror("pipe");
Expand Down Expand Up @@ -139,7 +141,7 @@ int main(int argc, char *argv[]) {

#endif

printf("average latency: %li ns\n", delta / (count * 2));
printf("average latency: %" PRId64 " ns\n", delta / (count * 2));
}

return 0;
Expand Down
9 changes: 6 additions & 3 deletions src/pipe_thr.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
OTHER DEALINGS IN THE SOFTWARE.
*/

#define __STDC_FORMAT_MACROS
#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -66,7 +68,7 @@ int main(int argc, char *argv[]) {
}

printf("message size: %i octets\n", size);
printf("message count: %li\n", count);
printf("message count: %" PRId64 "\n", count);

if (pipe(fds) == -1) {
perror("pipe");
Expand Down Expand Up @@ -124,8 +126,9 @@ int main(int argc, char *argv[]) {

#endif

printf("average throughput: %li msg/s\n", (count * 1000000) / delta);
printf("average throughput: %li Mb/s\n",
printf("average throughput: %" PRId64 " msg/s\n",
(count * 1000000) / delta);
printf("average throughput: %" PRId64 " Mb/s\n",
(((count * 1000000) / delta) * size * 8) / 1000000);
}

Expand Down
6 changes: 4 additions & 2 deletions src/tcp_lat.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
OTHER DEALINGS IN THE SOFTWARE.
*/

#define __STDC_FORMAT_MACROS
#include <inttypes.h>
#include <netdb.h>
#include <stdint.h>
#include <stdio.h>
Expand Down Expand Up @@ -86,7 +88,7 @@ int main(int argc, char *argv[]) {
}

printf("message size: %i octets\n", size);
printf("roundtrip count: %li\n", count);
printf("roundtrip count: %" PRId64 "\n", count);

if (!fork()) { /* child */

Expand Down Expand Up @@ -199,7 +201,7 @@ int main(int argc, char *argv[]) {

#endif

printf("average latency: %li ns\n", delta / (count * 2));
printf("average latency: %" PRId64 " ns\n", delta / (count * 2));
}

return 0;
Expand Down
4 changes: 3 additions & 1 deletion src/tcp_local_lat.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
OTHER DEALINGS IN THE SOFTWARE.
*/

#define __STDC_FORMAT_MACROS
#include <inttypes.h>
#include <netdb.h>
#include <stdint.h>
#include <stdio.h>
Expand Down Expand Up @@ -68,7 +70,7 @@ int main(int argc, char *argv[]) {
}

printf("message size: %i octets\n", size);
printf("roundtrip count: %li\n", count);
printf("roundtrip count: %" PRId64 "\n", count);

memset(&hints, 0, sizeof hints);
hints.ai_family = AF_UNSPEC; // use IPv4 or IPv6, whichever
Expand Down
10 changes: 6 additions & 4 deletions src/tcp_remote_lat.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
OTHER DEALINGS IN THE SOFTWARE.
*/

#define __STDC_FORMAT_MACROS
#include <inttypes.h>
#include <netdb.h>
#include <stdint.h>
#include <stdio.h>
Expand Down Expand Up @@ -66,7 +68,7 @@ int main(int argc, char *argv[]) {
}

printf("message size: %i octets\n", size);
printf("roundtrip count: %li\n", count);
printf("roundtrip count: %" PRId64 "\n", count);

memset(&hints, 0, sizeof hints);
hints.ai_family = AF_UNSPEC; // use IPv4 or IPv6, whichever
Expand Down Expand Up @@ -119,10 +121,10 @@ int main(int argc, char *argv[]) {

gettimeofday(&stop, NULL);

delta =
(stop.tv_sec - start.tv_sec) * 1000000000 + (stop.tv_usec - start.tv_usec) * 1000;
delta = (stop.tv_sec - start.tv_sec) * 1000000000 +
(stop.tv_usec - start.tv_usec) * 1000;

printf("average latency: %li ns\n", delta / (count * 2));
printf("average latency: %" PRId64 " ns\n", delta / (count * 2));

return 0;
}
9 changes: 6 additions & 3 deletions src/tcp_thr.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
OTHER DEALINGS IN THE SOFTWARE.
*/

#define __STDC_FORMAT_MACROS
#include <inttypes.h>
#include <netdb.h>
#include <netinet/tcp.h>
#include <stdint.h>
Expand Down Expand Up @@ -87,7 +89,7 @@ int main(int argc, char *argv[]) {
}

printf("message size: %i octets\n", size);
printf("message count: %li\n", count);
printf("message count: %" PRId64 "\n", count);

if (!fork()) {
/* child */
Expand Down Expand Up @@ -189,8 +191,9 @@ int main(int argc, char *argv[]) {

#endif

printf("average throughput: %li msg/s\n", (count * 1000000) / delta);
printf("average throughput: %li Mb/s\n",
printf("average throughput: %" PRId64 " msg/s\n",
(count * 1000000) / delta);
printf("average throughput: %" PRId64 " Mb/s\n",
(((count * 1000000) / delta) * size * 8) / 1000000);
}

Expand Down
30 changes: 18 additions & 12 deletions src/udp_lat.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
OTHER DEALINGS IN THE SOFTWARE.
*/

#define __STDC_FORMAT_MACROS
#include <inttypes.h>
#include <netdb.h>
#include <stdint.h>
#include <stdio.h>
Expand Down Expand Up @@ -89,12 +91,12 @@ int main(int argc, char *argv[]) {
}

printf("message size: %i octets\n", size);
printf("roundtrip count: %lli\n", count);
printf("roundtrip count: %" PRId64 "\n", count);

if (!fork()) { /* child */

if ((sockfd = socket(resChild->ai_family, resChild->ai_socktype, resChild->ai_protocol)) ==
-1) {
if ((sockfd = socket(resChild->ai_family, resChild->ai_socktype,
resChild->ai_protocol)) == -1) {
perror("socket");
return 1;
}
Expand All @@ -112,15 +114,17 @@ int main(int argc, char *argv[]) {
for (i = 0; i < count; i++) {

for (sofar = 0; sofar < size;) {
len = recvfrom(sockfd, buf, size - sofar, 0, resParent->ai_addr, &resParent->ai_addrlen);
len = recvfrom(sockfd, buf, size - sofar, 0, resParent->ai_addr,
&resParent->ai_addrlen);
if (len == -1) {
perror("recvfrom");
return 1;
}
sofar += len;
}

if (sendto(sockfd, buf, size, 0, resParent->ai_addr, resParent->ai_addrlen) != size) {
if (sendto(sockfd, buf, size, 0, resParent->ai_addr,
resParent->ai_addrlen) != size) {
perror("sendto");
return 1;
}
Expand All @@ -129,8 +133,8 @@ int main(int argc, char *argv[]) {

sleep(1);

if ((sockfd = socket(resParent->ai_family, resParent->ai_socktype, resParent->ai_protocol)) ==
-1) {
if ((sockfd = socket(resParent->ai_family, resParent->ai_socktype,
resParent->ai_protocol)) == -1) {
perror("socket");
return 1;
}
Expand Down Expand Up @@ -159,13 +163,15 @@ int main(int argc, char *argv[]) {

for (i = 0; i < count; i++) {

if (sendto(sockfd, buf, size, 0, resChild->ai_addr, resChild->ai_addrlen) != size) {
if (sendto(sockfd, buf, size, 0, resChild->ai_addr,
resChild->ai_addrlen) != size) {
perror("sendto");
return 1;
}

for (sofar = 0; sofar < size;) {
len = recvfrom(sockfd, buf, size - sofar, 0, resChild->ai_addr, &resChild->ai_addrlen);
len = recvfrom(sockfd, buf, size - sofar, 0, resChild->ai_addr,
&resChild->ai_addrlen);
if (len == -1) {
perror("read");
return 1;
Expand All @@ -189,12 +195,12 @@ int main(int argc, char *argv[]) {
return 1;
}

delta =
(stop.tv_sec - start.tv_sec) * 1000000000 + (stop.tv_usec - start.tv_usec) * 1000;
delta = (stop.tv_sec - start.tv_sec) * 1000000000 +
(stop.tv_usec - start.tv_usec) * 1000;

#endif

printf("average latency: %lli ns\n", delta / (count * 2));
printf("average latency: %" PRId64 " ns\n", delta / (count * 2));
}

return 0;
Expand Down
6 changes: 4 additions & 2 deletions src/unix_lat.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
OTHER DEALINGS IN THE SOFTWARE.
*/

#define __STDC_FORMAT_MACROS
#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -65,7 +67,7 @@ int main(int argc, char *argv[]) {
}

printf("message size: %i octets\n", size);
printf("roundtrip count: %li\n", count);
printf("roundtrip count: %" PRId64 "\n", count);

if (socketpair(AF_UNIX, SOCK_STREAM, 0, sv) == -1) {
perror("socketpair");
Expand Down Expand Up @@ -132,7 +134,7 @@ int main(int argc, char *argv[]) {

#endif

printf("average latency: %li ns\n", delta / (count * 2));
printf("average latency: %" PRId64 " ns\n", delta / (count * 2));
}

return 0;
Expand Down
9 changes: 6 additions & 3 deletions src/unix_thr.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
OTHER DEALINGS IN THE SOFTWARE.
*/

#define __STDC_FORMAT_MACROS
#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -65,7 +67,7 @@ int main(int argc, char *argv[]) {
}

printf("message size: %i octets\n", size);
printf("message count: %li\n", count);
printf("message count: %" PRId64 "\n", count);

if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds) == -1) {
perror("socketpair");
Expand Down Expand Up @@ -123,8 +125,9 @@ int main(int argc, char *argv[]) {

#endif

printf("average throughput: %li msg/s\n", (count * 1000000) / delta);
printf("average throughput: %li Mb/s\n",
printf("average throughput: %" PRId64 " msg/s\n",
(count * 1000000) / delta);
printf("average throughput: %" PRId64 " Mb/s\n",
(((count * 1000000) / delta) * size * 8) / 1000000);
}

Expand Down

0 comments on commit 332f02e

Please sign in to comment.