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