Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(552)

Side by Side Diff: test/cctest/test-heap-profiler.cc

Issue 27717003: HeapProfiler: integrate FindUntrackedObjects into js code. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: cosmetic change Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/builtins.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 1989 matching lines...) Expand 10 before | Expand all | Expand 10 after
2000 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 2000 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
2001 const v8::HeapGraphNode* foo_func = 2001 const v8::HeapGraphNode* foo_func =
2002 GetProperty(global, v8::HeapGraphEdge::kProperty, "foo"); 2002 GetProperty(global, v8::HeapGraphEdge::kProperty, "foo");
2003 CHECK_NE(NULL, foo_func); 2003 CHECK_NE(NULL, foo_func);
2004 const v8::HeapGraphNode* code = 2004 const v8::HeapGraphNode* code =
2005 GetProperty(foo_func, v8::HeapGraphEdge::kInternal, "code"); 2005 GetProperty(foo_func, v8::HeapGraphEdge::kInternal, "code");
2006 CHECK_NE(NULL, code); 2006 CHECK_NE(NULL, code);
2007 } 2007 }
2008 2008
2009 2009
2010
2011 class HeapProfilerExtension : public v8::Extension {
2012 public:
2013 static const char* kName;
2014 HeapProfilerExtension() : v8::Extension(kName, kSource) { }
2015 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
2016 v8::Handle<v8::String> name);
2017 static void FindUntrackedObjects(
2018 const v8::FunctionCallbackInfo<v8::Value>& args);
2019 private:
2020 static const char* kSource;
2021 };
2022
2023 const char* HeapProfilerExtension::kName = "v8/heap-profiler";
2024
2025
2026 const char* HeapProfilerExtension::kSource =
2027 "native function findUntrackedObjects();";
2028
2029
2030 v8::Handle<v8::FunctionTemplate> HeapProfilerExtension::GetNativeFunction(
2031 v8::Handle<v8::String> name) {
2032 if (name->Equals(v8::String::New("findUntrackedObjects"))) {
2033 return v8::FunctionTemplate::New(
2034 HeapProfilerExtension::FindUntrackedObjects);
2035 } else {
2036 CHECK(false);
2037 return v8::Handle<v8::FunctionTemplate>();
2038 }
2039 }
2040
2041
2042 void HeapProfilerExtension::FindUntrackedObjects(
2043 const v8::FunctionCallbackInfo<v8::Value>& args) {
2044 i::HeapProfiler* heap_profiler =
2045 reinterpret_cast<i::HeapProfiler*>(args.GetIsolate()->GetHeapProfiler());
2046 int untracked_objects = heap_profiler->FindUntrackedObjects();
2047 args.GetReturnValue().Set(untracked_objects);
2048 CHECK_EQ(0, untracked_objects);
2049 }
2050
2051
2052 static HeapProfilerExtension kHeapProfilerExtension;
2053 v8::DeclareExtension kHeapProfilerExtensionDeclaration(
2054 &kHeapProfilerExtension);
2055
2056
2010 // This is an example of using checking of JS allocations tracking in a test. 2057 // This is an example of using checking of JS allocations tracking in a test.
2011 TEST(HeapObjectsTracker) { 2058 TEST(HeapObjectsTracker) {
2012 LocalContext env; 2059 const char* extensions[] = { HeapProfilerExtension::kName };
2060 v8::ExtensionConfiguration config(1, extensions);
2061 LocalContext env(&config);
2013 v8::HandleScope scope(env->GetIsolate()); 2062 v8::HandleScope scope(env->GetIsolate());
2014 HeapObjectsTracker tracker; 2063 HeapObjectsTracker tracker;
2015 CompileRun("var a = 1.2"); 2064 CompileRun("var a = 1.2");
2016 CompileRun("var a = 1.2; var b = 1.0; var c = 1.0;"); 2065 CompileRun("var a = 1.2; var b = 1.0; var c = 1.0;");
2017 CompileRun( 2066 CompileRun(
2018 "var a = [];" 2067 "var a = [];\n"
2019 "for (var i = 0; i < 5; ++i)" 2068 "for (var i = 0; i < 5; ++i)\n"
2020 " a[i] = i;\n" 2069 " a[i] = i;\n"
2021 "for (var i = 0; i < 3; ++i)" 2070 "findUntrackedObjects();\n"
2022 " a.shift();\n"); 2071 "for (var i = 0; i < 3; ++i)\n"
2072 " a.shift();\n"
2073 "findUntrackedObjects();\n");
2023 } 2074 }
OLDNEW
« no previous file with comments | « src/builtins.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698