mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-05 04:30:38 +03:00
Enhance the ".stats" command in sqlite3.exe to show one-time stats information
if invoked with one argument. Also show /proc/PID/io information if run on Linux. FossilOrigin-Name: 3c36948f16b58fe8042c37d0df634308b4e48217
This commit is contained in:
47
src/shell.c
47
src/shell.c
@@ -1284,6 +1284,43 @@ static char *save_err_msg(
|
||||
return zErrMsg;
|
||||
}
|
||||
|
||||
#ifdef __linux__
|
||||
/*
|
||||
** Attempt to display I/O stats on Linux using /proc/PID/io
|
||||
*/
|
||||
static void displayLinuxIoStats(FILE *out){
|
||||
FILE *in;
|
||||
char z[200];
|
||||
sqlite3_snprintf(sizeof(z), z, "/proc/%d/io", getpid());
|
||||
in = fopen(z, "rb");
|
||||
if( in==0 ) return;
|
||||
while( fgets(z, sizeof(z), in)!=0 ){
|
||||
static const struct {
|
||||
const char *zPattern;
|
||||
const char *zDesc;
|
||||
} aTrans[] = {
|
||||
{ "rchar: ", "Number of bytes received by read():" },
|
||||
{ "wchar: ", "Number of bytes sent to write():" },
|
||||
{ "syscr: ", "Number of read() system calls:" },
|
||||
{ "syscw: ", "Number of write() system calls:" },
|
||||
{ "read_bytes: ", "Number of bytes from storage:" },
|
||||
{ "write_bytes: ", "Number of bytes sent to storage:" },
|
||||
{ "cancelled_write_bytes: ", "Cancelled write bytes:" },
|
||||
};
|
||||
int i;
|
||||
for(i=0; i<ArraySize(aTrans); i++){
|
||||
int n = (int)strlen(aTrans[i].zPattern);
|
||||
if( strncmp(aTrans[i].zPattern, z, n)==0 ){
|
||||
raw_printf(out, "%-36s %s", aTrans[i].zDesc, &z[n]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose(in);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
** Display memory stats.
|
||||
*/
|
||||
@@ -1406,6 +1443,10 @@ static int display_stats(
|
||||
raw_printf(pArg->out, "Virtual Machine Steps: %d\n", iCur);
|
||||
}
|
||||
|
||||
#ifdef __linux__
|
||||
displayLinuxIoStats(pArg->out);
|
||||
#endif
|
||||
|
||||
/* Do not remove this machine readable comment: extra-stats-output-here */
|
||||
|
||||
return 0;
|
||||
@@ -1957,7 +1998,7 @@ static char zHelp[] =
|
||||
" separator for both the output mode and .import\n"
|
||||
".shell CMD ARGS... Run CMD ARGS... in a system shell\n"
|
||||
".show Show the current values for various settings\n"
|
||||
".stats on|off Turn stats on or off\n"
|
||||
".stats ?on|off? Show stats or turn stats on or off\n"
|
||||
".system CMD ARGS... Run CMD ARGS... in a system shell\n"
|
||||
".tables ?TABLE? List names of tables\n"
|
||||
" If TABLE specified, only list tables matching\n"
|
||||
@@ -3835,8 +3876,10 @@ static int do_meta_command(char *zLine, ShellState *p){
|
||||
if( c=='s' && strncmp(azArg[0], "stats", n)==0 ){
|
||||
if( nArg==2 ){
|
||||
p->statsOn = booleanValue(azArg[1]);
|
||||
}else if( nArg==1 ){
|
||||
display_stats(p->db, p, 0);
|
||||
}else{
|
||||
raw_printf(stderr, "Usage: .stats on|off\n");
|
||||
raw_printf(stderr, "Usage: .stats ?on|off?\n");
|
||||
rc = 1;
|
||||
}
|
||||
}else
|
||||
|
||||
Reference in New Issue
Block a user