Skip to content
This repository has been archived by the owner on Sep 27, 2023. It is now read-only.

Develop fix rusage format error and add global rusage data #745

Merged
merged 4 commits into from
Sep 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions docs/Global/Rusage_data.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[[/Global/Rusage_data]] -- Resource usage data

# Synopsis

Python:

~~~
import gridlabd
gridlabd.get_global("rusage_data")
~~~

# Description

Hold the `rusage` data in JSON format.

# See also

* [[/Command/Rusage]]
* [[/Global/Rusage_rate]]
* [[/Global/Rusage_file]]
1 change: 1 addition & 0 deletions docs/Global/Rusage_file.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ Specifies the file in which system resource usage data is collected
# See also

* [[/Command/Rusage]]
* [[/Global/Rusage_data]]
* [[/Global/Rusage_rate]]
1 change: 1 addition & 0 deletions docs/Global/Rusage_rate.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ Specifies the rate at which system resource usage data is collected. The default

* [[/Command/Rusage]]
* [[/Global/Clock]]
* [[/Global/Rusage_data]]
* [[/Global/Rusage_file]]
70 changes: 48 additions & 22 deletions gldcore/exec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,28 +94,57 @@ static FILE *rusage_fp = NULL;

static void rusage_report(void)
{
static bool failed = false;
if ( rusage_fp == NULL && ! failed )
{
rusage_fp = fopen((const char*)global_rusage_file,"w");
if ( rusage_fp == NULL )
{
failed = true;
output_warning("unable to open '%s' for write access", (const char*)global_rusage_file);
}
else
struct rusage r;
if ( getrusage(RUSAGE_SELF,&r) == 0 )
{
snprintf(global_rusage_data,sizeof(global_rusage_data),
"{"
"\"utime\" : %ld.%06ld, "
"\"stime\" : %ld.%06ld, "
"\"maxrss\" : %ld, "
"\"ixrss\" : %ld, "
"\"idrss\" : %ld, "
"\"isrss\" : %ld, "
"\"minflt\" : %ld, "
"\"majflt\" : %ld, "
"\"nswap\" : %ld, "
"\"inblock\" : %ld, "
"\"oublock\" : %ld, "
"\"msgsnd\" : %ld, "
"\"msgrcv\" : %ld, "
"\"nsignals\" : %ld, "
"\"nvcsw\" : %ld, "
"\"nivcsw\" : %ld"
"}",
(long)(r.ru_utime.tv_sec),(long)(r.ru_utime.tv_usec),
(long)(r.ru_stime.tv_sec),(long)(r.ru_stime.tv_usec),
r.ru_maxrss, r.ru_ixrss, r.ru_idrss, r.ru_isrss,
r.ru_minflt, r.ru_majflt, r.ru_nswap,
r.ru_inblock, r.ru_oublock,
r.ru_msgsnd, r.ru_msgrcv,
r.ru_nsignals, r.ru_nvcsw, r.ru_nivcsw);
}
if ( global_rusage_rate > 0 && ( global_clock % global_rusage_rate ) == 0 )
{
static bool failed = false;
if ( rusage_fp == NULL && ! failed )
{
fprintf(rusage_fp,"%s","timestamp,utime,stime,maxrss,ixrss,idrss,isrss,minflt,majflt,nswap,inblock,oublock,msgsnd,msgrcv,nsignals,nvcsw,nivcsw\n");
rusage_fp = fopen((const char*)global_rusage_file,"w");
if ( rusage_fp == NULL )
{
failed = true;
output_warning("unable to open '%s' for write access", (const char*)global_rusage_file);
}
else
{
fprintf(rusage_fp,"%s","timestamp,utime,stime,maxrss,ixrss,idrss,isrss,minflt,majflt,nswap,inblock,oublock,msgsnd,msgrcv,nsignals,nvcsw,nivcsw\n");
}
}
}
if ( rusage_fp != NULL )
{
struct rusage r;
if ( getrusage(RUSAGE_SELF,&r) == 0 )
if ( rusage_fp != NULL )
{
fprintf(rusage_fp,"%lld,"
"%ld.%ld,"
"%ld.%ld,"
"%ld.%06ld,"
"%ld.%06ld,"
"%ld,%ld,%ld,%ld,"
"%ld,%ld,%ld,"
"%ld,%ld,"
Expand Down Expand Up @@ -2816,10 +2845,7 @@ STATUS GldExec::exec_start(void)
realtime_run_schedule();

/* report rusage */
if ( global_rusage_rate > 0 && ( global_clock % global_rusage_rate ) == 0 )
{
rusage_report();
}
rusage_report();
}

/* count number of passes */
Expand Down
2 changes: 2 additions & 0 deletions gldcore/globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,8 @@ DEPRECATED static struct s_varmap {
{"json_complex_format",PT_set,&global_json_complex_format,PA_PUBLIC,"JSON complex number format",jcf_keys},
{"rusage_file",PT_char1024,&global_rusage_file,PA_PUBLIC,"file in which resource usage data is collected"},
{"rusage_rate",PT_int64,&global_rusage_rate,PA_PUBLIC,"rate at which resource usage data is collected (in seconds)"},
{"rusage",PT_char1024,&global_rusage_data,PA_PUBLIC,"rusage data"},

/* add new global variables here */
};

Expand Down
2 changes: 2 additions & 0 deletions gldcore/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,8 @@ GLOBAL int64 global_rusage_rate INIT(0);
/* Variable: global_rusage_file */
GLOBAL char1024 global_rusage_file INIT("gridlabd-rusage.csv");

GLOBAL char1024 global_rusage_data INIT("{}");

#undef GLOBAL
#undef INIT

Expand Down