Skip to content

Commit

Permalink
start time with scope time (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilipDeegan authored Sep 28, 2024
1 parent 3bbb40f commit 868cca3
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 16 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/build_nix.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@

name: Build on Ubuntu

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

on:
pull_request:

Expand All @@ -13,8 +17,7 @@ jobs:
fail-fast: false
max-parallel: 4
matrix:
python-version: ['3.8', '3.9','3.10', '3.11']
os: [ubuntu-20.04] #, macos-latest
python-version: ['3.11','3.12']

steps:
- uses: actions/checkout@v4
Expand Down
22 changes: 13 additions & 9 deletions inc/phlop/timing/scope_timer.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
#ifndef _PHLOP_TIMING_SCOPE_TIMER_HPP_
#define _PHLOP_TIMING_SCOPE_TIMER_HPP_


#include <array>
#include <chrono>
#include <memory>
#include <thread>
#include <vector>
#include <cassert>
#include <cstdint>
Expand Down Expand Up @@ -93,9 +90,11 @@ struct ScopeTimerMan

struct RunTimerReportSnapshot
{
RunTimerReportSnapshot(RunTimerReport* s, RunTimerReport* p, std::uint64_t const& t)
RunTimerReportSnapshot(RunTimerReport* s, RunTimerReport* p, std::uint64_t const& st,
std::uint64_t const& t)
: self{s}
, parent{p}
, start{st}
, time{t}
{
childs.reserve(2);
Expand All @@ -104,6 +103,7 @@ struct RunTimerReportSnapshot
RunTimerReport const* const self;
RunTimerReport const* const parent;

std::uint64_t const start;
std::uint64_t const time;
std::vector<RunTimerReportSnapshot*> childs;
};
Expand Down Expand Up @@ -167,13 +167,16 @@ struct scope_timer

struct BinaryTimerFileNode
{
BinaryTimerFileNode(std::uint16_t _fn_id, std::uint64_t _time)
BinaryTimerFileNode(std::uint16_t const& _fn_id, std::uint64_t const& _start,
std::uint64_t const& _time)
: fn_id{_fn_id}
, start{_start}
, time{_time}
{
}

std::uint16_t fn_id;
std::uint64_t start;
std::uint64_t time;

std::vector<BinaryTimerFileNode> kinder{};
Expand All @@ -188,8 +191,9 @@ struct BinaryTimerFile
for (auto const& trace : ScopeTimerMan::INSTANCE().traces)
recurse_traces_for_keys(trace);
for (auto const& trace : ScopeTimerMan::INSTANCE().traces)
recurse_traces_for_nodes(
trace, roots.emplace_back(key_ids[std::string{trace->self->k}], trace->time));
recurse_traces_for_nodes(trace,
roots.emplace_back(key_ids[std::string{trace->self->k}],
trace->start, trace->time));
}
}

Expand All @@ -200,7 +204,7 @@ struct BinaryTimerFile
for (std::size_t i = 0; i < c->childs.size(); ++i)
recurse_traces_for_nodes(
c->childs[i], node.kinder.emplace_back(key_ids[std::string{c->childs[i]->self->k}],
c->childs[i]->time));
c->childs[i]->start, c->childs[i]->time));
}

template<typename Trace>
Expand Down Expand Up @@ -270,7 +274,7 @@ struct BinaryTimerFile
{
for (std::size_t ti = 0; ti < tabs; ++ti)
file << " ";
file << node.fn_id << " " << node.time << std::endl;
file << node.fn_id << " " << node.start << ":" << node.time << std::endl;
for (auto const& n : node.kinder)
_write(file, n, tabs + 1);
}
Expand Down
22 changes: 20 additions & 2 deletions phlop/timing/scope_timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,28 @@
@dataclass
class RunTimerNode:
k: int
s: int
t: int
c: list = field(default_factory=lambda: [])

@staticmethod
def from_scope_timer(line):
key, start_and_run_time = line.split(" ")
start_time, run_time = start_and_run_time.split(":")
return RunTimerNode(*[int(e) for e in (key, start_time, run_time)])

@property
def key(self) -> int:
return self.k

@property
def start_time(self) -> int:
return self.s

@property
def run_time(self) -> int:
return self.t


@dataclass
class ScopeTimerFile:
Expand Down Expand Up @@ -53,8 +72,7 @@ def _parent():
if not stripped_line: # last line might be blank
continue
idx = len(line) - len(stripped_line) # how many space indents from left
bits = stripped_line.split(" ")
node = RunTimerNode(*[int(b) for b in bits])
node = RunTimerNode.from_scope_timer(stripped_line)
if idx == 0: # is root node
stack[0] = len(roots)
roots.append(node)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "phlop"
version = "0.0.25"
version = "0.0.26"

dependencies = [

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name="phlop",
version="0.0.25",
version="0.0.26",
cmdclass={},
classifiers=[],
include_package_data=True,
Expand Down
2 changes: 1 addition & 1 deletion src/phlop/timing/scope_timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ scope_timer::~scope_timer()
detail::_current_scope_timer = this->pscope;

auto& s = *r.snapshots.emplace_back( // allocated in construtor
std::make_shared<RunTimerReportSnapshot>(&r, parent, now() - start));
std::make_shared<RunTimerReportSnapshot>(&r, parent, start, now() - start));

if (this->pscope)
pscope->childs.emplace_back(&s);
Expand Down
2 changes: 2 additions & 0 deletions tests/timing/test_scope_timer.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

#include "phlop/timing/scope_timer.hpp"

#include <thread>

using namespace std::chrono_literals;

void fny()
Expand Down

0 comments on commit 868cca3

Please sign in to comment.