added function
authormikhail.naganov@gmail.com <mikhail.naganov@gmail.com@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Tue, 1 Jun 2010 13:35:09 +0000 (13:35 +0000)
committermikhail.naganov@gmail.com <mikhail.naganov@gmail.com@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Tue, 1 Jun 2010 13:35:09 +0000 (13:35 +0000)
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@4766 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

src/cpu-profiler.cc
src/profile-generator.cc
src/profile-generator.h

index 31c4658..ba2ec9c 100644 (file)
@@ -415,14 +415,13 @@ CpuProfiler::~CpuProfiler() {
 void CpuProfiler::StartCollectingProfile(const char* title) {
   if (profiles_->StartProfiling(title, next_profile_uid_++)) {
     StartProcessorIfNotStarted();
+    generator_->AddCurrentStack();
   }
 }
 
 
 void CpuProfiler::StartCollectingProfile(String* title) {
-  if (profiles_->StartProfiling(title, next_profile_uid_++)) {
-    StartProcessorIfNotStarted();
-  }
+  StartCollectingProfile(profiles_->GetName(title));
 }
 
 
index 105c1a8..6cb76ff 100644 (file)
@@ -28,6 +28,7 @@
 #ifdef ENABLE_LOGGING_AND_PROFILING
 
 #include "v8.h"
+#include "frames-inl.h"
 #include "global-handles.h"
 
 #include "profile-generator-inl.h"
@@ -807,6 +808,22 @@ void ProfileGenerator::RecordTickSample(const TickSample& sample) {
   profiles_->AddPathToCurrentProfiles(entries);
 }
 
+
+void ProfileGenerator::AddCurrentStack() {
+  TickSample sample;
+  sample.state = VMState::current_state();
+  sample.pc = reinterpret_cast<Address>(&sample);  // Not NULL.
+  sample.frames_count = 0;
+  for (StackTraceFrameIterator it;
+       !it.done() && sample.frames_count < TickSample::kMaxFramesCount;
+       it.Advance()) {
+    JavaScriptFrame* frame = it.frame();
+    sample.stack[sample.frames_count++] =
+        reinterpret_cast<Address>(frame->function());
+  }
+  RecordTickSample(sample);
+}
+
 } }  // namespace v8::internal
 
 #endif  // ENABLE_LOGGING_AND_PROFILING
index 7830787..71deede 100644 (file)
@@ -260,6 +260,7 @@ class CpuProfilesCollection {
   CpuProfile* GetProfile(int security_token_id, unsigned uid);
   inline bool is_last_profile();
 
+  const char* GetName(String* name);
   CodeEntry* NewCodeEntry(Logger::LogEventsAndTags tag,
                           String* name, String* resource_name, int line_number);
   CodeEntry* NewCodeEntry(Logger::LogEventsAndTags tag, const char* name);
@@ -274,7 +275,6 @@ class CpuProfilesCollection {
  private:
   INLINE(const char* GetFunctionName(String* name));
   INLINE(const char* GetFunctionName(const char* name));
-  const char* GetName(String* name);
   const char* GetName(int args_count);
   List<CpuProfile*>* GetProfilesList(int security_token_id);
   int TokenToIndex(int security_token_id);
@@ -381,6 +381,9 @@ class ProfileGenerator {
     return sample_rate_calc_.ticks_per_ms();
   }
 
+  // Samples stack and adds it to current profiles.
+  void AddCurrentStack();
+
   static const char* kAnonymousFunctionName;
   static const char* kProgramEntryName;
   static const char* kGarbageCollectorEntryName;