added timing code
This commit is contained in:
parent
0cac03ba7d
commit
0279827768
3 changed files with 54 additions and 11 deletions
15
debug.h
15
debug.h
|
|
@ -59,6 +59,9 @@ namespace ledger {
|
|||
|
||||
#if RELEASE_LEVEL >= ALPHA
|
||||
|
||||
#include <pcre.h>
|
||||
#include <cstring>
|
||||
|
||||
#define DEBUG_ENABLED
|
||||
|
||||
extern std::ostream * warning_stream;
|
||||
|
|
@ -66,8 +69,16 @@ extern std::ostream * debug_stream;
|
|||
extern bool free_debug_stream;
|
||||
|
||||
inline bool _debug_active(const char * const cls) {
|
||||
char * debug = std::getenv("DEBUG_CLASS");
|
||||
return debug && std::strcmp(debug, cls) == 0;
|
||||
if (char * debug = std::getenv("DEBUG_CLASS")) {
|
||||
static const char * error;
|
||||
static int erroffset;
|
||||
static int ovec[30];
|
||||
static pcre * class_regexp = pcre_compile(debug, PCRE_CASELESS,
|
||||
&error, &erroffset, NULL);
|
||||
return pcre_exec(class_regexp, NULL, cls, std::strlen(cls),
|
||||
0, 0, ovec, 30) >= 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#define DEBUG_CLASS(cls) static const char * const _debug_cls = (cls)
|
||||
|
|
|
|||
35
main.cc
35
main.cc
|
|
@ -4,6 +4,7 @@
|
|||
#include "format.h"
|
||||
#include "walk.h"
|
||||
#include "option.h"
|
||||
#include "timing.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <cstring>
|
||||
|
|
@ -101,6 +102,7 @@ namespace {
|
|||
bool show_subtotals = true;
|
||||
bool show_expanded = false;
|
||||
bool show_related = false;
|
||||
bool show_all_related = false;
|
||||
bool show_inverted = false;
|
||||
bool show_empty = false;
|
||||
bool days_of_the_week = false;
|
||||
|
|
@ -436,6 +438,8 @@ int main(int argc, char * argv[], char * envp[])
|
|||
|
||||
// A ledger data file must be specified
|
||||
|
||||
TIMER_START(read_cache, "reading cache file");
|
||||
|
||||
// jww (2004-08-13): use LEDGER_FILE
|
||||
use_cache = std::getenv("LEDGER") != NULL;
|
||||
|
||||
|
|
@ -466,9 +470,14 @@ int main(int argc, char * argv[], char * envp[])
|
|||
}
|
||||
}
|
||||
|
||||
TIMER_STOP(read_cache);
|
||||
|
||||
// Parse the command-line options
|
||||
|
||||
TIMER_START(process_args, "processing command-line arguments");
|
||||
|
||||
std::list<std::string> args;
|
||||
|
||||
process_arguments(argc, argv, false, args);
|
||||
|
||||
if (args.empty()) {
|
||||
|
|
@ -477,8 +486,12 @@ int main(int argc, char * argv[], char * envp[])
|
|||
}
|
||||
std::list<std::string>::iterator arg = args.begin();
|
||||
|
||||
TIMER_STOP(process_args);
|
||||
|
||||
// Process options from the environment
|
||||
|
||||
TIMER_START(process_env, "processing environment");
|
||||
|
||||
process_environment(envp, "LEDGER_");
|
||||
|
||||
if (char * p = std::getenv("PRICE_HIST"))
|
||||
|
|
@ -486,8 +499,12 @@ int main(int argc, char * argv[], char * envp[])
|
|||
if (char * p = std::getenv("PRICE_EXP"))
|
||||
process_option("price-exp", p);
|
||||
|
||||
TIMER_STOP(process_env);
|
||||
|
||||
// Read the ledger file, unless we already read it from the cache
|
||||
|
||||
TIMER_START(parse_files, "parsing ledger files");
|
||||
|
||||
if (! use_cache || cache_dirty) {
|
||||
int entry_count = 0;
|
||||
|
||||
|
|
@ -529,10 +546,14 @@ int main(int argc, char * argv[], char * envp[])
|
|||
}
|
||||
}
|
||||
|
||||
TIMER_STOP(parse_files);
|
||||
|
||||
// Read the command word, and then check and simplify it
|
||||
|
||||
std::string command = *arg++;
|
||||
|
||||
TIMER_START(handle_options, "configuring based on options");
|
||||
|
||||
if (command == "balance" || command == "bal" || command == "b")
|
||||
command = "b";
|
||||
else if (command == "register" || command == "reg" || command == "r")
|
||||
|
|
@ -604,7 +625,7 @@ int main(int argc, char * argv[], char * envp[])
|
|||
try {
|
||||
std::istringstream stream(sort_string);
|
||||
sort_order.reset(parse_value_expr(stream));
|
||||
if (! stream.eof()) {
|
||||
if (stream.peek() != -1) {
|
||||
std::ostringstream err;
|
||||
err << "Unexpected character '" << char(stream.peek()) << "'";
|
||||
throw value_expr_error(err.str());
|
||||
|
|
@ -642,8 +663,6 @@ int main(int argc, char * argv[], char * envp[])
|
|||
|
||||
// Configure some option depending on the report type
|
||||
|
||||
bool show_all_related = false;
|
||||
|
||||
if (command == "p" || command == "e") {
|
||||
show_related = show_all_related = true;
|
||||
show_expanded = true;
|
||||
|
|
@ -685,8 +704,12 @@ int main(int argc, char * argv[], char * envp[])
|
|||
format_t format(first_line_format);
|
||||
format_t nformat(next_lines_format);
|
||||
|
||||
TIMER_STOP(handle_options);
|
||||
|
||||
// Walk the entries based on the report type and the options
|
||||
|
||||
TIMER_START(report_gen, "generation of final report");
|
||||
|
||||
if (command == "b") {
|
||||
std::auto_ptr<item_handler<transaction_t> > formatter;
|
||||
formatter.reset(new add_to_account_value);
|
||||
|
|
@ -807,8 +830,12 @@ int main(int argc, char * argv[], char * envp[])
|
|||
#endif
|
||||
}
|
||||
|
||||
TIMER_STOP(report_gen);
|
||||
|
||||
// Save the cache, if need be
|
||||
|
||||
TIMER_START(write_cache, "writing cache file");
|
||||
|
||||
if (use_cache && cache_dirty) {
|
||||
std::string cache_file = ledger_cache_file();
|
||||
if (! cache_file.empty()) {
|
||||
|
|
@ -818,6 +845,8 @@ int main(int argc, char * argv[], char * envp[])
|
|||
}
|
||||
}
|
||||
|
||||
TIMER_STOP(write_cache);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
15
textual.cc
15
textual.cc
|
|
@ -417,11 +417,13 @@ unsigned int parse_textual_journal(std::istream& in, journal_t * journal,
|
|||
date = std::time_t(((unsigned long) date) +
|
||||
hour * 3600 + min * 60 + sec);
|
||||
|
||||
amount_t price;
|
||||
|
||||
parse_commodity(in, symbol);
|
||||
in >> line; // the price
|
||||
price.parse(line);
|
||||
|
||||
in.getline(line, MAX_LINE);
|
||||
linenum++;
|
||||
|
||||
amount_t price;
|
||||
price.parse(skip_ws(line));
|
||||
|
||||
commodity_t * commodity = commodity_t::find_commodity(symbol, true);
|
||||
commodity->add_price(date, price);
|
||||
|
|
@ -434,7 +436,7 @@ unsigned int parse_textual_journal(std::istream& in, journal_t * journal,
|
|||
in >> c;
|
||||
parse_commodity(in, symbol);
|
||||
|
||||
commodity_t * commodity = commodity_t::find_commodity(line, true);
|
||||
commodity_t * commodity = commodity_t::find_commodity(symbol, true);
|
||||
commodity->flags |= (COMMODITY_STYLE_CONSULTED |
|
||||
COMMODITY_STYLE_NOMARKET);
|
||||
break;
|
||||
|
|
@ -447,9 +449,10 @@ unsigned int parse_textual_journal(std::istream& in, journal_t * journal,
|
|||
amount_t price;
|
||||
|
||||
parse_commodity(in, symbol);
|
||||
|
||||
in.getline(line, MAX_LINE);
|
||||
linenum++;
|
||||
price.parse(line);
|
||||
price.parse(skip_ws(line));
|
||||
|
||||
commodity_t * commodity = commodity_t::find_commodity(symbol, true);
|
||||
commodity->set_conversion(price);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue