Skip to content

Commit

Permalink
Swapped to long int (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
bencopl committed Sep 13, 2022
1 parent a542369 commit ad30052
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 20 deletions.
26 changes: 16 additions & 10 deletions src/c++/hashtable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ void HashTable::add_child_time(size_t hash, time_duration_t time_delta)
entry.child_walltime_ += time_delta;
}

long double HashTable::seconds(time_duration_t input_dur) const
{
long double n = 1.0e-9;
return static_cast<long double>(input_dur.count())*n;
}

This comment has been minimized.

Copy link
@bencopl

bencopl Sep 13, 2022

Author

I added a new function inside HashTable that simply converts a chrono duration of type <long int, std::nano> into a time in seconds. It has proved useful in a couple of the getters and also when writing the walltimes out but it might not be required.

/**
* @brief Writes all entries in the hashtable, sorted according to self times.
*
Expand Down Expand Up @@ -125,10 +131,10 @@ void HashTable::write()
// Data entries
for (auto& [hash, entry] : hashvec) {
std::cout
<< std::setw(40) << std::left << entry.region_name_ << " "
<< std::setw(15) << std::right << entry.self_walltime_.count() << " "
<< std::setw(15) << std::right << entry.total_walltime_.count() << " "
<< std::setw(10) << std::right << entry.call_count_ << "\n";
<< std::setw(40) << std::left << entry.region_name_ << " "
<< std::setw(15) << std::right << seconds(entry.self_walltime_) << " "
<< std::setw(15) << std::right << seconds(entry.total_walltime_) << " "
<< std::setw(10) << std::right << entry.call_count_ << "\n";
}
}

Expand Down Expand Up @@ -164,30 +170,30 @@ std::vector<size_t> HashTable::list_keys()
*
*/

double HashTable::get_total_walltime(size_t const hash) const
long double HashTable::get_total_walltime(size_t const hash) const
{
return table_.at(hash).total_walltime_.count();
return seconds(table_.at(hash).total_walltime_);
}

/**
* @brief Get the profiler self time corresponding to the input hash.
*
*/

double HashTable::get_self_walltime(size_t const hash)
long double HashTable::get_self_walltime(size_t const hash)
{
this->compute_self_times();
return table_.at(hash).self_walltime_.count();
return seconds(table_.at(hash).self_walltime_);
}

/**
* @brief Get the child time corresponding to the input hash.
*
*/

double HashTable::get_child_walltime(size_t const hash) const
long double HashTable::get_child_walltime(size_t const hash) const
{
return table_.at(hash).child_walltime_.count();
return seconds(table_.at(hash).child_walltime_);
}

/**
Expand Down
11 changes: 7 additions & 4 deletions src/c++/hashtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include <chrono>

// Type definitions for chrono steady clock time points and durations
using time_duration_t = std::chrono::duration<double>;
using time_duration_t = std::chrono::duration<long int, std::nano>;
using time_point_t = std::chrono::time_point<std::chrono::steady_clock, time_duration_t>;


Expand Down Expand Up @@ -76,6 +76,9 @@ class HashTable{
std::hash<std::string_view> hash_function_;
std::vector<std::pair<size_t, HashEntry>> hashvec;

// Prototype.. TODO Think about if this is needed, and where to place it
long double seconds(time_duration_t input_dur) const;

public:

// Constructors
Expand All @@ -93,9 +96,9 @@ class HashTable{
void compute_self_times();

// Getters
double get_total_walltime(size_t const hash) const;
double get_self_walltime(size_t const hash);
double get_child_walltime(size_t const hash) const;
long double get_total_walltime(size_t const hash) const;
long double get_self_walltime(size_t const hash);
long double get_child_walltime(size_t const hash) const;
std::string const& get_region_name(size_t const hash) const;
unsigned long long int const& get_region_call_count(size_t const hash) const;

Expand Down
6 changes: 3 additions & 3 deletions src/c++/profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ void Profiler::write()
*
*/

double Profiler::get_thread0_walltime(size_t const hash) const
long double Profiler::get_thread0_walltime(size_t const hash) const
{
auto tid = static_cast<hashtable_iterator_t_>(0);
return thread_hashtables_[tid].get_total_walltime(hash);
Expand All @@ -148,7 +148,7 @@ double Profiler::get_thread0_walltime(size_t const hash) const
*
*/

double Profiler::get_self_walltime(size_t const hash, int const input_tid)
long double Profiler::get_self_walltime(size_t const hash, int const input_tid)
{
auto tid = static_cast<hashtable_iterator_t_>(input_tid);
return thread_hashtables_[tid].get_self_walltime(hash);
Expand All @@ -159,7 +159,7 @@ double Profiler::get_self_walltime(size_t const hash, int const input_tid)
*
*/

double Profiler::get_child_walltime(size_t const hash, int const input_tid) const
long double Profiler::get_child_walltime(size_t const hash, int const input_tid) const
{
auto tid = static_cast<hashtable_iterator_t_>(input_tid);
return thread_hashtables_[tid].get_child_walltime(hash);
Expand Down
6 changes: 3 additions & 3 deletions src/c++/profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ class Profiler
void write();

// HashEntry getters
double get_thread0_walltime(size_t const hash) const;
double get_self_walltime(size_t const hash, int const input_tid);
double get_child_walltime(size_t const hash, int const input_tid) const;
long double get_thread0_walltime(size_t const hash) const;
long double get_self_walltime(size_t const hash, int const input_tid);
long double get_child_walltime(size_t const hash, int const input_tid) const;
std::string get_region_name(size_t const hash, int const input_tid) const;
unsigned long long int get_region_call_count(size_t const hash, int const input_tid) const;

Expand Down

0 comments on commit ad30052

Please sign in to comment.