Browse Source

better pstats

David Rose 17 years ago
parent
commit
0866bf9e51

+ 18 - 10
panda/src/event/asyncTask.cxx

@@ -126,27 +126,35 @@ set_name(const string &name) {
   }
 
 #ifdef DO_PSTATS
-  // Update the PStatCollector with the new name.  If the name ends
-  // with a hyphen followed by a string of digits, we strip all that
-  // off, for the parent collector, to group related tasks together in
-  // the pstats graph.  We still create a child collector that
-  // contains the full name, however.
+  // Update the PStatCollector with the new name.  If the name
+  // includes a colon, we stop the collector name there, and don't go
+  // further.
   size_t end = name.size();
-  size_t p = end;
+  size_t colon = name.find(':');
+  if (colon != string::npos) {
+    end = min(end, colon);
+  }
+
+  // If the name ends with a hyphen followed by a string of digits, we
+  // strip all that off, for the parent collector, to group related
+  // tasks together in the pstats graph.  We still create a child
+  // collector that contains the full name, however.
+  size_t trimmed = end;
+  size_t p = trimmed;
   while (true) {
     while (p > 0 && isdigit(name[p - 1])) {
       --p;
     }
     if (p > 0 && (name[p - 1] == '-' || name[p - 1] == '_')) {
       --p;
-      end = p;
+      trimmed = p;
     } else {
-      p = end;
+      p = trimmed;
       break;
     }
   }
-  PStatCollector parent(_show_code_pcollector, name.substr(0, end));
-  _task_pcollector = PStatCollector(parent, name);
+  PStatCollector parent(_show_code_pcollector, name.substr(0, trimmed));
+  _task_pcollector = PStatCollector(parent, name.substr(0, end));
 #endif  // DO_PSTATS
 }
 

+ 8 - 3
panda/src/event/asyncTaskChain.cxx

@@ -809,6 +809,10 @@ bool AsyncTaskChain::
 finish_sort_group() {
   nassertr(_num_busy_threads == 0, true);
 
+  if (!_threads.empty()) {
+    PStatClient::thread_tick(get_name());
+  }
+  
   if (!_active.empty()) {
     // There are more tasks; just set the next sort value.
     nassertr(_current_sort < _active.front()->get_sort(), true);
@@ -865,9 +869,6 @@ finish_sort_group() {
       _manager->_clock->tick();
       _manager->_frame_cvar.signal_all();
     }
-    if (!_threads.empty()) {
-      PStatClient::thread_tick(get_name());
-    }
     
     // Check for any sleeping tasks that need to be woken.
     double now = _manager->_clock->get_frame_time();
@@ -1145,6 +1146,10 @@ do_get_sleeping_tasks() const {
 ////////////////////////////////////////////////////////////////////
 void AsyncTaskChain::
 do_poll() {
+  if (_num_tasks == 0) {
+    return;
+  }
+
   do_start_threads();
 
   if (!_threads.empty()) {

+ 15 - 1
panda/src/event/asyncTaskManager.cxx

@@ -72,7 +72,21 @@ cleanup() {
     chain->do_cleanup();
   }
 
-  nassertv(_num_tasks == 0 && _tasks_by_name.empty());
+  // There might be one remaining task, the current task.  Especially
+  // if it wasn't running on a thread.
+  if (_num_tasks == 1) {
+    nassertv(_tasks_by_name.size() == 1);
+    TasksByName::const_iterator tbni = _tasks_by_name.begin();
+    AsyncTask *task = (*tbni);
+    nassertv(task->_state == AsyncTask::S_servicing || 
+             task->_state == AsyncTask::S_servicing_removed);
+    task->_state = AsyncTask::S_servicing_removed;
+
+  } else {
+    // If there isn't exactly one remaining task, there should be
+    // none.
+    nassertv(_num_tasks == 0 && _tasks_by_name.empty());
+  }
 }
 
 ////////////////////////////////////////////////////////////////////