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