| OLD | NEW | 
|---|
| 1 // Copyright (c) 2011, Google Inc. | 1 // Copyright (c) 2011, 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 24 matching lines...) Expand all  Loading... | 
| 35 // before the alloc+free should match the number of bytes used after. | 35 // before the alloc+free should match the number of bytes used after. | 
| 36 // However, the internal data structures used by tcmalloc will be | 36 // However, the internal data structures used by tcmalloc will be | 
| 37 // quite different -- new spans will have been allocated, etc.  This | 37 // quite different -- new spans will have been allocated, etc.  This | 
| 38 // is, thus, a simple test that we account properly for the internal | 38 // is, thus, a simple test that we account properly for the internal | 
| 39 // data structures, so that we report the actual application-used | 39 // data structures, so that we report the actual application-used | 
| 40 // bytes properly. | 40 // bytes properly. | 
| 41 | 41 | 
| 42 #include "config_for_unittests.h" | 42 #include "config_for_unittests.h" | 
| 43 #include <stdlib.h> | 43 #include <stdlib.h> | 
| 44 #include <stdio.h> | 44 #include <stdio.h> | 
| 45 #include <gperftools/malloc_extension.h> | 45 #include <google/malloc_extension.h> | 
| 46 #include "base/logging.h" | 46 #include "base/logging.h" | 
| 47 | 47 | 
| 48 const char kCurrent[] = "generic.current_allocated_bytes"; | 48 const char kCurrent[] = "generic.current_allocated_bytes"; | 
| 49 | 49 | 
| 50 int main() { | 50 int main() { | 
| 51   // We don't do accounting right when using debugallocation.cc, so | 51   // We don't do accounting right when using debugallocation.cc, so | 
| 52   // turn off the test then.  TODO(csilvers): get this working too. | 52   // turn off the test then.  TODO(csilvers): get this working too. | 
| 53 #ifdef NDEBUG | 53 #ifdef NDEBUG | 
| 54   size_t before_bytes, after_bytes; | 54   size_t before_bytes, after_bytes; | 
| 55   MallocExtension::instance()->GetNumericProperty(kCurrent, &before_bytes); | 55   MallocExtension::instance()->GetNumericProperty(kCurrent, &before_bytes); | 
| 56   free(malloc(200)); | 56   free(malloc(200)); | 
| 57   MallocExtension::instance()->GetNumericProperty(kCurrent, &after_bytes); | 57   MallocExtension::instance()->GetNumericProperty(kCurrent, &after_bytes); | 
| 58 | 58 | 
| 59   CHECK_EQ(before_bytes, after_bytes); | 59   CHECK_EQ(before_bytes, after_bytes); | 
| 60 #endif | 60 #endif | 
| 61   printf("PASS\n"); | 61   printf("PASS\n"); | 
| 62   return 0; | 62   return 0; | 
| 63 } | 63 } | 
| OLD | NEW | 
|---|