Add Valgrind commands check, quick, added, changed where available
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
#include <tcl.h>
|
||||
#include <site.h>
|
||||
#include <SCinter.h>
|
||||
#include <valgrind/memcheck.h>
|
||||
|
||||
#include "protocol.h"
|
||||
#include "sicslist.h"
|
||||
@@ -109,6 +110,120 @@ int SICS_Revision(SConnection *pCon, SicsInterp *pSics, void *pData, int argc, c
|
||||
return OKOK;
|
||||
};
|
||||
|
||||
static int Ansto_Valgrind(SConnection *pCon, SicsInterp *pSics, void *pData, int argc, char *argv[])
|
||||
{
|
||||
/* check authorisation: only users permitted here */
|
||||
if (!SCMatchRights(pCon, usUser)) {
|
||||
SCWrite(pCon, "ERROR: Insufficient Privilege to do Valgrind", eError);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* check enough arguments */
|
||||
if (argc < 2) {
|
||||
SCWrite(pCon, "ERROR: Valgrind subcommand not specified ", eError);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (strcasecmp(argv[1], "added") == 0) {
|
||||
#ifdef VALGRIND_DO_ADDED_LEAK_CHECK
|
||||
VALGRIND_DO_ADDED_LEAK_CHECK;
|
||||
SCSendOK(pCon);
|
||||
#else
|
||||
SCPrintf(pCon, eError, "VALGRIND_DO_ADDED_LEAK_CHECK not supported for %s", argv[1]);
|
||||
#endif
|
||||
return OKOK;
|
||||
}
|
||||
|
||||
if (strcasecmp(argv[1], "changed") == 0) {
|
||||
#ifdef VALGRIND_DO_CHANGED_LEAK_CHECK
|
||||
VALGRIND_DO_CHANGED_LEAK_CHECK;
|
||||
SCSendOK(pCon);
|
||||
#else
|
||||
SCPrintf(pCon, eError, "VALGRIND_DO_CHANGED_LEAK_CHECK not supported for %s", argv[1]);
|
||||
#endif
|
||||
return OKOK;
|
||||
}
|
||||
|
||||
if (strcasecmp(argv[1], "quick") == 0) {
|
||||
#ifdef VALGRIND_DO_QUICK_LEAK_CHECK
|
||||
VALGRIND_DO_QUICK_LEAK_CHECK;
|
||||
SCSendOK(pCon);
|
||||
#else
|
||||
SCPrintf(pCon, eError, "VALGRIND_DO_QUICK_LEAK_CHECK not supported for %s", argv[1]);
|
||||
#endif
|
||||
return OKOK;
|
||||
}
|
||||
|
||||
if (strcasecmp(argv[1], "check") == 0) {
|
||||
#ifdef VALGRIND_DO_LEAK_CHECK
|
||||
VALGRIND_DO_LEAK_CHECK;
|
||||
SCSendOK(pCon);
|
||||
#else
|
||||
SCPrintf(pCon, eError, "VALGRIND_DO_LEAK_CHECK not supported for %s", argv[1]);
|
||||
#endif
|
||||
return OKOK;
|
||||
}
|
||||
|
||||
if (strcasecmp(argv[1], "bytes") == 0) {
|
||||
#ifdef VALGRIND_COUNT_LEAKS
|
||||
static long int leaked_bytes = 0;
|
||||
static long int dubious_bytes = 0;
|
||||
static long int reachable_bytes = 0;
|
||||
static long int suppressed_bytes = 0;
|
||||
long int leaked = 0;
|
||||
long int dubious = 0;
|
||||
long int reachable = 0;
|
||||
long int suppressed = 0;
|
||||
VALGRIND_COUNT_LEAKS(leaked, dubious, reachable, suppressed);
|
||||
if (argc > 2 && strcasecmp(argv[2], "delta") == 0) {
|
||||
SCPrintf(pCon, eStatus, "Valgrind delta bytes: leaked=%ld, dubious=%ld, reachable=%ld, suppressed=%ld",
|
||||
leaked - leaked_bytes, dubious - dubious_bytes, reachable - reachable_bytes, suppressed - suppressed_bytes);
|
||||
} else {
|
||||
SCPrintf(pCon, eStatus, "Valgrind bytes: leaked=%ld, dubious=%ld, reachable=%ld, suppressed=%ld",
|
||||
leaked, dubious, reachable, suppressed);
|
||||
}
|
||||
leaked_bytes = leaked;
|
||||
dubious_bytes = dubious;
|
||||
reachable_bytes = reachable;
|
||||
suppressed_bytes = suppressed;
|
||||
#else
|
||||
SCPrintf(pCon, eError, "VALGRIND_COUNT_LEAKS not supported for %s", argv[1]);
|
||||
#endif
|
||||
return OKOK;
|
||||
}
|
||||
|
||||
if (strcasecmp(argv[1], "blocks") == 0) {
|
||||
#ifdef VALGRIND_COUNT_LEAK_BLOCKS
|
||||
static long int leaked_blocks = 0;
|
||||
static long int dubious_blocks = 0;
|
||||
static long int reachable_blocks = 0;
|
||||
static long int suppressed_blocks = 0;
|
||||
long int leaked = 0;
|
||||
long int dubious = 0;
|
||||
long int reachable = 0;
|
||||
long int suppressed = 0;
|
||||
VALGRIND_COUNT_LEAK_BLOCKS(leaked, dubious, reachable, suppressed);
|
||||
if (argc > 2 && strcasecmp(argv[2], "delta") == 0) {
|
||||
SCPrintf(pCon, eStatus, "Valgrind delta blocks: leaked=%ld, dubious=%ld, reachable=%ld, suppressed=%ld",
|
||||
leaked - leaked_blocks, dubious - dubious_blocks, reachable - reachable_blocks, suppressed - suppressed_blocks);
|
||||
} else {
|
||||
SCPrintf(pCon, eStatus, "Valgrind blocks: leaked=%ld, dubious=%ld, reachable=%ld, suppressed=%ld",
|
||||
leaked, dubious, reachable, suppressed);
|
||||
}
|
||||
leaked_blocks = leaked;
|
||||
dubious_blocks = dubious;
|
||||
reachable_blocks = reachable;
|
||||
suppressed_blocks = suppressed;
|
||||
#else
|
||||
SCPrintf(pCon, eError, "VALGRIND_COUNT_LEAK_BLOCKS not supported for %s", argv[1]);
|
||||
#endif
|
||||
return OKOK;
|
||||
}
|
||||
|
||||
SCPrintf(pCon, eError, "Valgrind subcommand not supported for %s", argv[1]);
|
||||
return OKOK;
|
||||
}
|
||||
|
||||
void SiteReportVersion(void)
|
||||
{
|
||||
fprintf(stdout, "SICS version=%s revision=%s at %s\n",
|
||||
@@ -227,6 +342,7 @@ static void AddCommands(SicsInterp *pInter)
|
||||
AddCommand(pInter,"SICS_Revision",SICS_Revision,NULL,NULL);
|
||||
AddCommand(pInter, "sicslist", SicsList, NULL, NULL);
|
||||
AddCommand(pInter, "FileEvalGlob", MacroFileEvalGlob, NULL, NULL);
|
||||
AddCommand(pInter, "Valgrind", Ansto_Valgrind, NULL, NULL);
|
||||
|
||||
/*
|
||||
* Tcl 8.5 has implemented the clock command in tcl rather then C.
|
||||
|
||||
Reference in New Issue
Block a user