Skip to content

Conversation

@chenzihan0416
Copy link
Contributor

Summary

This PR introduces a new Sensor Monitor feature - a dynamic debugging tool for NuttX sensor subsystem that provides runtime control over sensor logging without requiring system rebuild.

Impact

Significantly improves debugging experience for sensor-related issues

No Breaking Changes: Feature is opt-in via Kconfig

Testing

Testing on qemu

Add monitoring topics to sensor_monitor

goldfish-armv8a-ap> echo 1 sensor_accel0 2 sensor_baro0 > /proc/sensor_monitor
goldfish-armv8a-ap> cat /proc/sensor_monitor
Sensor procfs - Dynamic sensor debugging tool

Usage:
  cat /proc/sensor_monitor - Show currently monitored topics
  echo <level> <topic> > /proc/sensor_monitor - Add topic(s)
  echo rm <topic> > /proc/sensor_monitor - Remove topic(s)
  echo add <topic> <topic> > /proc/sensor_monitor - add/remove topics
  echo clean > /proc/sensor_monitor      - Remove all topics

Examples:
  echo sensor_accel > /proc/sensor_monitor
  echo "sensor_accel sensor_compass" > /proc/sensor_monitor
  echo "1 sensor_accel sensor_compass" > /proc/sensor_monitor
  echo "2 sensor_accel sensor_compass" > /proc/sensor_monitor
  echo "rm sensor_accel" > /proc/sensor_monitor
  echo "rm sensor_accel sensor_compass" > /proc/sensor_monitor
  echo clean > /proc/sensor_monitor
  echo "add 1 sensor_a rm sensor_b" > /proc/sensor_monitor

Note:
  If <level> is not specified, it defaults to 1.
sensor_accel0       	1                   
sensor_baro0        	1                   
goldfish-armv8a-ap> 

Delete the monitored topic

goldfish-armv8a-ap> echo clean > /proc/sensor_monitor
goldfish-armv8a-ap> cat /proc/sensor_monitor
Sensor procfs - Dynamic sensor debugging tool

Usage:
  cat /proc/sensor_monitor - Show currently monitored topics
  echo <level> <topic> > /proc/sensor_monitor - Add topic(s)
  echo rm <topic> > /proc/sensor_monitor - Remove topic(s)
  echo add <topic> <topic> > /proc/sensor_monitor - add/remove topics
  echo clean > /proc/sensor_monitor      - Remove all topics

Examples:
  echo sensor_accel > /proc/sensor_monitor
  echo "sensor_accel sensor_compass" > /proc/sensor_monitor
  echo "1 sensor_accel sensor_compass" > /proc/sensor_monitor
  echo "2 sensor_accel sensor_compass" > /proc/sensor_monitor
  echo "rm sensor_accel" > /proc/sensor_monitor
  echo "rm sensor_accel sensor_compass" > /proc/sensor_monitor
  echo clean > /proc/sensor_monitor
  echo "add 1 sensor_a rm sensor_b" > /proc/sensor_monitor

Note:
  If <level> is not specified, it defaults to 1.

goldfish-armv8a-ap> echo 1 sensor_accel0 > /proc/sensor_monitor
goldfish-armv8a-ap> cat /proc/sensor_monitor
Sensor procfs - Dynamic sensor debugging tool

Usage:
  cat /proc/sensor_monitor - Show currently monitored topics
  echo <level> <topic> > /proc/sensor_monitor - Add topic(s)
  echo rm <topic> > /proc/sensor_monitor - Remove topic(s)
  echo add <topic> <topic> > /proc/sensor_monitor - add/remove topics
  echo clean > /proc/sensor_monitor      - Remove all topics

Examples:
  echo sensor_accel > /proc/sensor_monitor
  echo "sensor_accel sensor_compass" > /proc/sensor_monitor
  echo "1 sensor_accel sensor_compass" > /proc/sensor_monitor
  echo "2 sensor_accel sensor_compass" > /proc/sensor_monitor
  echo "rm sensor_accel" > /proc/sensor_monitor
  echo "rm sensor_accel sensor_compass" > /proc/sensor_monitor
  echo clean > /proc/sensor_monitor
  echo "add 1 sensor_a rm sensor_b" > /proc/sensor_monitor

Note:
  If <level> is not specified, it defaults to 1.
sensor_accel0       	1                   
goldfish-armv8a-ap> 
goldfish-armv8a-ap> 
goldfish-armv8a-ap> echo "rm sensor_accel0" > /proc/sensor_monitor
goldfish-armv8a-ap> Aececat /proc/sensor_monitor
Sensor procfs - Dynamic sensor debugging tool

Usage:
  cat /proc/sensor_monitor - Show currently monitored topics
  echo <level> <topic> > /proc/sensor_monitor - Add topic(s)
  echo rm <topic> > /proc/sensor_monitor - Remove topic(s)
  echo add <topic> <topic> > /proc/sensor_monitor - add/remove topics
  echo clean > /proc/sensor_monitor      - Remove all topics

Examples:
  echo sensor_accel > /proc/sensor_monitor
  echo "sensor_accel sensor_compass" > /proc/sensor_monitor
  echo "1 sensor_accel sensor_compass" > /proc/sensor_monitor
  echo "2 sensor_accel sensor_compass" > /proc/sensor_monitor
  echo "rm sensor_accel" > /proc/sensor_monitor
  echo "rm sensor_accel sensor_compass" > /proc/sensor_monitor
  echo clean > /proc/sensor_monitor
  echo "add 1 sensor_a rm sensor_b" > /proc/sensor_monitor

Note:
  If <level> is not specified, it defaults to 1.
goldfish-armv8a-ap> 

Log printing when listening to sensor_accel0

sensor_accel0       	7                   
goldfish-armv8a-ap> uorb_listener sensor_accel
[  153.708584] [79] [  INFO] [ap] sensor_open: [topic: sensor_accel0] user address: 0x40ef8330, role type: 0, user generation: 22, upper generation: 22, nsubscribers: 0, nadvertisers: 1, persist: 0
[  153.710719] [79] [  INFO] [ap] sensor_close: [topic: sensor_accel0] user address: 0x40ef8330, close subscriber: 0, close advertiser:1

Mointor objects num:1
object_name:sensor_accel, object_instance:0
[  153.715162] [79] [  INFO] [ap] sensor_open: [topic: sensor_accel0] user address: 0x40f2a120, role type: 2, user generation: 22, upper generation: 22, nsubscribers: 1, nadvertisers: 1, persist: 0
[  153.708584] [79] [  INFO] [ap] sensor_open: [topic: sensor_accel0] user address: 0x40ef8330, role type: 0, user generation: 22, upper generation: 22, nsubscribers: 0, nadvertisers: 1, persist: 0
[  153.710719] [79] [  INFO] [ap] sensor_close: [topic: sensor_accel0] user address: 0x40ef8330, close subscriber: 0, close advertiser:1
[  153.715162] [79] [  INFO] [ap] sensor_open: [topic: sensor_accel0] user address: 0x40f2a120, role type: 2, user generation: 22, upper genera[  153.723194] [ 6] [  INFO] [ap] sensor_push_event: [topic: sensor_accel0] the number of write event is:1
[  153.723970] [79] [  INFO] [ap] sensor_do_samples: [topic: sensor_accel0] do sample interval:23, user.generation:23, ret:32
[  153.724229] [79] [  INFO] [ap] sensor_read: [topic: sensor_accel0] the number of read event is:1
sensor_accel(now:153724557):timestamp:153722454,x:0.000000,y:9.776310,z:0.812349,temperature:nan
  "Sensor procfs - Dynamic sensor debugging tool\n"
  "\n"
  "Usage:\n"
  "  cat /proc/sensor_monitor - Show currently monitored topics\n"
  "  echo <level> <topic> > /proc/sensor_monitor - Add topic(s)\n"
  "  echo rm <topic> > /proc/sensor_monitor - Remove topic(s)\n"
  "  echo add <topic> <topic> > /proc/sensor_monitor"
  " - add/remove topics\n"
  "  echo clean > /proc/sensor_monitor      - Remove all topics\n"
  "\n"
  "Examples:\n"
  "  echo sensor_accel > /proc/sensor_monitor\n"
  "  echo \"sensor_accel sensor_compass\" > /proc/sensor_monitor\n"
  "  echo \"1 sensor_accel sensor_compass\" > /proc/sensor_monitor\n"
  "  echo \"2 sensor_accel sensor_compass\" > /proc/sensor_monitor\n"
  "  echo \"rm sensor_accel\" > /proc/sensor_monitor\n"
  "  echo \"rm sensor_accel sensor_compass\" > /proc/sensor_monitor\n"
  "  echo clean > /proc/sensor_monitor\n"
  "  echo \"add 1 sensor_a rm sensor_b\" > /proc/sensor_monitor\n"
  "\n"
  "Note:\n"
  "  If <level> is not specified, it defaults to 1.\n";

Signed-off-by: chenzihan1 <chenzihan1@xiaomi.com>
@github-actions github-actions bot added Area: Documentation Improvements or additions to documentation Area: Sensors Sensors issues Size: XL The size of the change in this PR is very large. Consider breaking down the PR into smaller pieces. labels Dec 31, 2025
Copy link
Contributor

@acassis acassis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chenzihan0416 Please include the goldfish board profile with this sensor driver. Also please include in the goldfish profile Documentation the steps that you added in the Testing

@acassis
Copy link
Contributor

acassis commented Dec 31, 2025

@chenzihan0416 please explain for someone new to NuttX what "Sensor Monitor feature - a dynamic debugging tool for NuttX sensor subsystem that provides runtime control over sensor logging without requiring system rebuild." means?

You explained in high level "WHAT" it is, but it has so many terms that requires more explanation: "dynamic debugging tool", "runtime control", "system rebuild".

Please explain for the end user what is the purpose of this driver in simple phrases, what problem is it solving? And why and when the user will want to use it.

Currently users can use apps/system/sensortest and apps/system/uorb, please explain the limitation of these existing tool that this sensor monitor can help to solve.

@acassis acassis requested review from cederom and jerpelea December 31, 2025 11:40
Copy link
Contributor

@cederom cederom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @chenzihan0416 very nice feature!! :-)

There are some CI build errors to be fixed please :-)

Also as @acassis noticed some more information would be nice to have in the documentation, with usage examples, and comparison to existing sensor testing tools.. or this is only expansion of control mechanisms to existing ones right? This may not be clear to newcomers but very handy :-)

Copy link
Contributor

@linguini1 linguini1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in PR title: dirvers -> drivers
Please use the PR title as the commit message as well.

Does this do any operations that explicitly require it to be a kernel module? As in, could this be a stand-alone app in NuttX apps?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Documentation Improvements or additions to documentation Area: Sensors Sensors issues Size: XL The size of the change in this PR is very large. Consider breaking down the PR into smaller pieces.

6 participants