OLD | NEW |
1 // Copyright (c) 2009, Google Inc. | 1 // Copyright (c) 2009, Google Inc. |
2 // All rights reserved. | 2 // All rights reserved. |
3 // | 3 // |
4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
6 // met: | 6 // met: |
7 // | 7 // |
8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 #include "base/sysinfo.h" | 61 #include "base/sysinfo.h" |
62 | 62 |
63 using std::string; | 63 using std::string; |
64 using tcmalloc::DumpProcSelfMaps; // from sysinfo.h | 64 using tcmalloc::DumpProcSelfMaps; // from sysinfo.h |
65 | 65 |
66 | 66 |
67 DEFINE_string(symbolize_pprof, | 67 DEFINE_string(symbolize_pprof, |
68 EnvToString("PPROF_PATH", "pprof"), | 68 EnvToString("PPROF_PATH", "pprof"), |
69 "Path to pprof to call for reporting function names."); | 69 "Path to pprof to call for reporting function names."); |
70 | 70 |
71 // heap_profile_table_pprof may be referenced after destructors are | |
72 // called (since that's when leak-checking is done), so we make | |
73 // a more-permanent copy that won't ever get destroyed. | |
74 static string* g_pprof_path = new string(FLAGS_symbolize_pprof); | |
75 | |
76 // Returns NULL if we're on an OS where we can't get the invocation name. | 71 // Returns NULL if we're on an OS where we can't get the invocation name. |
77 // Using a static var is ok because we're not called from a thread. | 72 // Using a static var is ok because we're not called from a thread. |
78 static char* GetProgramInvocationName() { | 73 static char* GetProgramInvocationName() { |
79 #if defined(HAVE_PROGRAM_INVOCATION_NAME) | 74 #if defined(HAVE_PROGRAM_INVOCATION_NAME) |
80 extern char* program_invocation_name; // gcc provides this | 75 extern char* program_invocation_name; // gcc provides this |
81 return program_invocation_name; | 76 return program_invocation_name; |
82 #elif defined(__MACH__) | 77 #elif defined(__MACH__) |
83 // We don't want to allocate memory for this since we may be | 78 // We don't want to allocate memory for this since we may be |
84 // calculating it when memory is corrupted. | 79 // calculating it when memory is corrupted. |
85 static char program_invocation_name[PATH_MAX]; | 80 static char program_invocation_name[PATH_MAX]; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 int SymbolTable::Symbolize() { | 117 int SymbolTable::Symbolize() { |
123 #if !defined(HAVE_UNISTD_H) || !defined(HAVE_SYS_SOCKET_H) || !defined(HAVE_SYS
_WAIT_H) | 118 #if !defined(HAVE_UNISTD_H) || !defined(HAVE_SYS_SOCKET_H) || !defined(HAVE_SYS
_WAIT_H) |
124 PrintError("Perftools does not know how to call a sub-process on this O/S"); | 119 PrintError("Perftools does not know how to call a sub-process on this O/S"); |
125 return 0; | 120 return 0; |
126 #else | 121 #else |
127 const char* argv0 = GetProgramInvocationName(); | 122 const char* argv0 = GetProgramInvocationName(); |
128 if (argv0 == NULL) { // can't call symbolize if we can't figure out our name | 123 if (argv0 == NULL) { // can't call symbolize if we can't figure out our name |
129 PrintError("Cannot figure out the name of this executable (argv0)"); | 124 PrintError("Cannot figure out the name of this executable (argv0)"); |
130 return 0; | 125 return 0; |
131 } | 126 } |
132 if (access(g_pprof_path->c_str(), R_OK) != 0) { | 127 if (access(FLAGS_symbolize_pprof, R_OK) != 0) { |
133 PrintError("Cannot find 'pprof' (is PPROF_PATH set correctly?)"); | 128 PrintError("Cannot find 'pprof' (is PPROF_PATH set correctly?)"); |
134 return 0; | 129 return 0; |
135 } | 130 } |
136 | 131 |
137 // All this work is to do two-way communication. ugh. | 132 // All this work is to do two-way communication. ugh. |
138 int *child_in = NULL; // file descriptors | 133 int *child_in = NULL; // file descriptors |
139 int *child_out = NULL; // for now, we don't worry about child_err | 134 int *child_out = NULL; // for now, we don't worry about child_err |
140 int child_fds[5][2]; // socketpair may be called up to five times below | 135 int child_fds[5][2]; // socketpair may be called up to five times below |
141 | 136 |
142 // The client program may close its stdin and/or stdout and/or stderr | 137 // The client program may close its stdin and/or stdout and/or stderr |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 close(child_out[1]); // child uses the 0's, parent uses the 1's | 179 close(child_out[1]); // child uses the 0's, parent uses the 1's |
185 close(0); | 180 close(0); |
186 close(1); | 181 close(1); |
187 if (dup2(child_in[0], 0) == -1) _exit(1); | 182 if (dup2(child_in[0], 0) == -1) _exit(1); |
188 if (dup2(child_out[0], 1) == -1) _exit(2); | 183 if (dup2(child_out[0], 1) == -1) _exit(2); |
189 // Unset vars that might cause trouble when we fork | 184 // Unset vars that might cause trouble when we fork |
190 unsetenv("CPUPROFILE"); | 185 unsetenv("CPUPROFILE"); |
191 unsetenv("HEAPPROFILE"); | 186 unsetenv("HEAPPROFILE"); |
192 unsetenv("HEAPCHECK"); | 187 unsetenv("HEAPCHECK"); |
193 unsetenv("PERFTOOLS_VERBOSE"); | 188 unsetenv("PERFTOOLS_VERBOSE"); |
194 execlp(g_pprof_path->c_str(), g_pprof_path->c_str(), | 189 execlp(FLAGS_symbolize_pprof, FLAGS_symbolize_pprof, |
195 "--symbols", argv0, NULL); | 190 "--symbols", argv0, NULL); |
196 _exit(3); // if execvp fails, it's bad news for us | 191 _exit(3); // if execvp fails, it's bad news for us |
197 } | 192 } |
198 default: { // parent | 193 default: { // parent |
199 close(child_in[0]); // child uses the 0's, parent uses the 1's | 194 close(child_in[0]); // child uses the 0's, parent uses the 1's |
200 close(child_out[0]); // child uses the 0's, parent uses the 1's | 195 close(child_out[0]); // child uses the 0's, parent uses the 1's |
201 #ifdef HAVE_POLL_H | 196 #ifdef HAVE_POLL_H |
202 // Waiting for 1ms seems to give the OS time to notice any errors. | 197 // Waiting for 1ms seems to give the OS time to notice any errors. |
203 poll(0, 0, 1); | 198 poll(0, 0, 1); |
204 // For maximum safety, we check to make sure the execlp | 199 // For maximum safety, we check to make sure the execlp |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 num_symbols++; | 266 num_symbols++; |
272 } | 267 } |
273 } | 268 } |
274 return num_symbols; | 269 return num_symbols; |
275 } | 270 } |
276 } | 271 } |
277 PrintError("Unkown error (should never occur!)"); | 272 PrintError("Unkown error (should never occur!)"); |
278 return 0; // shouldn't be reachable | 273 return 0; // shouldn't be reachable |
279 #endif | 274 #endif |
280 } | 275 } |
OLD | NEW |