You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by da...@apache.org on 2021/06/20 14:05:52 UTC
[incubator-nuttx-apps] 01/02: system/critmon: add critmon program
for critmon once
This is an automated email from the ASF dual-hosted git repository.
davids5 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git
commit 696c6f412e5e9f7b519c57fbb650ee580a601014
Author: ligd <li...@xiaomi.com>
AuthorDate: Wed Mar 31 23:30:53 2021 +0800
system/critmon: add critmon program for critmon once
Change-Id: Ifc1f384ad5321d23030aaa5e424627f5d8ae0484
Signed-off-by: ligd <li...@xiaomi.com>
---
system/critmon/Makefile | 2 +-
system/critmon/critmon.c | 147 ++++++++++++++++++++++++++---------------------
2 files changed, 84 insertions(+), 65 deletions(-)
diff --git a/system/critmon/Makefile b/system/critmon/Makefile
index 4fa237c..ec1c3cc 100644
--- a/system/critmon/Makefile
+++ b/system/critmon/Makefile
@@ -22,7 +22,7 @@ include $(APPDIR)/Make.defs
# Stack Monitor Application
-PROGNAME = critmon_start critmon_stop
+PROGNAME = critmon critmon_start critmon_stop
PRIORITY = $(CONFIG_SYSTEM_CRITMONITOR_PRIORITY)
STACKSIZE = $(CONFIG_SYSTEM_CRITMONITOR_STACKSIZE)
MODULE = $(CONFIG_SYSTEM_CRITMONITOR)
diff --git a/system/critmon/critmon.c b/system/critmon/critmon.c
index f54a45e..93e5c04 100644
--- a/system/critmon/critmon.c
+++ b/system/critmon/critmon.c
@@ -378,101 +378,115 @@ errout_with_filepath:
}
/****************************************************************************
- * Name: critmon_daemon
+ * Name: critmon_list_once
****************************************************************************/
-static int critmon_daemon(int argc, char **argv)
+static int critmon_list_once(void)
{
- DIR *dirp;
int exitcode = EXIT_SUCCESS;
int errcount = 0;
+ DIR *dirp;
int ret;
- printf("Csection Monitor: Running: %d\n", g_critmon.pid);
-
- /* Loop until we detect that there is a request to stop. */
-
- while (!g_critmon.stop)
- {
- /* Wait for the next sample interval */
-
- sleep(CONFIG_SYSTEM_CRITMONITOR_INTERVAL);
-
- /* Output a Header */
+ /* Output a Header */
#if CONFIG_TASK_NAME_SIZE > 0
- printf("PRE-EMPTION CSECTION PID DESCRIPTION\n");
+ printf("PRE-EMPTION CSECTION PID DESCRIPTION\n");
#else
- printf("PRE-EMPTION CSECTION PID\n");
+ printf("PRE-EMPTION CSECTION PID\n");
#endif
- printf("MAX DISABLE MAX TIME\n");
+ printf("MAX DISABLE MAX TIME\n");
- /* Should global usage first */
+ /* Should global usage first */
- critmon_global_crit();
+ critmon_global_crit();
- /* Open the top-level procfs directory */
+ /* Open the top-level procfs directory */
- dirp = opendir(CONFIG_SYSTEM_CRITMONITOR_MOUNTPOINT);
- if (dirp == NULL)
- {
- /* Failed to open the directory */
+ dirp = opendir(CONFIG_SYSTEM_CRITMONITOR_MOUNTPOINT);
+ if (dirp == NULL)
+ {
+ /* Failed to open the directory */
- fprintf(stderr, "Csection Monitor: Failed to open directory: %s\n",
- CONFIG_SYSTEM_CRITMONITOR_MOUNTPOINT);
+ fprintf(stderr, "Csection Monitor: Failed to open directory: %s\n",
+ CONFIG_SYSTEM_CRITMONITOR_MOUNTPOINT);
- if (++errcount > 100)
- {
- fprintf(stderr,
- "Csection Monitor: Too many errors ... exiting\n");
- exitcode = EXIT_FAILURE;
- break;
- }
+ if (++errcount > 100)
+ {
+ fprintf(stderr, "Csection Monitor: Too many errors ... exiting\n");
+ return EXIT_FAILURE;
}
+ }
- /* Read each directory entry */
+ /* Read each directory entry */
- for (; ; )
+ for (; ; )
+ {
+ FAR struct dirent *entryp = readdir(dirp);
+ if (entryp == NULL)
{
- FAR struct dirent *entryp = readdir(dirp);
- if (entryp == NULL)
- {
- /* Finished with this directory */
+ /* Finished with this directory */
- break;
- }
+ break;
+ }
- /* Task/thread entries in the /proc directory will all be (1)
- * directories with (2) all numeric names.
- */
+ /* Task/thread entries in the /proc directory will all be (1)
+ * directories with (2) all numeric names.
+ */
- if (DIRENT_ISDIRECTORY(entryp->d_type) &&
- critmon_check_name(entryp->d_name))
+ if (DIRENT_ISDIRECTORY(entryp->d_type) &&
+ critmon_check_name(entryp->d_name))
+ {
+ /* Looks good -- process the directory */
+
+ ret = critmon_process_directory(entryp);
+ if (ret < 0)
{
- /* Looks good -- process the directory */
+ /* Failed to process the thread directory */
- ret = critmon_process_directory(entryp);
- if (ret < 0)
- {
- /* Failed to process the thread directory */
+ fprintf(stderr, "Csection Monitor: "
+ "Failed to process sub-directory: %s\n",
+ entryp->d_name);
+ if (++errcount > 100)
+ {
fprintf(stderr, "Csection Monitor: "
- "Failed to process sub-directory: %s\n",
- entryp->d_name);
-
- if (++errcount > 100)
- {
- fprintf(stderr, "Csection Monitor: "
- "Too many errors ... exiting\n");
- exitcode = EXIT_FAILURE;
- break;
- }
+ "Too many errors ... exiting\n");
+ exitcode = EXIT_FAILURE;
+ break;
}
}
}
+ }
+
+ closedir(dirp);
+ fputc('\n', stdout);
+ return exitcode;
+}
+
+/****************************************************************************
+ * Name: critmon_daemon
+ ****************************************************************************/
+
+static int critmon_daemon(int argc, char **argv)
+{
+ int exitcode = EXIT_SUCCESS;
+
+ printf("Csection Monitor: Running: %d\n", g_critmon.pid);
+
+ /* Loop until we detect that there is a request to stop. */
+
+ while (!g_critmon.stop)
+ {
+ /* Wait for the next sample interval */
- closedir(dirp);
- fputc('\n', stdout);
+ sleep(CONFIG_SYSTEM_CRITMONITOR_INTERVAL);
+
+ exitcode = critmon_list_once();
+ if (exitcode != EXIT_SUCCESS)
+ {
+ break;
+ }
}
/* Stopped */
@@ -488,7 +502,7 @@ static int critmon_daemon(int argc, char **argv)
* Public Functions
****************************************************************************/
-int main(int argc, char **argv)
+int critmon_start_main(int argc, char **argv)
{
/* Has the monitor already started? */
@@ -549,4 +563,9 @@ int critmon_stop_main(int argc, char **argv)
return 0;
}
+int critmon_main(int argc, char **argv)
+{
+ return critmon_list_once();
+}
+
#endif /* CONFIG_SYSTEM_CRITMONITOR */