To protect your data, the CISO officer has suggested users to enable GitLab 2FA as soon as possible.

Commit 1c22ca23 authored by John Zhang's avatar John Zhang
Browse files

static function

parent b52158d9
......@@ -31,7 +31,7 @@ limitations under the License.
static inline void get_nano_timestamp(timestamp_t* tstamp) {
*tstamp = mach_absolute_time();
}
double get_elapsed_time(timestamp_t* t0, timestamp_t* t1) {
static double get_elapsed_time(timestamp_t* t0, timestamp_t* t1) {
mach_timebase_info_data_t tb;
timestamp_t elapsed;
uint64_t elapsed_nano;
......@@ -47,7 +47,7 @@ limitations under the License.
static inline void get_nano_timestamp(timestamp_t* tstamp) {
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, tstamp);
}
double get_elapsed_time(timestamp_t* t0, timestamp_t* t1) {
static double get_elapsed_time(timestamp_t* t0, timestamp_t* t1) {
return ((double)(t1->tv_sec - t0->tv_sec)) +
((double)(t1->tv_nsec - t0->tv_nsec)) * 1e-9;
}
......
#!/usr/bin/env python3
# Copyright 2017 The Australian National University
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
class Callback:
"""
Callback root class used by RPython
"""
def __init__(self, param_s):
"""
:param param_s: parameter string for initialisation
"""
pass
def begin(self, kwds=None):
"""
Begin measurement.
"""
pass
def end(self, kwds=None):
"""
End measurement.
"""
pass
def report(self):
"""
Report data to file.
"""
pass
def get_callback(cb_name):
"""
Import callback classes from submodule files,
and dynamically select which class to return.
NOTE: new Callback class implementations should be added here
"""
from callback.cb_print import PrintCallback
from callback.cb_clock import ClockCallback
name_dic = {
'print': PrintCallback,
'clock': ClockCallback,
}
cb_cls = name_dic[cb_name]
return cb_cls
#!/usr/bin/env python3
# Copyright 2017 The Australian National University
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Time measurement using clock_gettime
"""
from rpython.rtyper.lltypesystem import lltype, rffi
from rpython.rlib.rtime import c_clock_gettime, CLOCK_PROCESS_CPUTIME_ID, TIMESPEC, decode_timeval
from callback import Callback
DEFAULT_FLOAT_PREC = 6
class Node:
def __init__(self):
self.t0 = lltype.malloc(TIMESPEC, flavor='raw')
self.t1 = lltype.malloc(TIMESPEC, flavor='raw')
self.nxt = None
def free(self):
lltype.free(self.t0, flavor='raw')
lltype.free(self.t1, flavor='raw')
def decode_timespec(t):
return (float(rffi.getintfield(t, 'c_tv_sec')) +
float(rffi.getintfield(t, 'c_tv_nsec')) * 0.000000001)
class ClockCallback(Callback):
def __init__(self, param_s):
self.nd_head = Node()
self.nd_end = self.nd_head
self.fltfmtprec = int(param_s) if param_s else DEFAULT_FLOAT_PREC
def begin(self, kwds=None):
new = Node()
self.nd_end.nxt = new
self.nd_end = new
c_clock_gettime(CLOCK_PROCESS_CPUTIME_ID, new.t0)
def end(self, kwds=None):
c_clock_gettime(CLOCK_PROCESS_CPUTIME_ID, self.nd_end.t1)
def report(self):
from rpython.rlib.rfloat import double_to_string, DTSF_ADD_DOT_0
p = self.nd_head.nxt
while p:
t0 = decode_timespec(p.t0)
t1 = decode_timespec(p.t1)
print double_to_string(t1 - t0, 'f', self.fltfmtprec, DTSF_ADD_DOT_0)[0]
p = p.nxt
h = self.nd_head
while h:
p = h.nxt
h.free()
h = p
#!/usr/bin/env python3
# Copyright 2017 The Australian National University
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
A simple print callback class as an example.
"""
from callback import Callback
class PrintCallback(Callback):
def __init__(self, param_s):
print("initialised PrintCallback with: %s" % param_s)
def begin(self, kwds=None):
print("begin measurement")
def end(self, kwds=None):
print("end measurement")
def report(self):
pass
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment