-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
284 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
from pycaliper.__pycaliper_impl import ( | ||
__version__, | ||
config_preset, | ||
init, | ||
is_initialized, | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1 @@ | ||
from pycaliper.__pycaliper_impl.types import * | ||
|
||
from enum import Enum | ||
|
||
|
||
_CALI_TYPE_ENUM_PREFIX = "CALI_TYPE_" | ||
_CALI_PROPERTIES_ENUM_PREFIX = "CALI_ATTR_" | ||
|
||
|
||
AttrType = Enum( | ||
"AttrType", | ||
{ | ||
name[len(_CALI_TYPE_ENUM_PREFIX) :]: val | ||
for name, val in AttrTypeEnum.__members__.items() | ||
if name.startswith(_CALI_TYPE_ENUM_PREFIX) | ||
}, | ||
) | ||
|
||
|
||
AttrProperties = Enum( | ||
"AttrProperties", | ||
{ | ||
name[len(_CALI_PROPERTIES_ENUM_PREFIX) :]: val | ||
for name, val in AttrPropertiesEnum.__members__.items() | ||
if name.startswith(_CALI_PROPERTIES_ENUM_PREFIX) | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# --- Caliper continuous integration test app for Python annotation interface | ||
|
||
from pycaliper import config_preset | ||
from pycaliper.instrumentation import ( | ||
Attribute, | ||
set_global_byname, | ||
begin_byname, | ||
set_byname, | ||
end_byname, | ||
) | ||
from pycaliper.types import AttrProperties | ||
from pycaliper.variant import Variant | ||
from pycaliper.config_manager import ConfigManager | ||
|
||
import sys | ||
|
||
|
||
def main(): | ||
config_preset({"CALI_CHANNEL_FLUSH_ON_EXIT", "false"}) | ||
|
||
mgr = ConfigManager() | ||
if len(sys.argv) > 1: | ||
mgr.add(sys.argv[1]) | ||
|
||
if mgr.error(): | ||
print("Caliper config error:", mgr.err_msg(), file=sys.stderr) | ||
exit(-1) | ||
|
||
mgr.start() | ||
|
||
set_global_byname("global.double", 42.42) | ||
set_global_byname("global.int", 1337) | ||
set_global_byname("global.string", "my global string") | ||
set_global_byname("global.uint", 42) | ||
|
||
iter_attr = Attribute("iteration", AttrProperties.CALI_ATTR_ASVALUE) | ||
|
||
begin_byname("phase", "loop") | ||
|
||
for i in range(4): | ||
iter_attr.begin(i) | ||
iter_attr.end() | ||
|
||
end_byname("phase") | ||
|
||
begin_byname("ci_test_c_ann.meta-attr") | ||
|
||
meta_attr = Attribute("meta-attr") | ||
meta_val = Variant(47) | ||
|
||
test_attr = Attribute( | ||
"test-attr-with-metadata", | ||
AttrProperties.CALI_ATTR_UNLIGNED, | ||
[meta_attr], | ||
[meta_val], | ||
) | ||
|
||
test_attr.set("abracadabra") | ||
|
||
end_byname("ci_test_c_ann.meta-attr") | ||
|
||
begin_byname("ci_test_c_ann.setbyname") | ||
|
||
set_byname("attr.int", 20) | ||
set_byname("attr.dbl", 1.25) | ||
set_byname("attr.str", "fidibus") | ||
|
||
end_byname("ci_test_c_ann.setbyname") | ||
|
||
mgr.flush() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
# Tests of the Python API | ||
|
||
import sys | ||
|
||
import unittest | ||
|
||
import calipertest as cat | ||
|
||
|
||
class CaliperPythonAPITest(unittest.TestCase): | ||
"""Caliper Python API test cases""" | ||
|
||
def test_py_ann_trace(self): | ||
target_cmd = [ | ||
sys.executable, | ||
"./ci_test_py_ann.py", | ||
"event-trace,output=stdout", | ||
] | ||
query_cmd = ["../../src/tools/cali-query/cali-query", "-e"] | ||
|
||
caliper_config = {"CALI_LOG_VERBOSITY": "0"} | ||
|
||
query_output = cat.run_test_with_query(target_cmd, query_cmd, caliper_config) | ||
snapshots = cat.get_snapshots_from_text(query_output) | ||
|
||
self.assertTrue(len(snapshots) >= 10) | ||
|
||
self.assertTrue( | ||
cat.has_snapshot_with_keys( | ||
snapshots, {"iteration", "phase", "time.duration.ns", "global.int"} | ||
) | ||
) | ||
self.assertTrue( | ||
cat.has_snapshot_with_attributes( | ||
snapshots, {"event.end#phase": "loop", "phase": "loop"} | ||
) | ||
) | ||
self.assertTrue( | ||
cat.has_snapshot_with_attributes( | ||
snapshots, | ||
{"event.end#iteration": "3", "iteration": "3", "phase": "loop"}, | ||
) | ||
) | ||
self.assertTrue( | ||
cat.has_snapshot_with_keys( | ||
snapshots, | ||
{"attr.int", "attr.dbl", "attr.str", "ci_test_c_ann.setbyname"}, | ||
) | ||
) | ||
self.assertTrue( | ||
cat.has_snapshot_with_attributes( | ||
snapshots, {"attr.int": "20", "attr.str": "fidibus"} | ||
) | ||
) | ||
self.assertTrue( | ||
cat.has_snapshot_with_attributes( | ||
snapshots, {"test-attr-with-metadata": "abracadabra"} | ||
) | ||
) | ||
|
||
def test_py_ann_globals(self): | ||
target_cmd = [sys.executable, "./ci_test_py_ann.py"] | ||
query_cmd = ["../../src/tools/cali-query/cali-query", "-e", "--list-globals"] | ||
|
||
caliper_config = { | ||
"CALI_CONFIG_PROFILE": "serial-trace", | ||
"CALI_RECORDER_FILENAME": "stdout", | ||
"CALI_LOG_VERBOSITY": "0", | ||
} | ||
|
||
query_output = cat.run_test_with_query(target_cmd, query_cmd, caliper_config) | ||
snapshots = cat.get_snapshots_from_text(query_output) | ||
|
||
self.assertTrue(len(snapshots) == 1) | ||
|
||
self.assertTrue( | ||
cat.has_snapshot_with_keys( | ||
snapshots, | ||
{ | ||
"global.double", | ||
"global.string", | ||
"global.int", | ||
"global.uint", | ||
"cali.caliper.version", | ||
}, | ||
) | ||
) | ||
self.assertTrue( | ||
cat.has_snapshot_with_attributes( | ||
snapshots, | ||
{ | ||
"global.int": "1337", | ||
"global.string": "my global string", | ||
"global.uint": "42", | ||
}, | ||
) | ||
) | ||
|
||
def test_py_ann_metadata(self): | ||
target_cmd = [sys.executable, "./ci_test_py_ann.py"] | ||
query_cmd = [ | ||
"../../src/tools/cali-query/cali-query", | ||
"-e", | ||
"--list-attributes", | ||
"--print-attributes", | ||
"cali.attribute.name,cali.attribute.type,meta-attr", | ||
] | ||
|
||
caliper_config = { | ||
"CALI_CONFIG_PROFILE": "serial-trace", | ||
"CALI_RECORDER_FILENAME": "stdout", | ||
"CALI_LOG_VERBOSITY": "0", | ||
} | ||
|
||
query_output = cat.run_test_with_query(target_cmd, query_cmd, caliper_config) | ||
snapshots = cat.get_snapshots_from_text(query_output) | ||
|
||
self.assertTrue( | ||
cat.has_snapshot_with_attributes( | ||
snapshots, | ||
{"cali.attribute.name": "meta-attr", "cali.attribute.type": "int"}, | ||
) | ||
) | ||
self.assertTrue( | ||
cat.has_snapshot_with_attributes( | ||
snapshots, | ||
{ | ||
"cali.attribute.name": "test-attr-with-metadata", | ||
"cali.attribute.type": "string", | ||
"meta-attr": "47", | ||
}, | ||
) | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |