| OLD | NEW |
| 1 // Copyright (c) 2006, Google Inc. | 1 // Copyright (c) 2006, 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 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 // gcc -- if you do a setenv() in a shared libarary in a global | 180 // gcc -- if you do a setenv() in a shared libarary in a global |
| 181 // constructor, the environment setting is lost by the time main() is | 181 // constructor, the environment setting is lost by the time main() is |
| 182 // called. The only safe thing we can do in such a situation is to | 182 // called. The only safe thing we can do in such a situation is to |
| 183 // modify the existing envvar. So we do a hack: in the parent, we set | 183 // modify the existing envvar. So we do a hack: in the parent, we set |
| 184 // the high bit of the 1st char of CPUPROFILE. In the child, we | 184 // the high bit of the 1st char of CPUPROFILE. In the child, we |
| 185 // notice the high bit is set and append the pid(). This works | 185 // notice the high bit is set and append the pid(). This works |
| 186 // assuming cpuprofile filenames don't normally have the high bit set | 186 // assuming cpuprofile filenames don't normally have the high bit set |
| 187 // in their first character! If that assumption is violated, we'll | 187 // in their first character! If that assumption is violated, we'll |
| 188 // still get a profile, but one with an unexpected name. | 188 // still get a profile, but one with an unexpected name. |
| 189 // TODO(csilvers): set an envvar instead when we can do it reliably. | 189 // TODO(csilvers): set an envvar instead when we can do it reliably. |
| 190 // |
| 191 // In Chromium this hack is intentionally disabled, because the path is not |
| 192 // re-initialized upon fork. |
| 190 bool GetUniquePathFromEnv(const char* env_name, char* path) { | 193 bool GetUniquePathFromEnv(const char* env_name, char* path) { |
| 191 char* envval = getenv(env_name); | 194 char* envval = getenv(env_name); |
| 192 if (envval == NULL || *envval == '\0') | 195 if (envval == NULL || *envval == '\0') |
| 193 return false; | 196 return false; |
| 194 if (envval[0] & 128) { // high bit is set | 197 if (envval[0] & 128) { // high bit is set |
| 195 snprintf(path, PATH_MAX, "%c%s_%u", // add pid and clear high bit | 198 snprintf(path, PATH_MAX, "%c%s_%u", // add pid and clear high bit |
| 196 envval[0] & 127, envval+1, (unsigned int)(getpid())); | 199 envval[0] & 127, envval+1, (unsigned int)(getpid())); |
| 197 } else { | 200 } else { |
| 198 snprintf(path, PATH_MAX, "%s", envval); | 201 snprintf(path, PATH_MAX, "%s", envval); |
| 202 #if 0 |
| 199 envval[0] |= 128; // set high bit for kids to see | 203 envval[0] |= 128; // set high bit for kids to see |
| 204 #endif |
| 200 } | 205 } |
| 201 return true; | 206 return true; |
| 202 } | 207 } |
| 203 | 208 |
| 204 // ---------------------------------------------------------------------- | 209 // ---------------------------------------------------------------------- |
| 205 // CyclesPerSecond() | 210 // CyclesPerSecond() |
| 206 // NumCPUs() | 211 // NumCPUs() |
| 207 // It's important this not call malloc! -- they may be called at | 212 // It's important this not call malloc! -- they may be called at |
| 208 // global-construct time, before we've set up all our proper malloc | 213 // global-construct time, before we've set up all our proper malloc |
| 209 // hooks and such. | 214 // hooks and such. |
| (...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 976 ProcMapsIterator::Buffer linebuf; | 981 ProcMapsIterator::Buffer linebuf; |
| 977 while (it.Next(&start, &end, &flags, &offset, &inode, &filename)) { | 982 while (it.Next(&start, &end, &flags, &offset, &inode, &filename)) { |
| 978 int written = it.FormatLine(linebuf.buf_, sizeof(linebuf.buf_), | 983 int written = it.FormatLine(linebuf.buf_, sizeof(linebuf.buf_), |
| 979 start, end, flags, offset, inode, filename, | 984 start, end, flags, offset, inode, filename, |
| 980 0); | 985 0); |
| 981 RawWrite(fd, linebuf.buf_, written); | 986 RawWrite(fd, linebuf.buf_, written); |
| 982 } | 987 } |
| 983 } | 988 } |
| 984 | 989 |
| 985 } // namespace tcmalloc | 990 } // namespace tcmalloc |
| OLD | NEW |