add partial API compatability with profiler v1
the general idea is the same however due to how profiles are handled after calling write or print profile the intervals inside are no longer valid. (they are deleted and will be removed from the internal hashmap) print profile is also now consistent with the new API, old calls will need to be updated.v1
parent
3266a7b102
commit
ab24a8733b
|
@ -103,9 +103,10 @@ namespace blt
|
||||||
|
|
||||||
void endInterval(const std::string& profile_name, const std::string& interval_name);
|
void endInterval(const std::string& profile_name, const std::string& interval_name);
|
||||||
|
|
||||||
void printProfile(const std::string& profile_name);
|
void printProfile(const std::string& profile_name, std::uint32_t flags = PRINT_HISTORY | PRINT_CYCLES | PRINT_THREAD | PRINT_WALL,
|
||||||
|
sort_by sort = sort_by::CYCLES, blt::logging::log_level log_level = blt::logging::log_level::NONE);
|
||||||
|
|
||||||
void writeProfile(const std::string& profile_name);
|
void writeProfile(std::ifstream& stream, const std::string& profile_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
class auto_interval
|
class auto_interval
|
||||||
|
|
|
@ -212,28 +212,45 @@ namespace blt
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* profiler V1 backwards compat
|
* profiler V1 partial backwards compat
|
||||||
|
* ----------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
HASHMAP<std::string, HASHMAP<std::string, interval_t*>> profiles;
|
||||||
|
|
||||||
void _internal::startInterval(const std::string& profile_name, const std::string& interval_name)
|
void _internal::startInterval(const std::string& profile_name, const std::string& interval_name)
|
||||||
{
|
{
|
||||||
|
auto& profile = profiles[profile_name];
|
||||||
|
if (!profile.contains(interval_name))
|
||||||
|
{
|
||||||
|
auto interval = new interval_t();
|
||||||
|
interval->interval_name = interval_name;
|
||||||
|
profile[interval_name] = interval;
|
||||||
|
}
|
||||||
|
blt::startInterval(profile[interval_name]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _internal::endInterval(const std::string& profile_name, const std::string& interval_name)
|
void _internal::endInterval(const std::string& profile_name, const std::string& interval_name)
|
||||||
{
|
{
|
||||||
|
blt::endInterval(profiles[profile_name].at(interval_name));
|
||||||
}
|
}
|
||||||
|
|
||||||
void _internal::printProfile(const std::string& profile_name)
|
void _internal::writeProfile(std::ifstream& stream, const std::string& profile_name)
|
||||||
{
|
{
|
||||||
|
auto& pref = profiles[profile_name];
|
||||||
|
profile_t profile{profile_name};
|
||||||
|
for (const auto& i : pref)
|
||||||
|
profile.intervals.push_back(i.second);
|
||||||
|
profiles.erase(profile_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _internal::writeProfile(const std::string& profile_name)
|
void _internal::printProfile(const std::string& profile_name, std::uint32_t flags, sort_by sort, blt::logging::log_level log_level)
|
||||||
{
|
{
|
||||||
|
auto& pref = profiles[profile_name];
|
||||||
|
profile_t profile{profile_name};
|
||||||
|
for (const auto& i : pref)
|
||||||
|
profile.intervals.push_back(i.second);
|
||||||
|
blt::printProfile(profile, flags, sort, log_level);
|
||||||
|
profiles.erase(profile_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue