12 #include "../bscript/berror.h" 13 #include "../bscript/bobject.h" 14 #include "../bscript/executor.h" 15 #include "../bscript/impstr.h" 16 #include "../bscript/objmethods.h" 17 #include "../clib/cfgelem.h" 18 #include "../clib/logfacility.h" 19 #include "../clib/streamsaver.h" 20 #include "../clib/strutil.h" 21 #include "../plib/systemstate.h" 44 return sizeof(
void* ) +
sizeof(
u64 ) *
hits.size();
84 PropLists::iterator el;
152 _proplists->insert( std::make_pair( proplist, type ) );
191 u64* cur = &( *_hits )[type][
name][key];
192 if ( *cur < std::numeric_limits<u64>::max() )
219 std::map<std::string, std::map<std::string, std::vector<std::string>>> outData;
224 for (
auto tIter =
_hits->begin(); tIter !=
_hits->end(); ++tIter )
226 Type t = tIter->first;
228 std::string typeName;
232 typeName =
"Account";
253 typeName =
"UNKNOWN";
256 typeName =
"ERROR " + std::to_string( static_cast<unsigned int>( t ) );
260 for (
auto pIter = tIter->second.begin(); pIter != tIter->second.end(); ++pIter )
262 std::ostringstream line;
263 line << pIter->first <<
" ";
269 outData[
"WRITTEN BUT NEVER READ"][typeName].push_back( line.str() );
271 outData[
"READ BUT NEVER WRITTEN"][typeName].push_back( line.str() );
273 outData[
"ALL THE REST"][typeName].push_back( line.str() );
279 for (
auto it1 = outData.rbegin(); it1 != outData.rend(); ++it1 )
282 os << std::string( 15,
'-' ) <<
" " << it1->first <<
" " << std::string( 15,
'-' ) << std::endl;
284 for (
auto it2 = it1->second.begin(); it2 != it1->second.end(); ++it2 )
287 os << it2->first <<
" CProps summary (read/write/erase):" << std::endl;
289 std::sort( it2->second.begin(), it2->second.end() );
290 for (
auto it3 = it2->second.begin(); it3 != it2->second.end(); ++it3 )
318 for (
auto itr1 =
_hits->begin(); itr1 !=
_hits->end(); ++itr1 )
321 for (
auto itr2 = itr1->second.begin(); itr2 != itr1->second.end(); ++itr2 )
323 ret += itr2->first.size() + itr2->second.sizeEstimate();
383 propval = ( *itr ).second;
425 propnames.push_back( prop.first );
433 const std::string& first = prop.first;
434 if ( first[0] !=
'#' )
436 sw() <<
"\tCProp\t" << first <<
" " << prop.second.get() <<
pf_endl;
444 const std::string& first = prop.first;
445 if ( first[0] !=
'#' )
447 elem.
add_prop(
"CProp", ( first +
"\t" + prop.second.get() ) );
456 const std::string& first = prop.first;
457 if ( first[0] !=
'#' )
459 sw() <<
"\t" << first <<
" " << prop.second.get() <<
pf_endl;
469 std::string propname;
470 std::string propvalue;
474 setprop( propname,
"s" + propvalue );
478 std::string propname;
479 std::string propvalue;
483 setprop( propname, propvalue );
489 std::string propname, propvalue;
492 setprop( propname, propvalue );
502 const std::set<std::string>& CPropNames )
504 for (
const auto&
name : CPropNames )
514 for (
const auto&
name : CPropNames )
523 using namespace Bscript;
529 return new BError(
"Not enough parameters" );
530 const String* propname_str;
532 return new BError(
"Invalid parameter type" );
535 return new BError(
"Property not found" );
543 return new BError(
"Not enough parameters" );
544 const String* propname_str;
546 return new BError(
"Invalid parameter type" );
551 POLLOG.Format(
"wtf, setprop w/ an error '{}' PC:{}\n" ) << ex.
scriptname().c_str() << ex.
PC;
553 std::string propname = propname_str->
value();
555 if ( propname[0] !=
'#' )
557 return new BLong( 1 );
563 return new BError(
"Not enough parameters" );
564 const String* propname_str;
566 return new BError(
"Invalid parameter type" );
567 std::string propname = propname_str->
value();
569 if ( propname[0] !=
'#' )
571 return new BLong( 1 );
576 std::vector<std::string> propnames;
578 std::unique_ptr<ObjArray> arr(
new ObjArray );
579 for (
const auto&
name : propnames )
583 return arr.release();
595 if ( objmethod !=
nullptr )
void printProperties(Clib::StreamWriter &sw) const
bool operator==(const PropertyList &) const
bool remove_first_prop(std::string *propname, std::string *value)
const std::string & value() const
void splitnamevalue(const std::string &istr, std::string &propname, std::string &propvalue)
std::unique_ptr< Hits > _hits
bool isa(BObjectType type) const
std::array< u64, 3 > hits
0=read, 1=write, 2=erase
static CPropProfiler & instance()
size_t estimatedSize() const
std::unique_ptr< PropLists > _proplists
static const size_t WRITE
ObjMethod * getKnownObjMethod(const char *token)
void eraseprop(const std::string &propname)
virtual std::string pack() const
bool isIgnored(Type type) const
void readRemainingPropertiesAsStrings(Clib::ConfigElem &elem)
Bscript::BObjectImp * CallPropertyListMethod_id(PropertyList &proplist, const int id, Bscript::Executor &ex, bool &changed)
boost::flyweight< std::string, boost::flyweights::tag< cprop_name_tag >, FLYWEIGHT_HASH_FACTORY > cprop_name_flystring
void add_prop(std::string propname, std::string propval)
void setprop(const std::string &propname, const std::string &propvalue)
void unregisterProplist(const PropertyList *proplist)
std::map< const PropertyList *, const Type > PropLists
void copyprops(const PropertyList &proplist)
size_t sizeEstimate() const
void registerProplist(const PropertyList *proplist, const Type type)
void printPropertiesAsStrings(Clib::StreamWriter &sw) const
void readProperties(Clib::ConfigElem &elem)
static BObjectImp * unpack(const char *pstr)
unknown type, do not use (internally used when profiler is enabled after startup) ...
size_t estimateSize() const
void getpropnames(std::vector< std::string > &propnames) const
std::map< const std::string, HitsCounter > HitsEntries
std::map< const Type, HitsEntries > Hits
u64 & operator[](size_t idx)
bool remove_prop(const char *propname, std::string *value)
Clib::SpinLock _proplistsLock
const std::string & scriptname() const
const String * getStringParam(unsigned param)
void cpropErase(const PropertyList *proplist, const std::string &name)
bool getprop(const std::string &propname, std::string &propvalue) const
bool hasParams(unsigned howmany) const
void operator-=(const std::set< std::string > &)
Bscript::BObjectImp * CallPropertyListMethod(PropertyList &proplist, const char *methodname, Bscript::Executor &ex, bool &changed)
PropertyList & operator-(const std::set< std::string > &)
boost::flyweight< std::string, boost::flyweights::tag< cprop_value_tag >, FLYWEIGHT_HASH_FACTORY > cprop_value_flystring
void cpropAction(const PropertyList *proplist, const std::string &name, const size_t key)
void cpropWrite(const PropertyList *proplist, const std::string &name)
static Type class_to_type(UOBJ_CLASS oclass)
std::lock_guard< SpinLock > SpinLockGuard
void dumpProfile(std::ostream &os) const
void cpropRead(const PropertyList *proplist, const std::string &name)
Type getProplistType(const PropertyList *proplist) const
BObjectImp * getParamImp(unsigned param)
static const size_t ERASE