Added command line option for enabling interpreter stats collection
'-d' or '-d0' to collect and print basic stats, '-d1' etc. for alternative output formats.
This commit is contained in:
parent
97030639f1
commit
31b08382db
|
@ -512,6 +512,9 @@ struct Picoc_Struct {
|
|||
struct Table StringTable;
|
||||
struct TableEntry *StringHashTable[STRING_TABLE_SIZE];
|
||||
char *StrEmpty;
|
||||
|
||||
/* stats */
|
||||
int CollectStats;
|
||||
};
|
||||
|
||||
/* table.c */
|
||||
|
|
14
picoc.c
14
picoc.c
|
@ -23,6 +23,8 @@ int main(int argc, char **argv)
|
|||
{
|
||||
int ParamCount = 1;
|
||||
int DontRunMain = false;
|
||||
int CollectStats = false;
|
||||
int StatsType = 0;
|
||||
int StackSize = getenv("STACKSIZE") ? atoi(getenv("STACKSIZE")) : PICOC_STACK_SIZE;
|
||||
Picoc pc;
|
||||
|
||||
|
@ -31,6 +33,7 @@ int main(int argc, char **argv)
|
|||
"Format:\n\n"
|
||||
"> picoc <file1.c>... [- <arg1>...] : run a program, calls main() as the entry point\n"
|
||||
"> picoc -s <file1.c>... [- <arg1>...] : run a script, runs the program without calling main()\n"
|
||||
"> picoc -d[type] <file1.c>... [- <arg1>...] : run a program, outputting debugging stats\n"
|
||||
"> picoc -i : interactive mode, Ctrl+d to exit\n"
|
||||
"> picoc -c : copyright info\n"
|
||||
"> picoc -h : this help message\n");
|
||||
|
@ -48,6 +51,13 @@ int main(int argc, char **argv)
|
|||
DontRunMain = true;
|
||||
PicocIncludeAllSystemHeaders(&pc);
|
||||
ParamCount++;
|
||||
} else if (strncmp(argv[ParamCount], "-d", 2) == 0) {
|
||||
if (strlen(argv[ParamCount]) > 2) {
|
||||
StatsType = atoi(&argv[ParamCount][2]);
|
||||
}
|
||||
CollectStats = true;
|
||||
pc.CollectStats = true;
|
||||
ParamCount++;
|
||||
}
|
||||
|
||||
if (argc > ParamCount && strcmp(argv[ParamCount], "-i") == 0) {
|
||||
|
@ -68,7 +78,9 @@ int main(int argc, char **argv)
|
|||
|
||||
PicocCleanup(&pc);
|
||||
|
||||
stats_print_tokens(0);
|
||||
if (CollectStats) {
|
||||
stats_print_tokens(StatsType == 1);
|
||||
}
|
||||
|
||||
return pc.PicocExitValue;
|
||||
}
|
||||
|
|
10
stats.c
10
stats.c
|
@ -120,14 +120,20 @@ struct LexTokenStat LexTokenStats[NO_TOKENS] = {
|
|||
|
||||
|
||||
void stats_log_statement(enum LexToken token, struct ParseState *parser) {
|
||||
fprintf(stderr, "Parsing Statement %s (%d) in %s (%d) at %s:%d:%d\n", LexTokenStats[token].name, token, RunModeNames[parser->Mode], parser->Mode, parser->FileName, parser->Line, parser->CharacterPos);
|
||||
if (parser->pc->CollectStats) {
|
||||
fprintf(stderr, "Parsing Statement %s (%d) in %s (%d) at %s:%d:%d\n", LexTokenStats[token].name, token,
|
||||
RunModeNames[parser->Mode], parser->Mode, parser->FileName, parser->Line, parser->CharacterPos);
|
||||
LexTokenStats[token].count[parser->Mode]++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void stats_log_expression(enum LexToken token, struct ParseState *parser) {
|
||||
fprintf(stderr, "Parsing Expression %s (%d) in %s (%d) at %s:%d:%d\n", LexTokenStats[token].name, token, RunModeNames[parser->Mode], parser->Mode, parser->FileName, parser->Line, parser->CharacterPos);
|
||||
if (parser->pc->CollectStats) {
|
||||
fprintf(stderr, "Parsing Expression %s (%d) in %s (%d) at %s:%d:%d\n", LexTokenStats[token].name, token,
|
||||
RunModeNames[parser->Mode], parser->Mode, parser->FileName, parser->Line, parser->CharacterPos);
|
||||
LexTokenStats[token].count[parser->Mode]++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue