test-platform-output.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
  2. *
  3. * Permission is hereby granted, free of charge, to any person obtaining a copy
  4. * of this software and associated documentation files (the "Software"), to
  5. * deal in the Software without restriction, including without limitation the
  6. * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  7. * sell copies of the Software, and to permit persons to whom the Software is
  8. * furnished to do so, subject to the following conditions:
  9. *
  10. * The above copyright notice and this permission notice shall be included in
  11. * all copies or substantial portions of the Software.
  12. *
  13. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  18. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  19. * IN THE SOFTWARE.
  20. */
  21. #include "uv.h"
  22. #include "task.h"
  23. #include <string.h>
  24. TEST_IMPL(platform_output) {
  25. char buffer[512];
  26. size_t rss;
  27. double uptime;
  28. uv_cpu_info_t* cpus;
  29. uv_interface_address_t* interfaces;
  30. int count;
  31. int i;
  32. uv_err_t err;
  33. err = uv_get_process_title(buffer, sizeof(buffer));
  34. ASSERT(UV_OK == err.code);
  35. printf("uv_get_process_title: %s\n", buffer);
  36. err = uv_resident_set_memory(&rss);
  37. ASSERT(UV_OK == err.code);
  38. printf("uv_resident_set_memory: %llu\n", (unsigned long long) rss);
  39. err = uv_uptime(&uptime);
  40. ASSERT(UV_OK == err.code);
  41. ASSERT(uptime > 0);
  42. printf("uv_uptime: %f\n", uptime);
  43. err = uv_cpu_info(&cpus, &count);
  44. ASSERT(UV_OK == err.code);
  45. printf("uv_cpu_info:\n");
  46. for (i = 0; i < count; i++) {
  47. printf(" model: %s\n", cpus[i].model);
  48. printf(" speed: %d\n", cpus[i].speed);
  49. printf(" times.sys: %llu\n", (unsigned long long) cpus[i].cpu_times.sys);
  50. printf(" times.user: %llu\n",
  51. (unsigned long long) cpus[i].cpu_times.user);
  52. printf(" times.idle: %llu\n",
  53. (unsigned long long) cpus[i].cpu_times.idle);
  54. printf(" times.irq: %llu\n", (unsigned long long) cpus[i].cpu_times.irq);
  55. printf(" times.nice: %llu\n",
  56. (unsigned long long) cpus[i].cpu_times.nice);
  57. }
  58. uv_free_cpu_info(cpus, count);
  59. err = uv_interface_addresses(&interfaces, &count);
  60. ASSERT(UV_OK == err.code);
  61. printf("uv_interface_addresses:\n");
  62. for (i = 0; i < count; i++) {
  63. printf(" name: %s\n", interfaces[i].name);
  64. printf(" internal: %d\n", interfaces[i].is_internal);
  65. if (interfaces[i].address.address4.sin_family == AF_INET) {
  66. uv_ip4_name(&interfaces[i].address.address4, buffer, sizeof(buffer));
  67. } else if (interfaces[i].address.address4.sin_family == AF_INET6) {
  68. uv_ip6_name(&interfaces[i].address.address6, buffer, sizeof(buffer));
  69. }
  70. printf(" address: %s\n", buffer);
  71. }
  72. uv_free_interface_addresses(interfaces, count);
  73. return 0;
  74. }