Skip to content

Commit

Permalink
Making clock type definitions private (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
bencopl committed Oct 11, 2022
1 parent 0b2f097 commit 3b96742
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/c++/clock.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "clock.h"

Clock::time_point_t Clock::now()
Clock::timepoint_t Clock::now()
{
return std::chrono::steady_clock::now();
}
18 changes: 10 additions & 8 deletions src/c++/clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@ class Clock{

Clock() = delete;

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

private:

// Type definitions for chrono steady clock time points and durations
using duration_t = std::chrono::duration<double>;
using timepoint_t = std::chrono::time_point<std::chrono::steady_clock, duration_t>;

// Member functions
static time_point_t now();
static timepoint_t now();

// Makes sure Clock::now() is only usable by Profiler and is otherwise
// private.
friend class Profiler;
// Makes sure Clock::now() and the type definitions are only usable by
// its friend classes
friend class Profiler;
friend class HashTable;
friend struct HashEntry;
};
10 changes: 5 additions & 5 deletions src/c++/hashtable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

HashEntry::HashEntry(std::string_view region_name)
: region_name_(region_name)
, total_walltime_(Clock::time_duration_t::zero())
, self_walltime_(Clock::time_duration_t::zero())
, child_walltime_(Clock::time_duration_t::zero())
, total_walltime_(Clock::duration_t::zero())
, self_walltime_(Clock::duration_t::zero())
, child_walltime_(Clock::duration_t::zero())
, call_count_(0)
{}

Expand Down Expand Up @@ -55,7 +55,7 @@ size_t HashTable::query_insert(std::string_view region_name) noexcept
*
*/

void HashTable::update(size_t hash, Clock::time_duration_t time_delta)
void HashTable::update(size_t hash, Clock::duration_t time_delta)
{
// Assertions
assert (table_.size() > 0);
Expand All @@ -74,7 +74,7 @@ void HashTable::update(size_t hash, Clock::time_duration_t time_delta)
*
*/

void HashTable::add_child_time(size_t hash, Clock::time_duration_t time_delta)
void HashTable::add_child_time(size_t hash, Clock::duration_t time_delta)
{
// Assertions
assert (table_.size() > 0);
Expand Down
10 changes: 5 additions & 5 deletions src/c++/hashtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ struct HashEntry{

// Data members
std::string region_name_;
Clock::time_duration_t total_walltime_;
Clock::time_duration_t self_walltime_;
Clock::time_duration_t child_walltime_;
Clock::duration_t total_walltime_;
Clock::duration_t self_walltime_;
Clock::duration_t child_walltime_;
unsigned long long int call_count_;

};
Expand Down Expand Up @@ -80,12 +80,12 @@ class HashTable{

// Prototypes
size_t query_insert(std::string_view) noexcept;
void update(size_t, Clock::time_duration_t);
void update(size_t, Clock::duration_t);
void write();

// Member functions
std::vector<size_t> list_keys();
void add_child_time(size_t, Clock::time_duration_t);
void add_child_time(size_t, Clock::duration_t);
void compute_self_times();

// Getters
Expand Down
2 changes: 1 addition & 1 deletion src/c++/profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Profiler::Profiler(){
HashTable new_table(tid);
thread_hashtables_.push_back(new_table);

std::vector<std::pair<size_t,Clock::time_point_t>> new_list;
std::vector<std::pair<size_t,Clock::timepoint_t>> new_list;
thread_traceback_.push_back(new_list);
}

Expand Down
4 changes: 2 additions & 2 deletions src/c++/profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ class Profiler
// Data members
int max_threads_;
std::vector<HashTable> thread_hashtables_;
std::vector<std::vector<std::pair<size_t,Clock::time_point_t>>> thread_traceback_;
std::vector<std::vector<std::pair<size_t,Clock::timepoint_t>>> thread_traceback_;

// Type definitions for vector array indexing.
typedef std::vector<HashTable>::size_type hashtable_iterator_t_;
typedef std::vector<std::vector<std::pair<size_t,Clock::time_point_t>>>::size_type pair_iterator_t_;
typedef std::vector<std::vector<std::pair<size_t,Clock::timepoint_t>>>::size_type pair_iterator_t_;

public:

Expand Down

0 comments on commit 3b96742

Please sign in to comment.