memtrack_helper.h 960 B

123456789101112131415161718192021222324252627282930313233
  1. /*
  2. * Copyright 2015 The Chromium Authors. All rights reserved.
  3. * Use of this source code is governed by a BSD-style license that can be
  4. * found in the LICENSE file.
  5. */
  6. #ifndef TOOLS_ANDROID_MEMTRACK_HELPER_H_
  7. #define TOOLS_ANDROID_MEMTRACK_HELPER_H_
  8. #include <android/log.h>
  9. #include <errno.h>
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #include <sys/socket.h>
  14. #include <sys/un.h>
  15. static const char* const kLogTag = "memtrack_helper";
  16. static inline void exit_with_failure(const char* reason) {
  17. perror(reason);
  18. __android_log_write(ANDROID_LOG_ERROR, kLogTag, reason);
  19. exit(EXIT_FAILURE);
  20. }
  21. static inline void init_memtrack_server_addr(struct sockaddr_un* addr) {
  22. const char* const kAbstractSocketName = "chrome_tracing_memtrack_helper";
  23. memset(addr, 0, sizeof(*addr));
  24. addr->sun_family = AF_UNIX;
  25. strncpy(&addr->sun_path[1], kAbstractSocketName, sizeof(addr->sun_path) - 2);
  26. }
  27. #endif // TOOLS_ANDROID_MEMTRACK_HELPER_H_