This chapter describes the GemStone C Statistics Interface (GCSI), a library of functions that allow your C application to collect GemStone statistics directly from the shared page cache without starting a database session.
The command lines in this chapter assume that you have set the $GEMSTONE environment variable to your GemStone installation directory.
Your GCSI program must include the following header files:
GemStone provides a shared library, $GEMSTONE/lib/libgcsi-3.5.0-64.so, that your program will load at runtime.
export LD_LIBRARY_PATH=$GEMSTONE/lib:$LD_LIBRARY_PATH
The $GEMSTONE/examples directory includes the sample GCSI program gsstat.cc, along with a set of sample makefiles that show how to compile the sample GCSI program, using the compilers that are used to build the GemStone product.
NOTE
It may still be possible to build your program with another compiler, as long as you specify the appropriate flags to enable multi-threading.
Whenever you upgrade to a new GemStone version, you must re-compile and re-link all your GCSI programs. This is because the internal structure of the shared cache may change from version to version. Assuming you’ve created a makefile, all you should need to do is change $GEMSTONE and rebuild.
The GCSI library allows your program to connect to a single GemStone shared page cache. Once the connection is made, a thread is started to monitor the cache and disconnect from it if the cache monitor process dies. This thread is needed to prevent your program from "holding on" to the shared cache after all other processes have detached from it. In this way, your program can safely sleep for a long time without preventing the operating system from freeing and recycling shared memory should the Stone be unexpectedly shut down.
The sample program gsstat.cc (in $GEMSTONE/examples) monitors a running GemStone repository by printing out a set of statistics at a regular interval that you specify. The program prints the following statistics:
To invoke gsstat, supply the name of a running Stone (or shared page cache, if running on a Gem server) and a time interval in seconds. For example:
% gsstat myStone 2
To stop the gsstat program and detach from the cache, issue a CTRL-C.
The following C types are used by GCSI functions. The file shrpcstats.ht defines each of the GCSI types (shown in capital letters below). That file is in the $GEMSTONE/include directory.
The union of all four statistics structured types: shared page cache monitor, page server, Stone, and Gem. |
|
Common statistics collected for all processes attached to the shared cache. |
The structured type GcsiResultSType provides a C representation of the result of executing a GCSI function. This structure contains the following fields:
typedef struct {
signed int processId;
signed int sessionId;
ShrPcCommonStatSType cmn;
union ShrPcStatUnion u;
} ShrPcStatsSType;
class GcsiResultSType {
public:
char vsdName[SHRPC_PROC_NAME_SIZE + 1];
unsigned int statType;
ShrPcStatsSType stats;
};
In addition, a set of C mnemonics support representation of the count of each process-specific structured type:
#define COMMON_STAT_COUNT
(sizeof(ShrPcCommonStatSType)/sizeof(int))
#define SHRPC_STAT_COUNT
(sizeof(ShrPcMonStatSType)/sizeof(int) + COMMON_STAT_COUNT)
#define GEM_STAT_COUNT
(sizeof(ShrPcGemStatSType)/sizeof(int) + COMMON_STAT_COUNT)
#define PGSVR_STAT_COUNT
(sizeof(ShrPcPgsvrStatSType)/sizeof(int) + COMMON_STAT_COUNT)
#define STN_STAT_COUNT
(sizeof(ShrPcStnStatSType)/sizeof(int) + COMMON_STAT_COUNT)
Get all cache statistics for a specified set of processes.
Returns 0 if successful; otherwise returns an error code, as defined in gcsierr.ht; see GCSI Errors.
Attach to the specified shared page cache.
Full name of the shared page cache, in the format stoneName@stoneHostIpAddress. To determine the full name of the shared cache, use the gslist -x utility. |
|
Returns 0 if successful; otherwise returns an error code, as defined in gcsierr.ht; see GCSI Errors.
Attaches this process to the specified shared page cache.
int GcsiAttachSharedCacheForStone(
const char * stoneName,
char * errBuf,
size_t errBufSize);
Returns 0 if successful; otherwise returns an error code, as defined in gcsierr.ht; see GCSI Errors.
This function assumes that the cache name is <stoneName>@<thisIpAddress> where thisIpAddress is the IP address of the local machine. This function may fail if the host is multi-homed (has more than one network interface). In that case, use GcsiAttachSharedCache to specify the full name of the shared cache.
Detach from the shared page cache.
Returns 0 if successful; otherwise returns an error code, as defined in gcsierr.ht; see GCSI Errors.
Return the maximum number of processes that can be attached to this shared cache at any instant. The result may be used to allocate memory for a calls to the GcsiFetchStatsForAll* family of functions.
Returns 0 if successful; otherwise returns an error code, as defined in gcsierr.ht; see GCSI Errors.
Get the cache statistics for the given Gem session id.
Returns 0 if successful; otherwise returns an error code, as defined in gcsierr.ht; see GCSI Errors.
Get the cache statistics for the first Gem in the cache with the given cache name.
Returns 0 if successful; otherwise returns an error code, as defined in gcsierr.ht; see GCSI Errors.
Get the cache statistics for the given page server with the given session id. Remote Gems have page servers on the Stone’s cache that assume the same session ID as the remote Gem.
Returns 0 if successful; otherwise returns an error code, as defined in gcsierr.ht; see GCSI Errors.
Get the cache statistics for the given process ID.
Returns 0 if successful; otherwise returns an error code, as defined in gcsierr.ht; see GCSI Errors.
Get the cache statistics for the shared page cache monitor process for this shared page cache.
Returns 0 if successful; otherwise returns an error code, as defined in gcsierr.ht; see GCSI Errors.
Get the cache statistics for the Stone if there is a Stone attached to this shared page cache.
Returns 0 if successful; otherwise returns an error code, as defined in gcsierr.ht; see GCSI Errors.