BUG: name collision on profiling (issue #440)

This commit is contained in:
Mark Olesen
2017-04-19 11:04:32 +02:00
parent 6a583851bc
commit e55339d1e1
4 changed files with 52 additions and 11 deletions

View File

@ -37,16 +37,21 @@ Foam::profiling* Foam::profiling::pool_(0);
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
Foam::profilingInformation* Foam::profiling::find(const string& name) Foam::profilingInformation* Foam::profiling::find
(
const string& descr,
const label parentId
)
{ {
StorageContainer::iterator iter = hash_.find(name); StorageContainer::iterator iter = hash_.find(Key(descr, parentId));
return (iter != hash_.end() ? iter() : 0); return (iter.found() ? iter() : 0);
} }
Foam::profilingInformation* Foam::profiling::store(profilingInformation *info) Foam::profilingInformation* Foam::profiling::store(profilingInformation *info)
{ {
hash_.insert(info->description(), info); // Profile information lookup is qualified by parent id
hash_.insert(Key(info->description(), info->parent().id()), info);
return info; return info;
} }
@ -174,7 +179,7 @@ Foam::profilingInformation* Foam::profiling::New
{ {
profilingInformation *parent = pool_->stack_.top(); profilingInformation *parent = pool_->stack_.top();
info = pool_->find(descr); info = pool_->find(descr, parent->id());
if (!info) if (!info)
{ {
info = pool_->store(new profilingInformation(descr, parent)); info = pool_->store(new profilingInformation(descr, parent));

View File

@ -87,10 +87,35 @@ public:
private: private:
// Private typedefs // Private classes, typedefs
typedef profilingSysInfo sysInfo; typedef profilingSysInfo sysInfo;
typedef HashPtrTable<Information, string> StorageContainer;
//- Profile information lookup is qualified by parent id
typedef Tuple2<string, label> Key;
//- Hashing for information lookup
class HashKey
:
public Hash<Key>
{
public:
HashKey()
{}
//- Hash qualified by the parent id to avoid collisions
unsigned operator()(const Key& key) const
{
return
(
Hash<string>()(key.first())
+ Hash<label>()(key.second())
);
}
};
typedef HashPtrTable<Information, Key, HashKey> StorageContainer;
typedef LIFOStack<Information*> StackContainer; typedef LIFOStack<Information*> StackContainer;
@ -164,8 +189,9 @@ protected:
// Protected Member Functions // Protected Member Functions
//- Find named profiling information element or null on failure //- Find named profiling information element with specified parent.
profilingInformation* find(const string& name); // Return nullptr on failure.
profilingInformation* find(const string& descr, const label parentId);
//- Add to hashed storage, //- Add to hashed storage,
// returns pointer to newly stored element for chaining // returns pointer to newly stored element for chaining

View File

@ -59,7 +59,12 @@ Foam::SolverPerformance<Type> Foam::fvMatrix<Type>::solve
const dictionary& solverControls const dictionary& solverControls
) )
{ {
addProfiling(solve, "fvMatrix::solve." + psi_.name()); word regionName;
if (psi_.mesh().name() != polyMesh::defaultRegion)
{
regionName = psi_.mesh().name() + "::";
}
addProfiling(solve, "fvMatrix::solve." + regionName + psi_.name());
if (debug) if (debug)
{ {

View File

@ -60,7 +60,12 @@ Foam::fvMatrix<Foam::scalar>::solver
const dictionary& solverControls const dictionary& solverControls
) )
{ {
addProfiling(solve, "fvMatrix::solve." + psi_.name()); word regionName;
if (psi_.mesh().name() != polyMesh::defaultRegion)
{
regionName = psi_.mesh().name() + "::";
}
addProfiling(solve, "fvMatrix::solve." + regionName + psi_.name());
if (debug) if (debug)
{ {