mirror of
https://git.openafs.org/openafs.git
synced 2025-01-18 15:00:12 +00:00
xstat: add xstat_*_Wait functions
Add the xstat_cm_Wait and xstat_fs_Wait functions and move the code to wait for the xstat data collection to complete from the applications down to the xstat library. This is a non-functional change in anticipation of converting the xstat library and programs to pthreads. Change-Id: Ifd1d6bcda618c89b4ce46e1e64f33b0b30a89a72 Reviewed-on: https://gerrit.openafs.org/12746 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
This commit is contained in:
parent
5ced6025b9
commit
2c1a7e4733
@ -3723,7 +3723,6 @@ afsmon_execute(void)
|
||||
int FSinitFlags = 0; /* flags for xstat_fs_Init */
|
||||
int CMinitFlags = 0; /* flags for xstat_cm_Init */
|
||||
int code; /* function return code */
|
||||
struct timeval tv; /* time structure */
|
||||
int i;
|
||||
short index;
|
||||
|
||||
@ -3897,24 +3896,8 @@ afsmon_execute(void)
|
||||
|
||||
/* This part of the code is reached only if the input server is not started
|
||||
* for debugging purposes */
|
||||
|
||||
/* sleep forever */
|
||||
tv.tv_sec = 24 * 60;
|
||||
tv.tv_usec = 0;
|
||||
fprintf(stderr, "[ %s ] going to sleep ...\n", rn);
|
||||
while (1) {
|
||||
code = IOMGR_Select(0, /*Num fds */
|
||||
0, /*Descriptors ready for reading */
|
||||
0, /*Descriptors ready for writing */
|
||||
0, /*Descriptors with exceptional conditions */
|
||||
&tv); /*Timeout structure */
|
||||
if (code) {
|
||||
fprintf(stderr,
|
||||
"[ %s ] IOMGR_Select() returned non-zero value %d\n", rn,
|
||||
code);
|
||||
afsmon_Exit(145);
|
||||
}
|
||||
} /* while sleep */
|
||||
xstat_cm_Wait(0); /* sleep forever */
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -642,3 +642,76 @@ xstat_cm_ForceProbeNow(void)
|
||||
*/
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Wait for the collection to complete. Returns after one cycle if running in
|
||||
* one-shot mode, otherwise wait for a given amount of time.
|
||||
*
|
||||
* Args:
|
||||
* int sleep_secs : time to wait in seconds when running
|
||||
* in continuous mode. 0 means wait forever.
|
||||
*
|
||||
* Returns:
|
||||
* 0 on success
|
||||
*/
|
||||
int
|
||||
xstat_cm_Wait(int sleep_secs)
|
||||
{
|
||||
static char rn[] = "xstat_cm_Wait"; /*Routine name */
|
||||
int code;
|
||||
struct timeval tv; /*Time structure */
|
||||
|
||||
if (xstat_cm_oneShot) {
|
||||
/*
|
||||
* One-shot operation; just wait for the collection to be done.
|
||||
*/
|
||||
if (xstat_cm_debug)
|
||||
printf("[%s] Calling LWP_WaitProcess() on event %" AFS_PTR_FMT
|
||||
"\n", rn, &terminationEvent);
|
||||
code = LWP_WaitProcess(&terminationEvent);
|
||||
if (xstat_cm_debug)
|
||||
printf("[%s] Returned from LWP_WaitProcess()\n", rn);
|
||||
if (code) {
|
||||
fprintf(stderr,
|
||||
"[%s] Error %d encountered by LWP_WaitProcess()\n",
|
||||
rn, code);
|
||||
}
|
||||
} else if (sleep_secs == 0) {
|
||||
/* Sleep forever. */
|
||||
tv.tv_sec = 24 * 60;
|
||||
tv.tv_usec = 0;
|
||||
if (xstat_cm_debug)
|
||||
fprintf(stderr, "[ %s ] going to sleep ...\n", rn);
|
||||
while (1) {
|
||||
code = IOMGR_Select(0, /*Num fds */
|
||||
0, /*Descriptors ready for reading */
|
||||
0, /*Descriptors ready for writing */
|
||||
0, /*Descriptors with exceptional conditions */
|
||||
&tv); /*Timeout structure */
|
||||
if (code) {
|
||||
fprintf(stderr,
|
||||
"[ %s ] IOMGR_Select() returned non-zero value %d\n",
|
||||
rn, code);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/* Let's just fall asleep while. */
|
||||
if (xstat_cm_debug)
|
||||
printf
|
||||
("xstat_cm service started, main thread sleeping for %d secs.\n",
|
||||
sleep_secs);
|
||||
tv.tv_sec = sleep_secs;
|
||||
tv.tv_usec = 0;
|
||||
code = IOMGR_Select(0, /*Num fds */
|
||||
0, /*Descriptors ready for reading */
|
||||
0, /*Descriptors ready for writing */
|
||||
0, /*Descriptors with exceptional conditions */
|
||||
&tv); /*Timeout structure */
|
||||
if (code)
|
||||
fprintf(stderr,
|
||||
"[%s] IOMGR_Select() returned non-zero value: %d\n", rn,
|
||||
code);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
@ -145,4 +145,17 @@ extern int xstat_cm_Cleanup(int);
|
||||
* with the xstat_cm connection array.
|
||||
*/
|
||||
|
||||
extern int xstat_cm_Wait(int sleep_secs);
|
||||
/*
|
||||
* Summary:
|
||||
* Wait for the collection to complete.
|
||||
*
|
||||
* Args:
|
||||
* int sleep_secs : time to wait in seconds when running
|
||||
* in continuous mode. 0 means wait forever.
|
||||
*
|
||||
* Returns:
|
||||
* 0 on success
|
||||
*/
|
||||
|
||||
#endif /* _xstat_cm_h_ */
|
||||
|
@ -747,10 +747,7 @@ RunTheTest(struct cmd_syndesc *a_s, void *arock)
|
||||
struct cmd_item *curr_item; /*Current CM cmd line record */
|
||||
struct sockaddr_in *CMSktArray; /*Cache Manager socket array */
|
||||
struct hostent *he; /*Host entry */
|
||||
struct timeval tv; /*Time structure */
|
||||
int sleep_secs; /*Number of seconds to sleep */
|
||||
int initFlags; /*Flags passed to the init fcn */
|
||||
int waitCode; /*Result of LWP_WaitProcess() */
|
||||
int freq; /*Frequency of polls */
|
||||
int period; /*Time in minutes of data collection */
|
||||
|
||||
@ -875,47 +872,8 @@ RunTheTest(struct cmd_syndesc *a_s, void *arock)
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if (one_shot) {
|
||||
/*
|
||||
* One-shot operation; just wait for the collection to be done.
|
||||
*/
|
||||
if (debugging_on)
|
||||
printf("[%s] Calling LWP_WaitProcess() on event %" AFS_PTR_FMT
|
||||
"\n", rn, &terminationEvent);
|
||||
waitCode = LWP_WaitProcess(&terminationEvent);
|
||||
if (debugging_on)
|
||||
printf("[%s] Returned from LWP_WaitProcess()\n", rn);
|
||||
if (waitCode) {
|
||||
if (debugging_on)
|
||||
fprintf(stderr,
|
||||
"[%s] Error %d encountered by LWP_WaitProcess()\n",
|
||||
rn, waitCode);
|
||||
}
|
||||
} else {
|
||||
/*
|
||||
* Continuous operation.
|
||||
*/
|
||||
sleep_secs = 60 * period; /*length of data collection */
|
||||
printf
|
||||
("xstat_cm service started, main thread sleeping for %d secs.\n",
|
||||
sleep_secs);
|
||||
|
||||
/*
|
||||
* Let's just fall asleep for a while, then we'll clean up.
|
||||
*/
|
||||
tv.tv_sec = sleep_secs;
|
||||
tv.tv_usec = 0;
|
||||
code = IOMGR_Select(0, /*Num fds */
|
||||
0, /*Descriptors ready for reading */
|
||||
0, /*Descriptors ready for writing */
|
||||
0, /*Descriptors with exceptional conditions */
|
||||
&tv); /*Timeout structure */
|
||||
if (code) {
|
||||
fprintf(stderr,
|
||||
"[%s] IOMGR_Select() returned non-zero value: %d\n", rn,
|
||||
code);
|
||||
}
|
||||
}
|
||||
/* Wait for the collection complete. */
|
||||
xstat_cm_Wait(60 * period);
|
||||
|
||||
/*
|
||||
* We're all done. Clean up, put the last nail in Rx, then
|
||||
|
@ -840,3 +840,76 @@ xstat_fs_DecodeFullPerfStats(struct fs_stats_FullPerfStats **aout,
|
||||
return 0;
|
||||
#undef DECODE_TV
|
||||
}
|
||||
|
||||
/*
|
||||
* Wait for the collection to complete. Returns after one cycle if running in
|
||||
* one-shot mode, otherwise wait for a given amount of time.
|
||||
*
|
||||
* Args:
|
||||
* int sleep_secs : time to wait in seconds when running
|
||||
* in continuous mode. 0 means wait forever.
|
||||
*
|
||||
* Returns:
|
||||
* 0 on success
|
||||
*/
|
||||
int
|
||||
xstat_fs_Wait(int sleep_secs)
|
||||
{
|
||||
static char rn[] = "xstat_fs_Wait"; /*Routine name */
|
||||
int code;
|
||||
struct timeval tv; /*Time structure */
|
||||
|
||||
if (xstat_fs_oneShot) {
|
||||
/*
|
||||
* One-shot operation; just wait for the collection to be done.
|
||||
*/
|
||||
if (xstat_fs_debug)
|
||||
printf("[%s] Calling LWP_WaitProcess() on event %" AFS_PTR_FMT
|
||||
"\n", rn, &terminationEvent);
|
||||
code = LWP_WaitProcess(&terminationEvent);
|
||||
if (xstat_fs_debug)
|
||||
printf("[%s] Returned from LWP_WaitProcess()\n", rn);
|
||||
if (code) {
|
||||
fprintf(stderr,
|
||||
"[%s] Error %d encountered by LWP_WaitProcess()\n",
|
||||
rn, code);
|
||||
}
|
||||
} else if (sleep_secs == 0) {
|
||||
/* Sleep forever. */
|
||||
tv.tv_sec = 24 * 60;
|
||||
tv.tv_usec = 0;
|
||||
if (xstat_fs_debug)
|
||||
fprintf(stderr, "[ %s ] going to sleep ...\n", rn);
|
||||
while (1) {
|
||||
code = IOMGR_Select(0, /*Num fds */
|
||||
0, /*Descriptors ready for reading */
|
||||
0, /*Descriptors ready for writing */
|
||||
0, /*Descriptors with exceptional conditions */
|
||||
&tv); /*Timeout structure */
|
||||
if (code) {
|
||||
fprintf(stderr,
|
||||
"[ %s ] IOMGR_Select() returned non-zero value %d\n",
|
||||
rn, code);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/* Let's just fall asleep while. */
|
||||
if (xstat_fs_debug)
|
||||
printf
|
||||
("xstat_fs service started, main thread sleeping for %d secs.\n",
|
||||
sleep_secs);
|
||||
tv.tv_sec = sleep_secs;
|
||||
tv.tv_usec = 0;
|
||||
code = IOMGR_Select(0, /*Num fds */
|
||||
0, /*Descriptors ready for reading */
|
||||
0, /*Descriptors ready for writing */
|
||||
0, /*Descriptors with exceptional conditions */
|
||||
&tv); /*Timeout structure */
|
||||
if (code)
|
||||
fprintf(stderr,
|
||||
"[%s] IOMGR_Select() returned non-zero value: %d\n", rn,
|
||||
code);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
@ -145,6 +145,19 @@ extern int xstat_fs_Cleanup(int);
|
||||
* with the xstat_fs connection array.
|
||||
*/
|
||||
|
||||
extern int xstat_fs_Wait(int sleep_secs);
|
||||
/*
|
||||
* Summary:
|
||||
* Wait for the collection to complete.
|
||||
*
|
||||
* Args:
|
||||
* int sleep_secs : time to wait in seconds when running
|
||||
* in continuous mode. 0 means wait forever.
|
||||
*
|
||||
* Returns:
|
||||
* 0 on success
|
||||
*/
|
||||
|
||||
/*
|
||||
* Decode the full performance statistics collection data.
|
||||
*/
|
||||
|
@ -660,10 +660,7 @@ RunTheTest(struct cmd_syndesc *a_s, void *dummy)
|
||||
struct cmd_item *curr_item; /*Current FS cmd line record */
|
||||
struct sockaddr_in FSSktArray[20]; /*File Server socket array - FIX! */
|
||||
struct hostent *he; /*Host entry */
|
||||
struct timeval tv; /*Time structure */
|
||||
int sleep_secs; /*Number of seconds to sleep */
|
||||
int initFlags; /*Flags passed to the init fcn */
|
||||
int waitCode; /*Result of LWP_WaitProcess() */
|
||||
int freq; /*Frequency of polls */
|
||||
int period; /*Time in minutes of data collection */
|
||||
|
||||
@ -772,47 +769,8 @@ RunTheTest(struct cmd_syndesc *a_s, void *dummy)
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if (one_shot) {
|
||||
/*
|
||||
* One-shot operation; just wait for the collection to be done.
|
||||
*/
|
||||
if (debugging_on)
|
||||
printf("[%s] Calling LWP_WaitProcess() on event %" AFS_PTR_FMT "\n", rn,
|
||||
&terminationEvent);
|
||||
waitCode = LWP_WaitProcess(&terminationEvent);
|
||||
if (debugging_on)
|
||||
printf("[%s] Returned from LWP_WaitProcess()\n", rn);
|
||||
if (waitCode) {
|
||||
if (debugging_on)
|
||||
fprintf(stderr,
|
||||
"[%s] Error %d encountered by LWP_WaitProcess()\n",
|
||||
rn, waitCode);
|
||||
}
|
||||
} else {
|
||||
/*
|
||||
* Continuous operation.
|
||||
*/
|
||||
sleep_secs = 60 * period; /*length of data collection */
|
||||
printf
|
||||
("xstat_fs service started, main thread sleeping for %d secs.\n",
|
||||
sleep_secs);
|
||||
|
||||
/*
|
||||
* Let's just fall asleep for a while, then we'll clean up.
|
||||
*/
|
||||
tv.tv_sec = sleep_secs;
|
||||
tv.tv_usec = 0;
|
||||
code = IOMGR_Select(0, /*Num fds */
|
||||
0, /*Descriptors ready for reading */
|
||||
0, /*Descriptors ready for writing */
|
||||
0, /*Descriptors with exceptional conditions */
|
||||
&tv); /*Timeout structure */
|
||||
if (code) {
|
||||
fprintf(stderr,
|
||||
"[%s] IOMGR_Select() returned non-zero value: %d\n", rn,
|
||||
code);
|
||||
}
|
||||
}
|
||||
/* Wait for the collection complete. */
|
||||
xstat_fs_Wait(60 * period);
|
||||
|
||||
/*
|
||||
* We're all done. Clean up, put the last nail in Rx, then
|
||||
|
Loading…
Reference in New Issue
Block a user