Return the file descriptor we're writing a log to
| 927 | |
| 928 | // Return the file descriptor we're writing a log to |
| 929 | static int TraceFd() { |
| 930 | static int trace_fd = -1; |
| 931 | if (trace_fd == -1) { // Open the trace file on the first call |
| 932 | trace_fd = open("/tmp/google.alloc", O_CREAT|O_TRUNC|O_WRONLY, 0666); |
| 933 | if (trace_fd == -1) { |
| 934 | trace_fd = 2; |
| 935 | TracePrintf(trace_fd, |
| 936 | "Can't open /tmp/google.alloc. Logging to stderr.\n"); |
| 937 | } |
| 938 | // Add a header to the log. |
| 939 | TracePrintf(trace_fd, "Trace started: %lu\n", |
| 940 | static_cast<unsigned long>(time(NULL))); |
| 941 | TracePrintf(trace_fd, |
| 942 | "func\tsize\tptr\tthread_id\tstack pcs for tools/symbolize\n"); |
| 943 | } |
| 944 | return trace_fd; |
| 945 | } |
| 946 | |
| 947 | // Print the hex stack dump on a single line. PCs are separated by tabs. |
| 948 | static void TraceStack(void) { |
no test coverage detected