Quick optimization to Broxygen doc gathering.

So script parsing is only ~2x slower rather than 20x.  Turns out cloning
Vals is particularly slow.  Changed to just get a string description of
the Val for initial value and redef tracking.
This commit is contained in:
Jon Siwek 2013-10-22 16:29:58 -05:00
parent 15b1904ca8
commit 52733b0501
6 changed files with 59 additions and 13 deletions

View file

@ -15,19 +15,22 @@ PackageDocument::PackageDocument(const string& arg_name)
IdentifierDocument::IdentifierDocument(ID* arg_id) IdentifierDocument::IdentifierDocument(ID* arg_id)
: Document(), : Document(),
comments(), id(arg_id), initial_val(), redefs(), fields(), comments(), id(arg_id), initial_val_desc(), redefs(), fields(),
last_field_seen() last_field_seen()
{ {
Ref(id); Ref(id);
if ( id->ID_Val() ) if ( id->ID_Val() )
initial_val = id->ID_Val()->Clone(); {
ODesc d;
id->ID_Val()->Describe(&d);
initial_val_desc = d.Description();
}
} }
IdentifierDocument::~IdentifierDocument() IdentifierDocument::~IdentifierDocument()
{ {
Unref(id); Unref(id);
//Unref(initial_val); // TODO: problematic w/ PatternVals
for ( RedefList::const_iterator it = redefs.begin(); it != redefs.end(); for ( RedefList::const_iterator it = redefs.begin(); it != redefs.end();
++it ) ++it )
@ -42,7 +45,14 @@ void IdentifierDocument::AddRedef(const string& script,
{ {
Redefinition* redef = new Redefinition(); Redefinition* redef = new Redefinition();
redef->from_script = script; redef->from_script = script;
redef->new_val = id->ID_Val() ? id->ID_Val()->Clone() : 0;
if ( id->ID_Val() )
{
ODesc d;
id->ID_Val()->Describe(&d);
redef->new_val_desc = d.Description();
}
redef->comments = comments; redef->comments = comments;
redefs.push_back(redef); redefs.push_back(redef);
} }

View file

@ -81,11 +81,8 @@ public:
private: private:
struct Redefinition { struct Redefinition {
~Redefinition()
{ Unref(new_val); }
std::string from_script; std::string from_script;
Val* new_val; string new_val_desc;
std::vector<std::string> comments; std::vector<std::string> comments;
}; };
@ -106,7 +103,7 @@ private:
std::vector<std::string> comments; std::vector<std::string> comments;
ID* id; ID* id;
Val* initial_val; string initial_val_desc;
RedefList redefs; RedefList redefs;
std::vector<RecordField*> fields; std::vector<RecordField*> fields;
RecordField* last_field_seen; RecordField* last_field_seen;

View file

@ -84,9 +84,11 @@ static string PrettifyParams(const string& s)
} }
Manager::Manager(const string& config) Manager::Manager(const string& config)
: comment_buffer(), packages(), scripts(), identifiers(), all_docs(), : disabled(), comment_buffer(), packages(), scripts(), identifiers(),
last_doc_seen(), incomplete_type() all_docs(), last_doc_seen(), incomplete_type()
{ {
if ( getenv("BRO_DISABLE_BROXYGEN") )
disabled = true;
// TODO config file stuff // TODO config file stuff
} }
@ -99,16 +101,22 @@ Manager::~Manager()
void Manager::InitPreScript() void Manager::InitPreScript()
{ {
if ( disabled )
return;
// TODO: create file/proto analyzer doc // TODO: create file/proto analyzer doc
} }
void Manager::InitPostScript() void Manager::InitPostScript()
{ {
if ( disabled )
return;
// TODO: dependency resolution stuff? // TODO: dependency resolution stuff?
} }
void Manager::GenerateDocs() const void Manager::GenerateDocs() const
{ {
if ( disabled )
return;
// TODO // TODO
// may be a no-op if no config file // may be a no-op if no config file
@ -116,6 +124,9 @@ void Manager::GenerateDocs() const
void Manager::File(const string& path) void Manager::File(const string& path)
{ {
if ( disabled )
return;
string name = without_bropath_component(path); string name = without_bropath_component(path);
if ( scripts.find(name) != scripts.end() ) if ( scripts.find(name) != scripts.end() )
@ -144,6 +155,9 @@ void Manager::File(const string& path)
void Manager::ScriptDependency(const string& path, const string& dep) void Manager::ScriptDependency(const string& path, const string& dep)
{ {
if ( disabled )
return;
if ( dep.empty() ) if ( dep.empty() )
{ {
DbgAndWarn(fmt("Empty script doc dependency: %s", path.c_str())); DbgAndWarn(fmt("Empty script doc dependency: %s", path.c_str()));
@ -173,6 +187,9 @@ void Manager::ScriptDependency(const string& path, const string& dep)
void Manager::ModuleUsage(const string& path, const string& module) void Manager::ModuleUsage(const string& path, const string& module)
{ {
if ( disabled )
return;
string name = without_bropath_component(path); string name = without_bropath_component(path);
ScriptMap::const_iterator it = scripts.find(name); ScriptMap::const_iterator it = scripts.find(name);
@ -189,6 +206,9 @@ void Manager::ModuleUsage(const string& path, const string& module)
void Manager::StartType(ID* id) void Manager::StartType(ID* id)
{ {
if ( disabled )
return;
if ( id->GetLocationInfo() == &no_location ) if ( id->GetLocationInfo() == &no_location )
{ {
DbgAndWarn(fmt("Can't document %s, no location available", id->Name())); DbgAndWarn(fmt("Can't document %s, no location available", id->Name()));
@ -218,6 +238,9 @@ void Manager::StartType(ID* id)
void Manager::Identifier(ID* id) void Manager::Identifier(ID* id)
{ {
if ( disabled )
return;
if ( incomplete_type && incomplete_type->Name() == id->Name() ) if ( incomplete_type && incomplete_type->Name() == id->Name() )
{ {
DBG_LOG(DBG_BROXYGEN, "Finished document for type %s", id->Name()); DBG_LOG(DBG_BROXYGEN, "Finished document for type %s", id->Name());
@ -273,6 +296,9 @@ void Manager::Identifier(ID* id)
void Manager::RecordField(const ID* id, const TypeDecl* field, void Manager::RecordField(const ID* id, const TypeDecl* field,
const string& path) const string& path)
{ {
if ( disabled )
return;
IdentifierDocument* idd = 0; IdentifierDocument* idd = 0;
if ( incomplete_type ) if ( incomplete_type )
@ -311,6 +337,9 @@ void Manager::RecordField(const ID* id, const TypeDecl* field,
void Manager::Redef(const ID* id, const string& path) void Manager::Redef(const ID* id, const string& path)
{ {
if ( disabled )
return;
if ( path == "<params>" ) if ( path == "<params>" )
// This is a redef defined on the command line. // This is a redef defined on the command line.
return; return;
@ -342,6 +371,9 @@ void Manager::Redef(const ID* id, const string& path)
void Manager::SummaryComment(const string& script, const string& comment) void Manager::SummaryComment(const string& script, const string& comment)
{ {
if ( disabled )
return;
string name = without_bropath_component(script); string name = without_bropath_component(script);
ScriptMap::const_iterator it = scripts.find(name); ScriptMap::const_iterator it = scripts.find(name);
@ -357,11 +389,17 @@ void Manager::SummaryComment(const string& script, const string& comment)
void Manager::PreComment(const string& comment) void Manager::PreComment(const string& comment)
{ {
if ( disabled )
return;
comment_buffer.push_back(PrettifyParams(RemoveLeadingSpace(comment))); comment_buffer.push_back(PrettifyParams(RemoveLeadingSpace(comment)));
} }
void Manager::PostComment(const string& comment) void Manager::PostComment(const string& comment)
{ {
if ( disabled )
return;
IdentifierDocument* doc = dynamic_cast<IdentifierDocument*>(last_doc_seen); IdentifierDocument* doc = dynamic_cast<IdentifierDocument*>(last_doc_seen);
if ( ! doc ) if ( ! doc )

View file

@ -13,7 +13,6 @@
namespace broxygen { namespace broxygen {
// TODO: documentation... // TODO: documentation...
// TODO: optimize parse time... maybe an env. option to disable doc collection?
class Manager { class Manager {
@ -60,6 +59,7 @@ private:
void RegisterDoc(Document* d); void RegisterDoc(Document* d);
bool disabled;
CommentBuffer comment_buffer; CommentBuffer comment_buffer;
PackageMap packages; PackageMap packages;
ScriptMap scripts; ScriptMap scripts;

View file

@ -227,6 +227,7 @@ void usage()
fprintf(stderr, " $BRO_SEED_FILE | file to load seeds from (not set)\n"); fprintf(stderr, " $BRO_SEED_FILE | file to load seeds from (not set)\n");
fprintf(stderr, " $BRO_LOG_SUFFIX | ASCII log file extension (.%s)\n", logging::writer::Ascii::LogExt().c_str()); fprintf(stderr, " $BRO_LOG_SUFFIX | ASCII log file extension (.%s)\n", logging::writer::Ascii::LogExt().c_str());
fprintf(stderr, " $BRO_PROFILER_FILE | Output file for script execution statistics (not set)\n"); fprintf(stderr, " $BRO_PROFILER_FILE | Output file for script execution statistics (not set)\n");
fprintf(stderr, " $BRO_DISABLE_BROXYGEN | Disable Broxygen documentation support (%s)\n", getenv("BRO_DISABLE_BROXYGEN") ? "set" : "not set");
fprintf(stderr, "\n"); fprintf(stderr, "\n");
fprintf(stderr, " Supported log formats: "); fprintf(stderr, " Supported log formats: ");

View file

@ -963,7 +963,7 @@ type_decl:
set_location(@1, @4); set_location(@1, @4);
$$ = new TypeDecl($3, $1, $4, (in_record > 0)); $$ = new TypeDecl($3, $1, $4, (in_record > 0));
if ( in_record > 0 ) if ( in_record > 0 && cur_decl_type_id )
broxygen_mgr->RecordField(cur_decl_type_id, $$, ::filename); broxygen_mgr->RecordField(cur_decl_type_id, $$, ::filename);
} }
; ;