Revision e5742249

View differences:

core/src/aos_system.c
540 540
#if (AMIROOS_CFG_DBG == true)
541 541
  chprintf(stream, "\tthread stack size:      %u bytes\n", aosThdGetStacksize(aos.shell.thread));
542 542
#if (CH_DBG_FILL_THREADS == TRUE)
543
  chprintf(stream, "\tstack peak utilization: %u bytes (%.2f%%)\n", aosThdGetStackPeakUtilization(aos.shell.thread), (double)((float)(aosThdGetStackPeakUtilization(aos.shell.thread)) / (float)(aosThdGetStacksize(aos.shell.thread)) * 100.0f));
543
  {
544
    const size_t utilization = aosThdGetStackPeakUtilization(aos.shell.thread);
545
    chprintf(stream, "\tstack peak utilization: %u bytes (%.2f%%)\n", utilization, (double)((float)utilization / (float)(aosThdGetStacksize(aos.shell.thread)) * 100.0f));
546
  }
544 547
#endif /* (CH_DBG_FILL_THREADS == TRUE) */
545 548
#endif /* (AMIROOS_CFG_DBG == true) */
546 549
  _printSystemInfoSeparator(stream, '=', SYSTEM_INFO_WIDTH);
core/src/aos_thread.c
91 91
{
92 92
  aosDbgCheck(thread != NULL);
93 93

  
94
  size_t util;
95
  uint8_t* ptr = (uint8_t*)thread->wabase;
96

  
97
  while (*ptr == CH_DBG_STACK_FILL_VALUE && ptr < (uint8_t*)thread->wabase + aosThdGetStacksize(thread)) {
98
    ++ptr;
94
  // iterator through the stack
95
  // note: since the stack is filled from top to bottom, the loop searches for the first irregular byte from the bottom (stack end).
96
  for (uint8_t* ptr = (uint8_t*)thread->wabase; ptr < (uint8_t*)thread->wabase + aosThdGetStacksize(thread); ++ptr) {
97
    if (*ptr != CH_DBG_STACK_FILL_VALUE) {
98
      return aosThdGetStacksize(thread) - (size_t)(--ptr - (uint8_t*)thread->wabase);
99
    }
99 100
  }
100
  util = aosThdGetStacksize(thread) - (ptr - (uint8_t*)thread->wabase);
101 101

  
102
  return util;
102
  return 0;
103 103
}
104 104
#endif /* (AMIROOS_CFG_DBG == true) && (CH_DBG_FILL_THREADS == TRUE) */
105 105

  

Also available in: Unified diff