| OLD | NEW |
| 1 // Copyright (c) 2008, Google Inc. | 1 // Copyright (c) 2008, 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 | 80 |
| 81 #undef LOG // defined in base/logging.h | 81 #undef LOG // defined in base/logging.h |
| 82 // Ideally, we'd put the newline at the end, but this hack puts the | 82 // Ideally, we'd put the newline at the end, but this hack puts the |
| 83 // newline at the end of the previous log message, which is good enough :-) | 83 // newline at the end of the previous log message, which is good enough :-) |
| 84 #define LOG(level) std::cerr << "\n" | 84 #define LOG(level) std::cerr << "\n" |
| 85 | 85 |
| 86 static std::string StringPrintf(const char* format, ...) { | 86 static std::string StringPrintf(const char* format, ...) { |
| 87 char buf[256]; // should be big enough for all logging | 87 char buf[256]; // should be big enough for all logging |
| 88 va_list ap; | 88 va_list ap; |
| 89 va_start(ap, format); | 89 va_start(ap, format); |
| 90 vsnprintf(buf, sizeof(buf), format, ap); | 90 perftools_vsnprintf(buf, sizeof(buf), format, ap); |
| 91 va_end(ap); | 91 va_end(ap); |
| 92 return buf; | 92 return buf; |
| 93 } | 93 } |
| 94 | 94 |
| 95 namespace { | 95 namespace { |
| 96 template<typename T> class scoped_array { | 96 template<typename T> class scoped_array { |
| 97 public: | 97 public: |
| 98 scoped_array(T* p) : p_(p) { } | 98 scoped_array(T* p) : p_(p) { } |
| 99 ~scoped_array() { delete[] p_; } | 99 ~scoped_array() { delete[] p_; } |
| 100 const T* get() const { return p_; } | 100 const T* get() const { return p_; } |
| (...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 640 | 640 |
| 641 | 641 |
| 642 // It's not really a test, but it's good to know | 642 // It's not really a test, but it's good to know |
| 643 TEST(Sample, size_of_class) { | 643 TEST(Sample, size_of_class) { |
| 644 tcmalloc::Sampler sampler; | 644 tcmalloc::Sampler sampler; |
| 645 sampler.Init(1); | 645 sampler.Init(1); |
| 646 LOG(INFO) << "Size of Sampler class is: " << sizeof(tcmalloc::Sampler); | 646 LOG(INFO) << "Size of Sampler class is: " << sizeof(tcmalloc::Sampler); |
| 647 LOG(INFO) << "Size of Sampler object is: " << sizeof(sampler); | 647 LOG(INFO) << "Size of Sampler object is: " << sizeof(sampler); |
| 648 } | 648 } |
| 649 | 649 |
| 650 // Make sure sampling is enabled, or the tests won't work right. |
| 651 DECLARE_int64(tcmalloc_sample_parameter); |
| 652 |
| 650 int main(int argc, char **argv) { | 653 int main(int argc, char **argv) { |
| 654 if (FLAGS_tcmalloc_sample_parameter == 0) |
| 655 FLAGS_tcmalloc_sample_parameter = 524288; |
| 651 return RUN_ALL_TESTS(); | 656 return RUN_ALL_TESTS(); |
| 652 } | 657 } |
| OLD | NEW |