Skip to content

Commit 717634c

Browse files
authored
AlgoTimeRegister addtime/Init export to python - ornl-next (#38190)
* AlgoTimeRegister export, tests, docs added
1 parent 59905c8 commit 717634c

File tree

9 files changed

+510
-1
lines changed

9 files changed

+510
-1
lines changed

Framework/API/src/AlgoTimeRegister.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,4 @@ AlgoTimeRegisterImpl::AlgoTimeRegisterImpl()
9292
AlgoTimeRegisterImpl::~AlgoTimeRegisterImpl() {}
9393

9494
} // namespace Instrumentation
95-
} // namespace Mantid
95+
} // namespace Mantid

Framework/PythonInterface/mantid/api/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ set(EXPORT_FILES
9090
src/Exports/RegionSelectorObserver.cpp
9191
)
9292

93+
if(PROFILE_ALGORITHM_LINUX)
94+
set(EXPORT_FILES "${EXPORT_FILES}" "src/Exports/AlgoTimeRegister.cpp")
95+
endif()
96+
9397
set(MODULE_DEFINITION ${CMAKE_CURRENT_BINARY_DIR}/api.cpp)
9498
create_module(${MODULE_TEMPLATE} ${MODULE_DEFINITION} ${EXPORT_FILES})
9599

Framework/PythonInterface/mantid/api/_aliases.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
Defines a set of aliases to make accessing certain objects easier
99
"""
1010

11+
import sys
12+
1113
from mantid.api import (
1214
AlgorithmFactoryImpl,
1315
AlgorithmManagerImpl,
@@ -41,6 +43,12 @@
4143
FunctionFactory = lazy_instance_access(FunctionFactoryImpl)
4244
WorkspaceFactory = lazy_instance_access(WorkspaceFactoryImpl)
4345
CatalogManager = lazy_instance_access(CatalogManagerImpl)
46+
if sys.platform.startswith("linux"):
47+
try:
48+
from mantid.api import AlgoTimeRegisterImpl
4449

50+
AlgoTimeRegister = lazy_instance_access(AlgoTimeRegisterImpl)
51+
except:
52+
AlgoTimeRegister = None
4553
# backwards-compatible
4654
mtd = AnalysisDataService
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Mantid Repository : https://github.com/mantidproject/mantid
2+
//
3+
// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4+
// NScD Oak Ridge National Laboratory, European Spallation Source,
5+
// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6+
// SPDX - License - Identifier: GPL - 3.0 +
7+
#include "MantidAPI/AlgoTimeRegister.h"
8+
#include "MantidKernel/Timer.h"
9+
#include <boost/python/class.hpp>
10+
#include <boost/python/make_constructor.hpp>
11+
#include <boost/python/reference_existing_object.hpp>
12+
#include <boost/python/register_ptr_to_python.hpp>
13+
#include <boost/python/return_value_policy.hpp>
14+
15+
using namespace Mantid::Instrumentation;
16+
using namespace boost::python;
17+
using Mantid::Kernel::time_point_ns;
18+
19+
void addTimeWrapper(const std::string &name, long int begin, long int end) {
20+
21+
std::chrono::nanoseconds begin_ns(begin);
22+
std::chrono::nanoseconds end_ns(end);
23+
24+
// calculate the start time timepoint
25+
std::chrono::time_point<std::chrono::high_resolution_clock> tp_begin_ns(begin_ns);
26+
27+
// calculate the end time timepoint
28+
std::chrono::time_point<std::chrono::high_resolution_clock> tp_end_ns(end_ns);
29+
30+
Mantid::Instrumentation::AlgoTimeRegister::Instance().addTime(name, tp_begin_ns, tp_end_ns);
31+
}
32+
33+
void export_AlgoTimeRegister() {
34+
35+
// AlgoTimeRegister class
36+
class_<AlgoTimeRegisterImpl, boost::noncopyable>("AlgoTimeRegisterImpl", no_init)
37+
.def("addTime", &addTimeWrapper, (arg("name"), arg("begin"), arg("end")),
38+
"Adds a time entry in the file for a function with <name> that starts at <begin> time_ns and ends at <end> "
39+
"time_ns relative to the <START_POINT> clock")
40+
.staticmethod("addTime")
41+
.def("Instance", &AlgoTimeRegister::Instance, return_value_policy<reference_existing_object>(),
42+
"Returns a reference to the AlgoTimeRegister")
43+
.staticmethod("Instance");
44+
}

0 commit comments

Comments
 (0)