mirror of
https://github.com/zeek/zeek.git
synced 2025-10-11 11:08:20 +00:00

Doesn't generate any docs, but it's hooked in to all places needed to gather the necessary stuff w/ significantly less coupling than before. The gathering now always occurs unconditionally to make documentation available at runtime and a command line switch (-X) only toggles whether to output docs to disk (reST format). Should also improve the treatment of type name aliasing which wasn't a big problem in practice before, but I think it's more correct now: there's now a distinct BroType for each alias, but extensible types (record/enum) will automatically update the types for aliases on redef. Other misc refactoring of note: - Removed a redundant/unused way of declaring event types. - Changed type serialization format/process to preserve type name information and remove compatibility code (since broccoli will have be updated anyway).
83 lines
2 KiB
C++
83 lines
2 KiB
C++
#ifndef BROFILER_H_
|
|
#define BROFILER_H_
|
|
|
|
#include <map>
|
|
#include <utility>
|
|
#include <list>
|
|
#include <Stmt.h>
|
|
|
|
|
|
/**
|
|
* A simple class for managing stats of Bro script coverage across Bro runs.
|
|
*/
|
|
class Brofiler {
|
|
public:
|
|
Brofiler();
|
|
virtual ~Brofiler();
|
|
|
|
/**
|
|
* Imports Bro script Stmt usage information from file pointed to by
|
|
* environment variable BRO_PROFILER_FILE.
|
|
*
|
|
* @return: true if usage info was read, otherwise false.
|
|
*/
|
|
bool ReadStats();
|
|
|
|
/**
|
|
* Combines usage stats from current run with any read from ReadStats(),
|
|
* then writes information to file pointed to by environment variable
|
|
* BRO_PROFILER_FILE. If the value of that env. variable ends with
|
|
* ".XXXXXX" (exactly 6 X's), then it is first passed through mkstemp
|
|
* to get a unique file.
|
|
*
|
|
* @return: true when usage info is written, otherwise false.
|
|
*/
|
|
bool WriteStats();
|
|
|
|
void SetDelim(char d) { delim = d; }
|
|
|
|
void IncIgnoreDepth() { ignoring++; }
|
|
void DecIgnoreDepth() { ignoring--; }
|
|
|
|
void AddStmt(const Stmt* s) { if ( ignoring == 0 ) stmts.push_back(s); }
|
|
|
|
private:
|
|
/**
|
|
* The current, global Brofiler instance creates this list at parse-time.
|
|
*/
|
|
list<const Stmt*> stmts;
|
|
|
|
/**
|
|
* Indicates whether new statments will not be considered as part of
|
|
* coverage statistics because it was marked with the @no-test tag.
|
|
*/
|
|
unsigned int ignoring;
|
|
|
|
/**
|
|
* This maps Stmt location-desc pairs to the total number of times that
|
|
* Stmt has been executed. The map can be initialized from a file at
|
|
* startup time and modified at shutdown time before writing back
|
|
* to a file.
|
|
*/
|
|
map<pair<string, string>, uint64> usage_map;
|
|
|
|
/**
|
|
* The character to use to delimit Brofiler output files. Default is '\t'.
|
|
*/
|
|
char delim;
|
|
|
|
/**
|
|
* A canonicalization routine for Stmt descriptions containing characters
|
|
* that don't agree with the output format of Brofiler.
|
|
*/
|
|
struct canonicalize_desc {
|
|
void operator() (char& c)
|
|
{
|
|
if ( c == '\n' ) c = ' ';
|
|
}
|
|
};
|
|
};
|
|
|
|
extern Brofiler brofiler;
|
|
|
|
#endif /* BROFILER_H_ */
|