├── .gitmodules ├── CREDITS ├── thirdparty ├── tracewriter │ ├── tracewriter_config.h │ ├── tracewriter.h │ └── tracewriter_xrc.c ├── progress │ ├── progress.h │ └── progress.c ├── npy │ └── npy.cpp └── trs │ └── trs.h ├── src ├── Perf.h ├── LeakageModelFactory.h ├── BivMergeOutput.h ├── PWTermSetMode.h ├── Log.cpp ├── Stackable.h ├── Perf.cpp ├── TraceReader.h ├── StFott.h ├── StChisq.h ├── HWModel.h ├── ElmoModel.h ├── PWArgs.h ├── Passes.h ├── StPattern.h ├── IPWModel.h ├── StCorr.h ├── StStaticAlign.h ├── StNorm.h ├── StNormCrossCorr.h ├── PWFactory.h ├── StMean.h ├── TraceReaderNpy.h ├── TraceReaderTrs.h ├── TraceReaderXrc.h ├── TraceWriter.h ├── CpBivFirstOrderTTest.h ├── CpDynLib.h ├── CpFilter.h ├── CpTrivFirstOrderTTest.h ├── CpUnivFirstOrderTTest.h ├── LeakageModelFactory.cpp ├── CpConvert.h ├── CpUnivSecondOrderTTest.h ├── PImpl.h ├── bivoutputmerge.cpp ├── CpCompress.h ├── CpFileUnivFirstOrderTTest.h ├── Analysis.h ├── leakage_models │ └── AESModel.h ├── MeanAnalysis.h ├── TraceWriterWrapper.h ├── PWTermSetMode.cpp ├── IPWTermSetProc.h ├── TraceWriterNpy.h ├── TraceWriterTrs.h ├── ChisquareTest.h ├── CpStack.h ├── CpFileBivFirstOrderTTest.h ├── CorrAnalysis.h ├── CpFileTrivFirstOrderTTest.h ├── ElmoExtModel.h ├── CpFileBivFirstOrderTTestMt.h ├── CmdPipeline.h ├── DataFile.h ├── PWTermSet.h ├── AnalysisOuput.h ├── StMean.cpp ├── LeakageModel.h ├── FirstOrderTTestAnalysis.h ├── SecondOrderTTestAnalysis.h ├── Log.h ├── Trace.cpp ├── SafeQueue.h ├── Vec2.h ├── Allocator.h ├── IPWLeakageModel.h ├── BivAnalysisMt.h ├── FileProcessor.h ├── WorkContext.h ├── Allocator.cpp ├── StCorr.cpp ├── CpStack.cpp ├── StFott.cpp ├── StChisq.cpp ├── PWConfig.cpp ├── CpConvert.cpp ├── TraceUtils.h ├── CpFileUnivFirstOrderTTest.cpp ├── StNorm.cpp ├── CpCompress.cpp ├── StTraceCombiner.h ├── Passes.cpp ├── Makefile ├── DataFile.cpp ├── PWArgs.cpp ├── WorkContext.cpp ├── CpUnivFirstOrderTTest.cpp ├── transposer.cpp ├── BivMergeOutput.cpp ├── CpUnivSecondOrderTTest.cpp ├── Util.cpp ├── PWTermSet.cpp ├── TraceWriterWrapper.cpp ├── CpStackFactory.cpp ├── AnalysisOuput.cpp ├── CpDynLib.cpp ├── TraceReaderXrc.cpp ├── TraceWriterTrs.cpp ├── MeanAnalysis.cpp ├── CpFileBivFirstOrderTTestMt.cpp ├── RefCountedPtr.h ├── Variant.h └── TraceUtils.cpp └── include ├── PWLeakageParams.h ├── PWConfig.h ├── Util.h └── PWModel.h /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "thirdparty/iir1"] 2 | path = thirdparty/iir1 3 | url = https://github.com/berndporr/iir1.git 4 | -------------------------------------------------------------------------------- /CREDITS: -------------------------------------------------------------------------------- 1 | # Following is a list (alphabetically sorted) of 2 | # contributors of the trace tools project 3 | 4 | N: Madura Anushanga Shelton 5 | E: madura.shelton@adelaide.edu.au 6 | W: https://manushanga.github.io/ 7 | 8 | N: Niels Samwel 9 | E: nsamwel@cs.ru.nl 10 | W: https://nielssamwel.nl/ 11 | -------------------------------------------------------------------------------- /thirdparty/tracewriter/tracewriter_config.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | 16 | #define TW_FMT_I16 17 | -------------------------------------------------------------------------------- /src/Perf.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | #include 16 | 17 | class perf_t 18 | { 19 | public: 20 | perf_t(); 21 | double get_elapsed(); 22 | private: 23 | std::chrono::steady_clock::time_point _tpstart; 24 | }; 25 | -------------------------------------------------------------------------------- /include/PWLeakageParams.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | 16 | enum pwleakage_model_param 17 | { 18 | PWL_PARAM_DUMP_TRACES_FILE = 0, 19 | PWL_PARAM_END 20 | }; 21 | -------------------------------------------------------------------------------- /src/LeakageModelFactory.h: -------------------------------------------------------------------------------- 1 | // Copyright 2022 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "LeakageModel.h" 16 | 17 | class leakage_model_factory_t { 18 | public: 19 | static leakage_model_factory_t* get_instance(); 20 | leakage_model_t* get_model(const std::string& name); 21 | }; -------------------------------------------------------------------------------- /src/BivMergeOutput.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | 16 | #include 17 | #include 18 | 19 | void biv_merge_output(const std::string& inppathtempl, const std::string& outpath, 20 | int splits, uint64_t nsamples, uint64_t ntraces); 21 | -------------------------------------------------------------------------------- /src/PWTermSetMode.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | #include "Util.h" 16 | 17 | enum pwtermset_mode_t 18 | { 19 | TS_RECORD, 20 | TS_IGNORE, 21 | TS_PLAYBACK, 22 | TS_ONLINE, 23 | TS_END 24 | }; 25 | 26 | CAPI pwtermset_mode_t pwtermset_mode_from_config(); 27 | -------------------------------------------------------------------------------- /src/Log.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #include "Log.h" 15 | #include 16 | 17 | int __pw_log_verbosity = 10; 18 | int __pw_log_fd = STDOUT_FILENO; 19 | void pwlog_set_verbosity(int verbosity) 20 | { 21 | __pw_log_verbosity = verbosity; 22 | } 23 | 24 | void pwlog_set_fd(int fd) 25 | { 26 | __pw_log_fd = fd; 27 | } 28 | -------------------------------------------------------------------------------- /include/PWConfig.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | #include "Util.h" 16 | 17 | CAPI void pwconfig_init(); 18 | CAPI void pwconfig_set_value(const char* key, const char* value); 19 | CAPI const char* pwconfig_get_value(const char* key); 20 | CAPI int pwconfig_get_value_int(const char* key); 21 | CAPI void pwconfig_finit(); 22 | -------------------------------------------------------------------------------- /src/Stackable.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | #include "Trace.h" 16 | class stackable_t 17 | { 18 | public: 19 | virtual void init(const traceinfo_t* inti, traceinfo_t* outti) = 0; 20 | virtual const trace_t* process(const trace_t* trace) = 0; 21 | virtual void finit() {} 22 | virtual ~stackable_t() {} 23 | }; 24 | 25 | -------------------------------------------------------------------------------- /src/Perf.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #include "Perf.h" 15 | 16 | perf_t::perf_t() 17 | { 18 | _tpstart = std::chrono::steady_clock::now(); 19 | } 20 | 21 | double perf_t::get_elapsed() 22 | { 23 | auto tpend = std::chrono::steady_clock::now(); 24 | return std::chrono::duration_cast(tpend - _tpstart).count()/1000000000.0; 25 | } 26 | -------------------------------------------------------------------------------- /src/TraceReader.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | #include "Trace.h" 16 | 17 | class tracereader_t 18 | { 19 | public: 20 | virtual void open_file(const char* tracepath, traceinfo_t* info) = 0; 21 | virtual void seek(size_t traceid) = 0; 22 | virtual void rewind() = 0; 23 | virtual int read_trace(trace_t* trace) = 0; 24 | virtual ~tracereader_t() {}; 25 | }; 26 | -------------------------------------------------------------------------------- /src/StFott.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | 16 | #include "Stackable.h" 17 | #include "PImpl.h" 18 | struct st_fott_priv_t; 19 | 20 | class st_fott_t : public stackable_t 21 | { 22 | public: 23 | st_fott_t(); 24 | void init(const traceinfo_t* inti, traceinfo_t* outti); 25 | const trace_t* process(const trace_t* trace); 26 | void finit(); 27 | ~st_fott_t(); 28 | private: 29 | PImpl pimpl; 30 | }; 31 | -------------------------------------------------------------------------------- /src/StChisq.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | 16 | #include "Stackable.h" 17 | #include "PImpl.h" 18 | struct st_chisq_priv_t; 19 | 20 | class st_chisq_t : public stackable_t 21 | { 22 | public: 23 | st_chisq_t(); 24 | void init(const traceinfo_t* inti, traceinfo_t* outti); 25 | const trace_t* process(const trace_t* trace); 26 | void finit(); 27 | ~st_chisq_t(); 28 | private: 29 | PImpl pimpl; 30 | }; 31 | -------------------------------------------------------------------------------- /src/HWModel.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #include "IPWModel.h" 15 | typedef struct _pwprops_t pwprops_t; 16 | typedef struct _pwanalyzer_t pwanalyzer_t; 17 | 18 | struct hwmodel_t : public pwmodel_i 19 | { 20 | public: 21 | void init(pwmodel_t*, const char*); 22 | void finit(pwmodel_t*); 23 | void on_first_trace_done(pwmodel_t*); 24 | void on_trace_done(pwmodel_t*); 25 | private: 26 | pwanalyzer_t* _pwa; 27 | int _totaltraces; 28 | }; 29 | -------------------------------------------------------------------------------- /src/ElmoModel.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #include "IPWModel.h" 15 | typedef struct _pwprops_t pwprops_t; 16 | typedef struct _pwanalyzer_t pwanalyzer_t; 17 | 18 | struct elmomodel_t : public pwmodel_i 19 | { 20 | public: 21 | void init(pwmodel_t*, const char*); 22 | void finit(pwmodel_t*); 23 | void on_first_trace_done(pwmodel_t*); 24 | void on_trace_done(pwmodel_t*); 25 | private: 26 | pwanalyzer_t* _pwa; 27 | int _totaltraces; 28 | }; 29 | -------------------------------------------------------------------------------- /src/PWArgs.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | #include 16 | #include "Util.h" 17 | 18 | typedef struct _pwargs_t 19 | { 20 | char long_sw[32]; 21 | char short_sw[8]; 22 | int arg_start_idx; 23 | int jump_length; 24 | } pwargs_t; 25 | CAPI void pwargs_print_options(pwargs_t *args, const char* longdescs[], int args_count); 26 | CAPI void pwargs_process(int argc, char** argv, pwargs_t *args, int args_count, int* nosw_args_start); 27 | -------------------------------------------------------------------------------- /src/Passes.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | #include "Trace.h" 16 | void pwpass_update_properties(); 17 | void pwpass_moving_average(trace_t *trace); 18 | void pwpass_add_padding(const double* insamples, uint32_t nin, double* outsamples, 19 | uint32_t nout, uint16_t pad_amount, double pad_value); 20 | void pwpass_compress(const double* insamples, uint32_t nin, double* outsamples, 21 | uint32_t nout, uint32_t window, uint32_t overlap); 22 | -------------------------------------------------------------------------------- /src/StPattern.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | #include "Trace.h" 16 | #include "Stackable.h" 17 | #include "PImpl.h" 18 | struct st_pattern_priv_t; 19 | class st_pattern_t : public stackable_t 20 | { 21 | public: 22 | void init(const traceinfo_t* inti, traceinfo_t* outti); 23 | const trace_t* process(const trace_t* trace); 24 | void finit(); 25 | ~st_pattern_t(); 26 | private: 27 | PImpl _pimpl; 28 | }; 29 | 30 | -------------------------------------------------------------------------------- /src/IPWModel.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | #include "PWModel.h" 16 | 17 | struct _pwmodel_i 18 | { 19 | public: 20 | virtual void init(pwmodel_t*, const char*) = 0; 21 | virtual void finit(pwmodel_t*) = 0; 22 | // called when first trace is done before on_trace_done() 23 | virtual void on_first_trace_done(pwmodel_t*) = 0; 24 | // called on all trace collection done events 25 | virtual void on_trace_done(pwmodel_t*) = 0; 26 | }; 27 | -------------------------------------------------------------------------------- /src/StCorr.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | 16 | #include "Stackable.h" 17 | #include "PImpl.h" 18 | struct st_corr_priv_t; 19 | 20 | class st_corr_t : public stackable_t 21 | { 22 | public: 23 | st_corr_t(); 24 | void init(const traceinfo_t* inti, traceinfo_t* outti) override; 25 | const trace_t* process(const trace_t*) override; 26 | void finit() override; 27 | ~st_corr_t() override; 28 | private: 29 | PImpl pimpl; 30 | }; 31 | -------------------------------------------------------------------------------- /src/StStaticAlign.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | #include "Trace.h" 16 | #include "Stackable.h" 17 | #include "PImpl.h" 18 | struct st_static_align_priv_t; 19 | class st_static_align_t : public stackable_t 20 | { 21 | public: 22 | void init(const traceinfo_t* inti, traceinfo_t* outti); 23 | const trace_t* process(const trace_t* trace); 24 | void finit(); 25 | ~st_static_align_t(); 26 | private: 27 | PImpl _pimpl; 28 | }; 29 | 30 | -------------------------------------------------------------------------------- /thirdparty/progress/progress.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | typedef struct _progress_t 16 | { 17 | int perc; 18 | int perc_incr; 19 | unsigned long last; 20 | unsigned long mod; 21 | } progress_t; 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | void progress_init(progress_t* pg, unsigned long max); 26 | void progress_update(progress_t* pg, unsigned long current); 27 | void progress_finit(progress_t* pg); 28 | #ifdef __cplusplus 29 | } 30 | #endif 31 | 32 | -------------------------------------------------------------------------------- /src/StNorm.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | 16 | #include "Stackable.h" 17 | #include "StMean.h" 18 | #include "PImpl.h" 19 | struct st_norm_priv_t; 20 | 21 | class st_norm_t : public stackable_t 22 | { 23 | public: 24 | st_norm_t(st_mean_t* prerunmeans); 25 | void init(const traceinfo_t* inti, traceinfo_t* outti) override; 26 | const trace_t* process(const trace_t* trace) override; 27 | ~st_norm_t() override; 28 | private: 29 | PImpl pimpl; 30 | }; 31 | -------------------------------------------------------------------------------- /src/StNormCrossCorr.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | #include "Trace.h" 16 | #include "Stackable.h" 17 | #include "PImpl.h" 18 | struct st_norm_cross_corr_priv_t; 19 | class st_norm_cross_corr_t : public stackable_t 20 | { 21 | public: 22 | void init(const traceinfo_t* inti, traceinfo_t* outti); 23 | const trace_t* process(const trace_t* trace); 24 | void finit(); 25 | ~st_norm_cross_corr_t(); 26 | private: 27 | PImpl _pimpl; 28 | }; 29 | 30 | -------------------------------------------------------------------------------- /src/PWFactory.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | #include "TraceReader.h" 16 | #include "TraceWriter.h" 17 | #include "Analysis.h" 18 | #include "CmdPipeline.h" 19 | class pwfactory_t 20 | { 21 | public: 22 | static pwfactory_t* get_instance(); 23 | tracereader_t* new_tracereader(const std::string& kind); 24 | tracewriter_t* new_tracewriter(const std::string& kind); 25 | analysis_t* new_analysis(const std::string& kind); 26 | cmd_pipeline_t* new_cmdpipeline(const std::string& kind); 27 | }; 28 | -------------------------------------------------------------------------------- /src/StMean.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | 16 | #include "Stackable.h" 17 | #include "PImpl.h" 18 | #include 19 | struct st_mean_priv_t; 20 | 21 | class st_mean_t : public stackable_t 22 | { 23 | public: 24 | st_mean_t(); 25 | void init(const traceinfo_t* inti, traceinfo_t* outti) override; 26 | const trace_t* process(const trace_t* trace) override; 27 | double get_mean(int group, int sample); 28 | ~st_mean_t() override; 29 | private: 30 | PImpl pimpl; 31 | }; 32 | -------------------------------------------------------------------------------- /src/TraceReaderNpy.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | #include "TraceReader.h" 16 | #include "PImpl.h" 17 | 18 | struct tracereader_npy_priv_t; 19 | 20 | class tracereader_npy_t : public tracereader_t 21 | { 22 | public: 23 | tracereader_npy_t(); 24 | void open_file(const char* tracepath, traceinfo_t* info) override; 25 | void seek(size_t traceid) override; 26 | void rewind() override; 27 | int read_trace(trace_t* trace) override; 28 | ~tracereader_npy_t() override; 29 | private: 30 | PImpl pimpl; 31 | }; 32 | -------------------------------------------------------------------------------- /src/TraceReaderTrs.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | #include "TraceReader.h" 16 | #include "PImpl.h" 17 | 18 | struct tracereader_trs_priv_t; 19 | 20 | class tracereader_trs_t : public tracereader_t 21 | { 22 | public: 23 | tracereader_trs_t(); 24 | void open_file(const char* tracepath, traceinfo_t* info) override; 25 | void seek(size_t traceid) override; 26 | void rewind() override; 27 | int read_trace(trace_t* trace) override; 28 | ~tracereader_trs_t() override; 29 | private: 30 | PImpl pimpl; 31 | }; 32 | -------------------------------------------------------------------------------- /src/TraceReaderXrc.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | #include "TraceReader.h" 16 | #include "PImpl.h" 17 | 18 | struct tracereader_xrc_priv_t; 19 | 20 | class tracereader_xrc_t : public tracereader_t 21 | { 22 | public: 23 | tracereader_xrc_t(); 24 | void open_file(const char* tracepath, traceinfo_t* info) override; 25 | void seek(size_t traceid) override; 26 | void rewind() override; 27 | int read_trace(trace_t* trace) override; 28 | ~tracereader_xrc_t() override; 29 | private: 30 | PImpl pimpl; 31 | }; 32 | -------------------------------------------------------------------------------- /src/TraceWriter.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | 16 | #include 17 | #include "Trace.h" 18 | 19 | class tracewriter_t 20 | { 21 | public: 22 | virtual void open_file(const char* tracepath, 23 | const traceinfo_t* info, 24 | const std::vector& opts) = 0; 25 | virtual void update_traceinfo(const traceinfo_t* newtraceinfo) = 0; 26 | virtual int write_trace(const trace_t* trace) = 0; 27 | virtual void finit(const traceinfo_t* finaltraceinfo) = 0; 28 | virtual ~tracewriter_t() {}; 29 | }; 30 | -------------------------------------------------------------------------------- /src/CpBivFirstOrderTTest.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | 16 | #include "CmdPipeline.h" 17 | #include "PImpl.h" 18 | struct cp_biv_first_order_ttest_priv_t; 19 | class cp_biv_first_order_ttest_t : public cmd_pipeline_t 20 | { 21 | public: 22 | cp_biv_first_order_ttest_t(); 23 | void init(const traceinfo_t *traceinfo, pwtermset_mode_t mode) override; 24 | void process(const trace_t* trace) override; 25 | void finit() override; 26 | ~cp_biv_first_order_ttest_t(); 27 | private: 28 | PImpl pimpl; 29 | 30 | }; 31 | -------------------------------------------------------------------------------- /src/CpDynLib.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | 16 | #include "CmdPipeline.h" 17 | #include "PImpl.h" 18 | struct cp_dynlib_priv_t; 19 | 20 | class cp_dynlib_t : public cmd_pipeline_t 21 | { 22 | public: 23 | cp_dynlib_t(); 24 | void init(const traceinfo_t *traceinfo, pwtermset_mode_t mode) override; 25 | void init(const char* filename) override; 26 | void process() override; 27 | void process(const trace_t* trace) override; 28 | void finit() override; 29 | ~cp_dynlib_t() override; 30 | private: 31 | PImpl pimpl; 32 | }; 33 | -------------------------------------------------------------------------------- /src/CpFilter.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | 16 | #include "CmdPipeline.h" 17 | #include "PImpl.h" 18 | struct cp_filter_priv_t; 19 | 20 | class cp_filter_t : public cmd_pipeline_t 21 | { 22 | public: 23 | cp_filter_t(); 24 | void init(const traceinfo_t *traceinfo, pwtermset_mode_t mode) override; 25 | void init(const char* filename) override; 26 | void process() override; 27 | void process(const trace_t* trace) override; 28 | void finit() override; 29 | ~cp_filter_t() override; 30 | private: 31 | PImpl pimpl; 32 | }; 33 | -------------------------------------------------------------------------------- /src/CpTrivFirstOrderTTest.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | 16 | #include "CmdPipeline.h" 17 | #include "PImpl.h" 18 | struct cp_triv_first_order_ttest_priv_t; 19 | class cp_triv_first_order_ttest_t : public cmd_pipeline_t 20 | { 21 | public: 22 | cp_triv_first_order_ttest_t(); 23 | void init(const traceinfo_t *traceinfo, pwtermset_mode_t mode) override; 24 | void process(const trace_t* trace) override; 25 | void finit() override; 26 | ~cp_triv_first_order_ttest_t(); 27 | private: 28 | PImpl pimpl; 29 | 30 | }; 31 | -------------------------------------------------------------------------------- /src/CpUnivFirstOrderTTest.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | 16 | #include "CmdPipeline.h" 17 | #include "PImpl.h" 18 | struct cp_univ_first_order_ttest_priv_t; 19 | 20 | class cp_univ_first_order_ttest_t : public cmd_pipeline_t 21 | { 22 | public: 23 | cp_univ_first_order_ttest_t(); 24 | void init(const traceinfo_t *traceinfo, pwtermset_mode_t mode) override; 25 | void process(const trace_t* trace) override; 26 | void finit() override; 27 | ~cp_univ_first_order_ttest_t(); 28 | private: 29 | PImpl pimpl; 30 | }; 31 | -------------------------------------------------------------------------------- /src/LeakageModelFactory.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2022 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "LeakageModelFactory.h" 16 | 17 | #include "leakage_models/AESModel.h" 18 | 19 | leakage_model_factory_t* leakage_model_factory_t::get_instance() 20 | { 21 | static leakage_model_factory_t model_fac; 22 | return &model_fac; 23 | } 24 | leakage_model_t* leakage_model_factory_t::get_model(const std::string& name) 25 | { 26 | if (name == "aes128" || name == "aes") { 27 | return new aes_model_t(); 28 | } 29 | else 30 | { 31 | LogErrDie("No matching model found\n"); 32 | } 33 | } -------------------------------------------------------------------------------- /src/CpConvert.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | 16 | #include "CmdPipeline.h" 17 | #include "PImpl.h" 18 | struct cp_convert_priv_t; 19 | 20 | class cp_convert_t : public cmd_pipeline_t 21 | { 22 | public: 23 | cp_convert_t(); 24 | void init(const traceinfo_t *traceinfo, pwtermset_mode_t mode) override; 25 | void init(const char* filename) override; 26 | void process() override; 27 | void process(const trace_t* trace) override; 28 | void finit() override; 29 | ~cp_convert_t() override; 30 | private: 31 | PImpl pimpl; 32 | }; 33 | -------------------------------------------------------------------------------- /src/CpUnivSecondOrderTTest.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | 16 | #include "CmdPipeline.h" 17 | #include "PImpl.h" 18 | struct cp_univ_second_order_ttest_priv_t; 19 | 20 | class cp_univ_second_order_ttest_t : public cmd_pipeline_t 21 | { 22 | public: 23 | cp_univ_second_order_ttest_t(); 24 | void init(const traceinfo_t *traceinfo, pwtermset_mode_t mode) override; 25 | void process(const trace_t* trace) override; 26 | void finit() override; 27 | ~cp_univ_second_order_ttest_t(); 28 | private: 29 | PImpl pimpl; 30 | }; 31 | -------------------------------------------------------------------------------- /src/PImpl.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | 16 | template 17 | class PImpl 18 | { 19 | public: 20 | PImpl() : _t(nullptr) {} 21 | PImpl(const PImpl& other) 22 | { 23 | _t = new T(*other._t); 24 | } 25 | PImpl(PImpl&& other) 26 | { 27 | _t = other._t; 28 | other._t = nullptr; 29 | } 30 | void init() 31 | { 32 | _t = new T(); 33 | } 34 | T* get() 35 | { 36 | return _t; 37 | } 38 | ~PImpl() 39 | { 40 | delete _t; 41 | } 42 | private: 43 | T* _t; 44 | }; 45 | -------------------------------------------------------------------------------- /src/bivoutputmerge.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #include "BivMergeOutput.h" 15 | #include "Log.h" 16 | #include 17 | 18 | void showhelp() 19 | { 20 | LogInfo("Usage: bivoutputmerge \ 21 | \n"); 22 | } 23 | int main(int argc, char **argv) 24 | { 25 | if (argc != 5) 26 | { 27 | showhelp(); 28 | return 0; 29 | } 30 | 31 | biv_merge_output(argv[1], argv[2], 4, 32 | (uint64_t)atol(argv[3]), (uint64_t)atol(argv[4])); 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /src/CpCompress.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | 16 | #include "CmdPipeline.h" 17 | #include "PImpl.h" 18 | struct cp_compress_priv_t; 19 | 20 | class cp_compress_t : public cmd_pipeline_t 21 | { 22 | public: 23 | cp_compress_t(); 24 | void init(const traceinfo_t *traceinfo, pwtermset_mode_t mode) override; 25 | void init(const char* filename) override; 26 | void process() override; 27 | void process(const trace_t* trace) override; 28 | void finit() override; 29 | ~cp_compress_t() override; 30 | private: 31 | PImpl pimpl; 32 | }; 33 | -------------------------------------------------------------------------------- /src/CpFileUnivFirstOrderTTest.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | 16 | #include "CmdPipeline.h" 17 | #include "PImpl.h" 18 | struct cp_file_univ_first_order_ttest_priv_t; 19 | 20 | class cp_file_univ_first_order_ttest_t : public cmd_pipeline_t 21 | { 22 | public: 23 | cp_file_univ_first_order_ttest_t(); 24 | void init(const traceinfo_t *traceinfo, pwtermset_mode_t mode) override; 25 | void process(const trace_t* trace) override; 26 | void finit() override; 27 | ~cp_file_univ_first_order_ttest_t(); 28 | private: 29 | PImpl pimpl; 30 | }; 31 | -------------------------------------------------------------------------------- /src/Analysis.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | 16 | #include 17 | #include 18 | #include "Trace.h" 19 | #include "Variant.h" 20 | 21 | class analysis_output_t; 22 | 23 | typedef std::map analysis_opts_t; 24 | 25 | class analysis_t 26 | { 27 | public: 28 | virtual void init(const traceinfo_t *traceinfo, 29 | analysis_output_t* output, 30 | const analysis_opts_t& opts = {}) = 0; 31 | virtual void trace_submit(const trace_t *trace) = 0; 32 | virtual void finit() = 0; 33 | virtual ~analysis_t() {} 34 | }; 35 | -------------------------------------------------------------------------------- /src/leakage_models/AESModel.h: -------------------------------------------------------------------------------- 1 | // Copyright 2022 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "LeakageModel.h" 18 | 19 | class aes_model_t : public leakage_model_t { 20 | public: 21 | void init(const traceinfo_t* ti, leakage_t** leakage); 22 | void model_leakage(const uint8_t* data, leakage_t* leakage); 23 | void pick_best(const trace_t* corr, std::vector& winners); 24 | private: 25 | const uint8_t* get_key(const uint8_t* data); 26 | const uint8_t* get_plain(const uint8_t* data); 27 | const uint8_t* get_cipher(const uint8_t* data); 28 | 29 | std::vector cipher; 30 | traceinfo_t _ti; 31 | }; -------------------------------------------------------------------------------- /src/MeanAnalysis.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | 16 | #include "Analysis.h" 17 | #include "PImpl.h" 18 | 19 | struct mean_analysis_priv_t; 20 | class mean_analysis_t : public analysis_t 21 | { 22 | public: 23 | mean_analysis_t(); 24 | void init(const traceinfo_t *traceinfo, 25 | analysis_output_t* output, 26 | const analysis_opts_t& opts = {}) override; 27 | void trace_submit(const trace_t *trace) override; 28 | void finit() override; 29 | 30 | double getmean(int groupid, int sampleid); 31 | ~mean_analysis_t(); 32 | private: 33 | PImpl pimpl; 34 | }; 35 | -------------------------------------------------------------------------------- /src/TraceWriterWrapper.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | #include "TraceWriter.h" 16 | 17 | class tracewriter_wrapper_t : public tracewriter_t 18 | { 19 | public: 20 | tracewriter_wrapper_t(tracewriter_t* base); 21 | virtual void open_file(const char* tracepath, 22 | const traceinfo_t* info, 23 | const std::vector& opts); 24 | virtual void update_traceinfo(const traceinfo_t* newtraceinfo); 25 | virtual int write_trace(const trace_t* trace); 26 | virtual void finit(const traceinfo_t* finaltraceinfo); 27 | virtual ~tracewriter_wrapper_t(); 28 | private: 29 | tracewriter_t* _base; 30 | bool _active; 31 | }; 32 | -------------------------------------------------------------------------------- /src/PWTermSetMode.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #include "PWTermSetMode.h" 15 | #include "PWConfig.h" 16 | #include 17 | pwtermset_mode_t pwtermset_mode_from_config() 18 | { 19 | const char* mode = pwconfig_get_value("TS_MODE"); 20 | pwtermset_mode_t ret = TS_ONLINE; 21 | 22 | if (mode == nullptr) 23 | { 24 | return ret; 25 | } 26 | 27 | if (strcmp("online", mode) == 0) 28 | { 29 | ret = TS_ONLINE; 30 | } 31 | else if (strcmp("record", mode) == 0) 32 | { 33 | ret = TS_RECORD; 34 | } 35 | else if (strcmp("ignore", mode) == 0) 36 | { 37 | ret = TS_IGNORE; 38 | } 39 | return ret; 40 | } 41 | -------------------------------------------------------------------------------- /src/IPWTermSetProc.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | #include "Log.h" 16 | 17 | #include 18 | #include 19 | 20 | #define TS_DUMP_FILE "./termsetdump.npy" 21 | 22 | struct _pwtsp_i 23 | { 24 | virtual void pwtsp_init(int nterms, int nsamples, int ntraces) = 0; 25 | virtual void pwtsp_bulk_process(double* termsamples) = 0; 26 | virtual void pwtsp_set_leakyindexes(int* leakyinds, int leakyindscount) { LogErrDie("leaky indexes not implemented\n"); } 27 | virtual void pwtsp_trace_submit(double* termsamples) = 0; 28 | virtual void pwtsp_dump_output(const char* outputfile) = 0; 29 | virtual void pwtsp_finit() = 0; 30 | virtual ~_pwtsp_i() {} 31 | }; 32 | -------------------------------------------------------------------------------- /src/TraceWriterNpy.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | #include "TraceWriter.h" 16 | #include "PImpl.h" 17 | 18 | struct tracewriter_npy_priv_t; 19 | 20 | class tracewriter_npy_t : public tracewriter_t 21 | { 22 | public: 23 | tracewriter_npy_t(); 24 | void open_file(const char* tracepath, const traceinfo_t* info, 25 | const std::vector& opts = {"termcomb",""}) override; 26 | void update_traceinfo(const traceinfo_t* newtraceinfo) override; 27 | int write_trace(const trace_t* trace) override; 28 | void finit(const traceinfo_t* finaltraceinfo) override; 29 | ~tracewriter_npy_t() override; 30 | private: 31 | PImpl pimpl; 32 | }; 33 | -------------------------------------------------------------------------------- /src/TraceWriterTrs.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | #include "TraceWriter.h" 16 | #include "PImpl.h" 17 | 18 | struct tracewriter_trs_priv_t; 19 | 20 | class tracewriter_trs_t : public tracewriter_t 21 | { 22 | public: 23 | tracewriter_trs_t(); 24 | void open_file(const char* tracepath, const traceinfo_t* info, 25 | const std::vector& opts = {"termcomb",""}) override; 26 | void update_traceinfo(const traceinfo_t* newtraceinfo) override; 27 | int write_trace(const trace_t* trace) override; 28 | void finit(const traceinfo_t* finaltraceinfo) override; 29 | ~tracewriter_trs_t() override; 30 | private: 31 | PImpl pimpl; 32 | }; 33 | -------------------------------------------------------------------------------- /src/ChisquareTest.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | 16 | #include "Analysis.h" 17 | #include "PImpl.h" 18 | 19 | struct chisquare_test_priv_t; 20 | 21 | class chisquare_test_t : public analysis_t 22 | { 23 | public: 24 | struct is_sample_independent {}; 25 | 26 | chisquare_test_t(); 27 | chisquare_test_t(const chisquare_test_t&); 28 | chisquare_test_t(chisquare_test_t&&); 29 | void init(const traceinfo_t *traceinfo, 30 | analysis_output_t* output, const analysis_opts_t& opts = {}); 31 | void trace_submit(const trace_t *trace); 32 | void finit(); 33 | ~chisquare_test_t(); 34 | private: 35 | double calc_chisq_at(int index); 36 | 37 | PImpl _pimpl; 38 | }; 39 | -------------------------------------------------------------------------------- /src/CpStack.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | #include "Trace.h" 16 | #include "CmdPipeline.h" 17 | #include "Stackable.h" 18 | 19 | #include 20 | #include 21 | class cp_stack_t : public cmd_pipeline_t 22 | { 23 | public: 24 | static cp_stack_t* make_instance(const std::string& name); 25 | void get_info(cmd_pipeline_info_t& info); 26 | 27 | void init(const traceinfo_t *traceinfo, pwtermset_mode_t mode); 28 | void stack_add(stackable_t* cp, int pass); 29 | 30 | void pass_begin(int pass); 31 | void process(const trace_t* trace); 32 | void pass_end(int pass); 33 | void finit(); 34 | private: 35 | std::vector> _multistack; 36 | uint32_t _passes; 37 | uint32_t _current_pass; 38 | }; 39 | 40 | -------------------------------------------------------------------------------- /src/CpFileBivFirstOrderTTest.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | 16 | #include "CmdPipeline.h" 17 | #include "PImpl.h" 18 | struct cp_file_biv_first_order_ttest_priv_t; 19 | class cp_file_biv_first_order_ttest_t : public cmd_pipeline_t 20 | { 21 | public: 22 | cp_file_biv_first_order_ttest_t(); 23 | void get_info(cmd_pipeline_info_t& info) override; 24 | void init(const traceinfo_t *traceinfo, pwtermset_mode_t mode); 25 | void init(const char* filename) override; 26 | void pass_begin(int pass) override; 27 | void process() override; 28 | void process(const trace_t* trace) override; 29 | void pass_end(int pass) override; 30 | void finit() override; 31 | ~cp_file_biv_first_order_ttest_t(); 32 | private: 33 | PImpl pimpl; 34 | 35 | }; 36 | -------------------------------------------------------------------------------- /src/CorrAnalysis.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | 16 | #include "Trace.h" 17 | #include "Analysis.h" 18 | #include "AnalysisOuput.h" 19 | #include "PImpl.h" 20 | 21 | struct corr_analysis_priv_t; 22 | 23 | class corr_analysis_t : public analysis_t 24 | { 25 | public: 26 | corr_analysis_t(); 27 | void init(const traceinfo_t *traceinfo, 28 | analysis_output_t* output, 29 | const analysis_opts_t& opts = {}); 30 | void trace_submit(const trace_t *trace); 31 | void finit(); 32 | ~corr_analysis_t(); 33 | private: 34 | void calc_output(uint32_t outputtraces, trace_t* trace, 35 | uint32_t model_dist_idx, double* maxcorrelation); 36 | void read_stdin(std::vector& modelvals); 37 | PImpl pimpl; 38 | }; 39 | -------------------------------------------------------------------------------- /src/CpFileTrivFirstOrderTTest.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | 16 | #include "CmdPipeline.h" 17 | #include "PImpl.h" 18 | struct cp_file_triv_first_order_ttest_priv_t; 19 | class cp_file_triv_first_order_ttest_t : public cmd_pipeline_t 20 | { 21 | public: 22 | cp_file_triv_first_order_ttest_t(); 23 | void get_info(cmd_pipeline_info_t& info) override; 24 | void init(const traceinfo_t *traceinfo, pwtermset_mode_t mode); 25 | void init(const char* filename) override; 26 | void pass_begin(int pass) override; 27 | void process() override; 28 | void process(const trace_t* trace) override; 29 | void pass_end(int pass) override; 30 | void finit() override; 31 | ~cp_file_triv_first_order_ttest_t(); 32 | private: 33 | PImpl pimpl; 34 | 35 | }; 36 | -------------------------------------------------------------------------------- /src/ElmoExtModel.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | 16 | #include 17 | #include "IPWModel.h" 18 | 19 | typedef struct _pwprops_t pwprops_t; 20 | typedef struct _pwanalyzer_t pwanalyzer_t; 21 | typedef struct _pwtermset_t pwtermset_t; 22 | typedef struct _termcombs_t termcombs_t; 23 | 24 | struct elmoextmodel_t : public pwmodel_i 25 | { 26 | public: 27 | void init(pwmodel_t*, const char*); 28 | void finit(pwmodel_t*); 29 | void on_first_trace_done(pwmodel_t*); 30 | void on_trace_done(pwmodel_t*); 31 | private: 32 | uint8_t* _data; 33 | pwprops_t* _props; 34 | pwanalyzer_t* _power; 35 | termcombs_t* _tc; 36 | pwtermset_t* _ts; 37 | pwtermset_t* _tpower; 38 | double* _powersamples; 39 | double* _termsamples; 40 | int _nsamples; 41 | int _totaltraces; 42 | }; 43 | -------------------------------------------------------------------------------- /src/CpFileBivFirstOrderTTestMt.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | 16 | #include "CmdPipeline.h" 17 | #include "PImpl.h" 18 | struct cp_file_biv_first_order_ttest_mt_priv_t; 19 | class cp_file_biv_first_order_ttest_mt_t : public cmd_pipeline_t 20 | { 21 | public: 22 | cp_file_biv_first_order_ttest_mt_t(); 23 | void get_info(cmd_pipeline_info_t& info) override; 24 | void init(const traceinfo_t *traceinfo, pwtermset_mode_t mode); 25 | void init(const char* filename) override; 26 | void pass_begin(int pass) override; 27 | void process() override; 28 | void process(const trace_t* trace) override; 29 | void pass_end(int pass) override; 30 | void finit() override; 31 | ~cp_file_biv_first_order_ttest_mt_t(); 32 | private: 33 | PImpl pimpl; 34 | 35 | }; 36 | -------------------------------------------------------------------------------- /src/CmdPipeline.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | #include "PWTermSetMode.h" 16 | #include "Trace.h" 17 | #include "Log.h" 18 | 19 | struct cmd_pipeline_info_t 20 | { 21 | int passes_count; 22 | }; 23 | class cmd_pipeline_t 24 | { 25 | public: 26 | virtual void get_info(cmd_pipeline_info_t& info) { info = cmd_pipeline_info_t{1}; } 27 | 28 | virtual void init(const traceinfo_t *traceinfo, pwtermset_mode_t mode) { LogErrDie("not implemented\n"); } 29 | virtual void init(const char* filename) { LogErrDie("not implemented\n"); } 30 | virtual void pass_begin(int pass) {} 31 | virtual void process() { LogErrDie("not implemented\n"); } 32 | virtual void process(const trace_t* trace) = 0; 33 | virtual void pass_end(int pass) {} 34 | virtual void finit() = 0; 35 | virtual ~cmd_pipeline_t() {} 36 | 37 | }; 38 | -------------------------------------------------------------------------------- /src/DataFile.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | 16 | #include 17 | #include 18 | struct pwdatastream_t 19 | { 20 | std::ofstream ofstream; 21 | std::ifstream ifstream; 22 | int length; 23 | bool hasdata; 24 | }; 25 | bool pwdata_write_open(pwdatastream_t& pwd, const std::string& filename); 26 | bool pwdata_read_open(pwdatastream_t& pwd, const std::string& filename, uint32_t& length); 27 | int pwdata_get_data_length(pwdatastream_t& pwd); 28 | void pwdata_read_data(pwdatastream_t& pwd, uint8_t* data, uint32_t length); 29 | void pwdata_write_data(pwdatastream_t& pwd, uint8_t* data, uint32_t length); 30 | void pwdata_write_close(pwdatastream_t& pwd); 31 | void pwdata_read_close(pwdatastream_t& pwd); 32 | void pwdata_read_rewind(pwdatastream_t& pwd); 33 | void pwdata_read_seek(pwdatastream_t& pwd, size_t traceid); 34 | -------------------------------------------------------------------------------- /src/PWTermSet.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | 16 | #include 17 | #include "Trace.h" 18 | 19 | struct _pwtsp_i; 20 | struct _pwtermset_impl_t; 21 | struct trace_t; 22 | typedef struct _pwtermset_t 23 | { 24 | _pwtsp_i* tsp; 25 | _pwtermset_impl_t* impl; 26 | } pwtermset_t; 27 | 28 | void pwtermset_init(pwtermset_t**, const traceinfo_t *traceinfo, const char* tsdumpfile); 29 | void pwtermset_init_from_file(pwtermset_t**, const char* termsetfile); 30 | void pwtermset_process_file(pwtermset_t*); 31 | void pwtermset_bulk_process(pwtermset_t*, double* termsamples); 32 | void pwtermset_set_leakyindexes(pwtermset_t*, int* leakyinds, int leakyindscount); 33 | void pwtermset_trace_submit(pwtermset_t*, trace_t* trace); 34 | void pwtermset_dump_output(pwtermset_t*, const char* outputfile); 35 | void pwtermset_finit(pwtermset_t*); 36 | 37 | -------------------------------------------------------------------------------- /include/Util.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | #include 16 | #include 17 | 18 | #ifdef __cplusplus 19 | #define CAPI \ 20 | extern "C" 21 | #else 22 | #define CAPI 23 | #endif 24 | 25 | #define PWASSERT(_exp, _msg) \ 26 | { \ 27 | if ( (_exp) == false ) \ 28 | { \ 29 | printf("assert failed: '%s' at %s:%u\n", _msg, __FILE__, __LINE__); \ 30 | std::abort(); \ 31 | } \ 32 | } 33 | 34 | CAPI int pwutil_get_tracecount(const char* execfile); 35 | CAPI char* pwutil_dirname(char *path); 36 | CAPI int pwutil_abspath(const char* relpath, char* abspath, int abspathlen); 37 | CAPI uint8_t hex_to_byte(const char hex[2]); 38 | CAPI void hexstr_to_bytebuf(const char* hexstr, uint8_t* bytebuf); 39 | CAPI void bytebuf_to_hexstr(const uint8_t* bytebuf, int bytebuflen, char* hexstr); 40 | -------------------------------------------------------------------------------- /src/AnalysisOuput.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | #include 16 | #include 17 | #include "PImpl.h" 18 | #include "Trace.h" 19 | struct analysis_output_priv_t; 20 | 21 | class analysis_output_t 22 | { 23 | public: 24 | analysis_output_t(); 25 | analysis_output_t(const analysis_output_t& a); 26 | analysis_output_t(analysis_output_t&&); 27 | void init(const char* outputfile, const std::string& kind); 28 | analysis_output_t* add_sub_output(const std::string& id, const std::string& kind); 29 | analysis_output_t* get_sub_output(size_t index); 30 | void init(const traceinfo_t* traceinfo); 31 | void on_result_trace(const trace_t* trace); 32 | void update_written_count(); 33 | size_t get_written_count(); 34 | size_t finit(); 35 | ~analysis_output_t(); 36 | private: 37 | PImpl pimpl; 38 | }; 39 | -------------------------------------------------------------------------------- /src/StMean.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #include "StMean.h" 15 | #include "MeanAnalysis.h" 16 | #include "AnalysisOuput.h" 17 | #include "WorkContext.h" 18 | #include "PWFactory.h" 19 | #include "TraceReader.h" 20 | struct st_mean_priv_t 21 | { 22 | mean_analysis_t mean; 23 | traceinfo_t traceinfo; 24 | traceinfo_t winti; 25 | }; 26 | st_mean_t::st_mean_t() 27 | { 28 | pimpl.init(); 29 | } 30 | 31 | void st_mean_t::init(const traceinfo_t* inti, traceinfo_t* outti) 32 | { 33 | pimpl.get()->mean.init(inti, nullptr); 34 | outti->nsamples = 0; // return nothing 35 | } 36 | const trace_t* st_mean_t::process(const trace_t* trace) 37 | { 38 | pimpl.get()->mean.trace_submit(trace); 39 | return nullptr; 40 | } 41 | double st_mean_t::get_mean(int group, int sample) 42 | { 43 | return pimpl.get()->mean.getmean(group, sample); 44 | } 45 | st_mean_t::~st_mean_t() 46 | {} 47 | -------------------------------------------------------------------------------- /src/LeakageModel.h: -------------------------------------------------------------------------------- 1 | // Copyright 2022 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | #include 17 | #include 18 | 19 | #include "Trace.h" 20 | 21 | class leakage_t { 22 | public: 23 | void init(uint32_t dist_count) { 24 | _values.resize(dist_count); 25 | } 26 | float *get_dist_values() { 27 | return _values.data(); 28 | } 29 | uint32_t get_dist_count() { 30 | return _values.size(); 31 | } 32 | protected: 33 | std::vector _values; 34 | }; 35 | 36 | struct winner_t { 37 | float best_corr; 38 | std::string winner_name; 39 | uint32_t model_dist_idx; 40 | }; 41 | 42 | class leakage_model_t { 43 | public: 44 | virtual void init(const traceinfo_t* ti, leakage_t** leakage) = 0; 45 | virtual void model_leakage(const uint8_t* data, leakage_t* leakage) = 0; 46 | virtual void pick_best(const trace_t* corr, std::vector& winners) = 0; 47 | }; -------------------------------------------------------------------------------- /src/FirstOrderTTestAnalysis.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | 16 | #include "Analysis.h" 17 | #include "PImpl.h" 18 | 19 | struct first_order_ttest_analysis_priv_t; 20 | 21 | class first_order_ttest_analysis_t : public analysis_t 22 | { 23 | public: 24 | struct is_sample_independent {}; 25 | 26 | first_order_ttest_analysis_t(); 27 | first_order_ttest_analysis_t(const first_order_ttest_analysis_t&); 28 | first_order_ttest_analysis_t(first_order_ttest_analysis_t&&); 29 | void init(const traceinfo_t *traceinfo, 30 | analysis_output_t* output, const analysis_opts_t& opts = {}); 31 | void trace_submit(const trace_t *trace); 32 | void finit(); 33 | ~first_order_ttest_analysis_t(); 34 | private: 35 | void calc_output(uint32_t outputtraces, trace_t *trace); 36 | void var_output(uint32_t outputtraces, trace_t *trace, int group); 37 | 38 | PImpl pimpl; 39 | }; 40 | -------------------------------------------------------------------------------- /thirdparty/progress/progress.c: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #include "progress.h" 15 | #include 16 | 17 | void progress_init(progress_t* pg, unsigned long max) 18 | { 19 | pg->perc = 0; 20 | pg->perc_incr = 1; 21 | if (max < 10000) 22 | { 23 | pg->last = 1; 24 | pg->mod = 1; 25 | pg->perc_incr = 10000 / max; 26 | } 27 | else 28 | { 29 | pg->last = max / 10000; 30 | pg->mod = max / 10000; 31 | } 32 | printf("[ 0.00%%]"); 33 | fflush(stdout); 34 | } 35 | void progress_update(progress_t* pg, unsigned long current) 36 | { 37 | if (current >= pg->last) 38 | { 39 | pg->perc += pg->perc_incr; 40 | 41 | printf("\r[%3d.%2d%%]", pg->perc / 100, pg->perc % 100); 42 | 43 | fflush(stdout); 44 | pg->last += pg->mod; 45 | } 46 | } 47 | void progress_finit(progress_t* pg) 48 | { 49 | printf("\r[100.00%%]\n"); 50 | fflush(stdout); 51 | } 52 | -------------------------------------------------------------------------------- /src/SecondOrderTTestAnalysis.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | 16 | #include "Analysis.h" 17 | #include "PImpl.h" 18 | 19 | struct second_order_ttest_analysis_priv_t; 20 | 21 | class second_order_ttest_analysis_t : public analysis_t 22 | { 23 | public: 24 | struct is_sample_independent {}; 25 | 26 | second_order_ttest_analysis_t(); 27 | second_order_ttest_analysis_t(const second_order_ttest_analysis_t&); 28 | second_order_ttest_analysis_t(second_order_ttest_analysis_t&&); 29 | void init(const traceinfo_t *traceinfo, 30 | analysis_output_t* output, const analysis_opts_t& opts = {}); 31 | void trace_submit(const trace_t *trace); 32 | void finit(); 33 | ~second_order_ttest_analysis_t(); 34 | private: 35 | void calc_output(uint32_t outputtraces, trace_t *trace); 36 | void var_output(uint32_t outputtraces, trace_t *trace, int group); 37 | 38 | PImpl pimpl; 39 | }; 40 | -------------------------------------------------------------------------------- /src/Log.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | 16 | #include "Util.h" 17 | #include 18 | #include 19 | extern int __pw_log_verbosity; 20 | extern int __pw_log_fd; 21 | #define LOG_STAT_TIME 22 | #define LOG_STAT_TIME_STR "time" 23 | #define LOG_STAT_MEM 24 | #define LOG_STAT_MEM_STR "mem" 25 | #define LOG_STAT_INTL 26 | #define LOG_STAT_INTL_STR "intl" 27 | 28 | #define LogStat(__stat, ...) \ 29 | { \ 30 | dprintf(__pw_log_fd, __stat##_STR ": " __VA_ARGS__); \ 31 | } 32 | #define LogInfo(...) \ 33 | dprintf(__pw_log_fd, "info: " __VA_ARGS__) 34 | #define LogInfoV(__verb, ...) \ 35 | { \ 36 | if (__pw_log_verbosity > __verb) \ 37 | dprintf(__pw_log_fd, "info: " __VA_ARGS__); \ 38 | } 39 | #define LogErr(...) \ 40 | dprintf(__pw_log_fd, "err: " __VA_ARGS__) 41 | #define LogErrDie(...) \ 42 | { \ 43 | dprintf(__pw_log_fd, "err: " __VA_ARGS__);\ 44 | fsync(__pw_log_fd); \ 45 | abort(); \ 46 | } 47 | 48 | CAPI void pwlog_set_verbosity(int verbosity); 49 | CAPI void pwlog_set_fd(int fd); 50 | -------------------------------------------------------------------------------- /src/Trace.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #include "Trace.h" 15 | #include "Log.h" 16 | 17 | std::string __traceopt_empty=""; 18 | 19 | const std::string& traceopt_empty() 20 | { 21 | return __traceopt_empty; 22 | } 23 | bool traceopt_has_key(const std::vector& opts, const std::string& key) 24 | { 25 | for (auto opt: opts) 26 | { 27 | if (opt.key == key) 28 | { 29 | return true; 30 | } 31 | } 32 | return false; 33 | } 34 | const std::string& traceopt_get_value(const std::vector& opts, const std::string& key) 35 | { 36 | for (auto& opt: opts) 37 | { 38 | if (opt.key == key) 39 | { 40 | return opt.value; 41 | } 42 | } 43 | return traceopt_empty(); 44 | } 45 | 46 | void traceinfo_print(const char* msg, const traceinfo_t* traceinfo) 47 | { 48 | LogInfo("%s t:%s,ns:%d,nt:%d,terms:%d,nd:%d\n", msg, traceinfo->title.c_str(), 49 | traceinfo->nsamples, 50 | traceinfo->ntraces, 51 | traceinfo->nterms, 52 | traceinfo->ndata 53 | ); 54 | } 55 | -------------------------------------------------------------------------------- /src/SafeQueue.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | template 21 | class SafeQueue 22 | { 23 | public: 24 | SafeQueue(void) 25 | : q() 26 | , m() 27 | , c() 28 | {} 29 | 30 | ~SafeQueue(void) 31 | {} 32 | 33 | // Add an element to the queue. 34 | void push(T t) 35 | { 36 | std::lock_guard lock(m); 37 | q.push(t); 38 | c.notify_one(); 39 | } 40 | 41 | // Get the "front"-element. 42 | // If the queue is empty, wait till a element is avaiable. 43 | T pop(void) 44 | { 45 | std::unique_lock lock(m); 46 | while(q.empty()) 47 | { 48 | // release lock as long as the wait and reaquire it afterwards. 49 | c.wait(lock); 50 | } 51 | T val = q.front(); 52 | q.pop(); 53 | return val; 54 | } 55 | 56 | bool isempty() 57 | { 58 | std::unique_lock lock(m); 59 | return q.empty(); 60 | } 61 | 62 | private: 63 | std::queue q; 64 | mutable std::mutex m; 65 | std::condition_variable c; 66 | }; 67 | -------------------------------------------------------------------------------- /src/Vec2.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | #include 16 | template 17 | class Vec2 18 | { 19 | public: 20 | Vec2() : 21 | _data(nullptr) 22 | {} 23 | Vec2(const Vec2& other) 24 | { 25 | _data = new T[other._nrows*other._ncols]; 26 | for (size_t i=0;i 16 | #include 17 | #include 18 | #include "Log.h" 19 | 20 | 21 | template 22 | class allocator_t 23 | { 24 | public: 25 | static allocator_t* get_instance(); 26 | 27 | T* allocate(int arraycount) 28 | { 29 | auto mm = freelist.find(arraycount); 30 | if (mm != freelist.end() && mm->second.size() > 0) 31 | { 32 | alloc_header_t* val = mm->second.back(); 33 | T* ret = (T*) (&val[1]); 34 | mm->second.pop_back(); 35 | return ret; 36 | } 37 | else 38 | { 39 | alloc_header_t* headerptr = (alloc_header_t*) malloc(sizeof(alloc_header_t) + sizeof(T)*arraycount); 40 | headerptr->length = arraycount; 41 | return (T*) (&headerptr[1]); 42 | } 43 | } 44 | void deallocate(T* t) 45 | { 46 | alloc_header_t* headerptr = (alloc_header_t*) t; 47 | headerptr = headerptr - 1; 48 | 49 | freelist[headerptr->length].push_front( headerptr ); 50 | } 51 | private: 52 | struct alloc_header_t 53 | { 54 | int length; 55 | }; 56 | std::map> freelist; 57 | }; 58 | -------------------------------------------------------------------------------- /src/IPWLeakageModel.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | #include "PWLeakageParams.h" 16 | #include "Log.h" 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | typedef struct _pwaccessor_i pwaccessor_i; 23 | 24 | struct _pwleakage_model_i 25 | { 26 | virtual void pwleakage_init(int nototaltraces) = 0; 27 | virtual void pwleakage_set_param(pwleakage_model_param param, int value) {} 28 | virtual void pwleakage_set_param(pwleakage_model_param param, const char* value) {} 29 | virtual void pwleakage_set_leaky_indexes(int* leakyindexes, int leakyindexescount) { LogErrDie("set leaky indexes not implemented\n"); } 30 | virtual void pwleakage_on_trace_done(double* samples, uint32_t samplecount) = 0; 31 | virtual _pwleakage_model_i* pwleakage_merge(_pwleakage_model_i* dest) { LogErrDie("merge not implemented\n"); return nullptr; } 32 | virtual uint32_t pwleakage_get_output_size() = 0; 33 | virtual double pwleakage_get_output_at(uint32_t index) = 0; 34 | virtual void pwleakage_get_internals_size(uint32_t* nrows, uint32_t* ncols) { *nrows = 0; *ncols = 0; } 35 | virtual void pwleakage_get_internals_at(uint32_t row_idx, double* row) {} 36 | virtual void pwleakage_finit() = 0; 37 | virtual ~_pwleakage_model_i() {} 38 | }; 39 | -------------------------------------------------------------------------------- /src/BivAnalysisMt.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | #include 16 | 17 | #include "Analysis.h" 18 | #include "Trace.h" 19 | #include "PImpl.h" 20 | 21 | struct biv_analysis_mt_priv_t ; 22 | 23 | class biv_analysis_mt_t : public analysis_t 24 | { 25 | public: 26 | 27 | template 28 | void init_threaded(int nsplits) 29 | { 30 | typename AnalysisT::is_sample_independent{}; 31 | _nsplits = nsplits; 32 | 33 | _make_analysis = []() { return new AnalysisT(); }; 34 | _make_analysis_output = []() { return new AnalysisOutputT(); }; 35 | 36 | } 37 | biv_analysis_mt_t(); 38 | biv_analysis_mt_t(const biv_analysis_mt_t&); 39 | biv_analysis_mt_t(biv_analysis_mt_t&&); 40 | void init(const traceinfo_t* traceinfo, 41 | analysis_output_t* output, 42 | const analysis_opts_t& opts = {}) override; 43 | void trace_submit(const trace_t *trace) override; 44 | void finit() override; 45 | ~biv_analysis_mt_t(); 46 | private: 47 | std::function _make_analysis; 48 | std::function _make_analysis_output; 49 | int _nsplits; 50 | int _nt; 51 | 52 | PImpl pimpl; 53 | }; 54 | -------------------------------------------------------------------------------- /src/FileProcessor.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | #include 16 | #include 17 | 18 | #include "CmdPipeline.h" 19 | #include "Trace.h" 20 | #include "PImpl.h" 21 | 22 | struct file_processor_priv_t; 23 | class file_processor_t 24 | { 25 | public: 26 | typedef std::function preprocess_func_t; 27 | struct range_t 28 | { 29 | size_t samplewinstart; 30 | size_t samplewinlen; 31 | size_t tracerangestart; 32 | size_t tracerangelen; 33 | 34 | range_t(): 35 | samplewinstart(0) 36 | ,samplewinlen(0) 37 | ,tracerangestart(0) 38 | ,tracerangelen(0) 39 | {} 40 | }; 41 | file_processor_t(); 42 | void init(cmd_pipeline_t* cp, const std::string& filename, range_t* range=nullptr); 43 | const traceinfo_t* get_file_traceinfo(); 44 | void process_window(size_t samplewinstart, size_t samplewinlen); 45 | void process_range(const range_t& range); 46 | void process_window(size_t samplewinstart, size_t samplewinlen, preprocess_func_t func); 47 | void process_all(); 48 | void process_all(preprocess_func_t func); 49 | void finit(); 50 | 51 | ~file_processor_t(); 52 | private: 53 | PImpl pimpl; 54 | }; 55 | -------------------------------------------------------------------------------- /thirdparty/tracewriter/tracewriter.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | #include 16 | #include 17 | 18 | #include "tracewriter_config.h" 19 | 20 | struct TraceWriter 21 | { 22 | FILE* file; 23 | void* impl; 24 | int fd; 25 | ssize_t size; 26 | }; 27 | 28 | //#define TW_FMT_F32 0 29 | //#define TW_FMT_I16 1 30 | 31 | #define TW_P_FMT 0 32 | #define TW_P_SAMPLES_PER_CAP 1 33 | #define TW_P_CAPS_PER_ROUND 2 34 | #define TW_P_ROUNDS 3 35 | #define TW_P_FRAC_NUM 4 36 | #define TW_P_FRAC_DENO 5 37 | 38 | #define TW_M_NEW 0 39 | #define TW_M_CONT 1 40 | #define TW_M_READ 2 41 | 42 | #if defined(TW_FMT_F32) 43 | #define TW_FMT 0 44 | typedef float tw_t; 45 | #elif defined(TW_FMT_I16) 46 | #define TW_FMT 1 47 | typedef int16_t tw_t; 48 | #else 49 | #error "unsupported format" 50 | #endif 51 | #ifdef __cplusplus 52 | extern "C" { 53 | #endif 54 | void tw_open(struct TraceWriter* tw, const char* file, int mode); 55 | void tw_get_property(struct TraceWriter* tw, int prop, uint32_t* value); 56 | void tw_set_property(struct TraceWriter* tw, int prop, uint32_t value); 57 | ssize_t tw_read_samples(struct TraceWriter* tw, tw_t** samples); 58 | ssize_t tw_write_samples(struct TraceWriter* tw, tw_t* samples, int count); 59 | void tw_close(struct TraceWriter* tw); 60 | #ifdef __cplusplus 61 | } 62 | #endif 63 | -------------------------------------------------------------------------------- /src/WorkContext.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | #include 16 | #include 17 | #include 18 | 19 | #include "Log.h" 20 | #include "Variant.h" 21 | 22 | typedef std::map wc_gopts_t; 23 | 24 | void wc_gopts_merge(const wc_gopts_t& opts); 25 | 26 | const variant_t& wc_gopts_get(const std::string& key); 27 | 28 | bool wc_gopts_has(const std::string& key); 29 | 30 | const variant_t& wc_gopts_get(const std::string& key, const variant_t& defaultvar); 31 | 32 | std::string wc_output_dir(); 33 | 34 | class wc_path_gen_t 35 | { 36 | public: 37 | wc_path_gen_t(const std::string& title) 38 | { 39 | std::string outdir = wc_output_dir(); 40 | if (outdir != "") 41 | { 42 | _ss << outdir << "/" << title; 43 | } 44 | else 45 | { 46 | _ss << title; 47 | } 48 | } 49 | template 50 | void add(T t) 51 | { 52 | _ss << "-" < 56 | void add(T t, Args... args) 57 | { 58 | _ss << "-" <* __g_thread_instance_dbl = nullptr; 17 | thread_local allocator_t* __g_thread_instance_st = nullptr; 18 | thread_local allocator_t* __g_thread_instance_u8 = nullptr; 19 | thread_local allocator_t* __g_thread_instance_trc = nullptr; 20 | 21 | template<> 22 | allocator_t* allocator_t::get_instance() 23 | { 24 | if (__g_thread_instance_dbl == nullptr) 25 | { 26 | __g_thread_instance_dbl = new allocator_t(); 27 | } 28 | return __g_thread_instance_dbl; 29 | } 30 | template<> 31 | allocator_t* allocator_t::get_instance() 32 | { 33 | if (__g_thread_instance_st == nullptr) 34 | { 35 | __g_thread_instance_st = new allocator_t(); 36 | } 37 | return __g_thread_instance_st; 38 | } 39 | template<> 40 | allocator_t* allocator_t::get_instance() 41 | { 42 | if (__g_thread_instance_u8 == nullptr) 43 | { 44 | __g_thread_instance_u8 = new allocator_t(); 45 | } 46 | return __g_thread_instance_u8; 47 | } 48 | template<> 49 | allocator_t* allocator_t::get_instance() 50 | { 51 | if (__g_thread_instance_trc == nullptr) 52 | { 53 | __g_thread_instance_trc = new allocator_t(); 54 | } 55 | return __g_thread_instance_trc; 56 | } 57 | -------------------------------------------------------------------------------- /src/StCorr.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #include "StCorr.h" 15 | #include "CorrAnalysis.h" 16 | #include "AnalysisOuput.h" 17 | #include "Log.h" 18 | #include "Trace.h" 19 | #include "Variant.h" 20 | #include "WorkContext.h" 21 | #include "PWFactory.h" 22 | #include "TraceReader.h" 23 | #include "MeanAnalysis.h" 24 | #include "Passes.h" 25 | 26 | #include 27 | #include 28 | 29 | struct st_corr_priv_t 30 | { 31 | corr_analysis_t corr; 32 | analysis_output_t ao; 33 | traceinfo_t traceinfo; 34 | }; 35 | 36 | st_corr_t::st_corr_t() 37 | { 38 | pimpl.init(); 39 | } 40 | void st_corr_t::init(const traceinfo_t* inti, traceinfo_t* outti) 41 | { 42 | pimpl.get()->traceinfo = *inti; 43 | std::string outfilepath = wc_generate_path(inti->title.c_str(), "corr.npy"); 44 | pimpl.get()->ao.init(outfilepath.c_str(), "numpy"); 45 | pimpl.get()->corr.init(inti, &pimpl.get()->ao); 46 | 47 | traceinfo_print("", inti); 48 | } 49 | 50 | const trace_t* st_corr_t::process(const trace_t* trace) 51 | { 52 | auto p = pimpl.get(); 53 | trace_t tempout(&trace->_traceinfo); 54 | trace->copyto(&tempout, 0); 55 | pwpass_moving_average(&tempout); 56 | 57 | pimpl.get()->corr.trace_submit(&tempout); 58 | 59 | return trace; 60 | } 61 | void st_corr_t::finit() 62 | { 63 | auto p = pimpl.get(); 64 | 65 | pimpl.get()->corr.finit(); 66 | } 67 | st_corr_t::~st_corr_t() 68 | { 69 | } 70 | -------------------------------------------------------------------------------- /src/CpStack.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #include "CpStack.h" 15 | #include "Trace.h" 16 | void cp_stack_t::get_info(cmd_pipeline_info_t& info) 17 | { 18 | info.passes_count = _passes; 19 | } 20 | 21 | void cp_stack_t::init(const traceinfo_t *traceinfo, pwtermset_mode_t mode) 22 | { 23 | for (auto i=0u;i<_passes;i++) 24 | { 25 | auto& stacks = _multistack[i]; 26 | traceinfo_t inti, outti; 27 | inti = *traceinfo; 28 | for (auto& st : stacks) 29 | { 30 | st->init(&inti, &outti); 31 | inti = outti; 32 | } 33 | } 34 | } 35 | void cp_stack_t::stack_add(stackable_t* cp, int pass) 36 | { 37 | if (pass >= (int)_multistack.size()) 38 | { 39 | _multistack.resize(pass*2+32); 40 | } 41 | _passes = std::max(_passes, pass+1); 42 | _multistack[pass].push_back(cp); 43 | } 44 | 45 | void cp_stack_t::pass_begin(int pass) 46 | { 47 | _current_pass = pass; 48 | } 49 | void cp_stack_t::process(const trace_t* trace) 50 | { 51 | auto& stacks = _multistack[_current_pass]; 52 | for (auto& st : stacks) 53 | { 54 | trace = st->process(trace); 55 | } 56 | } 57 | void cp_stack_t::pass_end(int pass) 58 | {} 59 | void cp_stack_t::finit() 60 | { 61 | for (auto i=0u;i<_passes;i++) 62 | { 63 | auto& stacks = _multistack[i]; 64 | for (auto& st : stacks) 65 | { 66 | st->finit(); 67 | } 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /include/PWModel.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | #include "Util.h" 16 | 17 | #include 18 | 19 | typedef struct _pwmodel_i pwmodel_i; 20 | 21 | typedef struct _pwmodel_input 22 | { 23 | uint32_t op1; 24 | uint32_t op2; 25 | uint16_t reg_op1; 26 | uint16_t reg_op2; 27 | uint32_t inst_id; 28 | uint32_t result; 29 | uint64_t pc; 30 | void* privateptr; 31 | struct _pwmodel_input* next; 32 | } pwmodel_input_t; 33 | 34 | typedef struct _pwmodel 35 | { 36 | pwmodel_input_t* codesegment_start; 37 | pwmodel_input_t* codesegment_current; 38 | pwmodel_i* model; 39 | uint64_t startpc; 40 | uint64_t endpc; 41 | uint32_t currenttrace; 42 | uint32_t nsamples; 43 | uint32_t nsamples_first; 44 | uint32_t ndata_first; 45 | uint8_t* inputdata; 46 | uint32_t inputdatalength; 47 | } pwmodel_t; 48 | 49 | CAPI pwmodel_i* pwmodel_get_model(const char* modelname); 50 | CAPI void pwmodel_init(pwmodel_t**, const char* execfile); 51 | CAPI void pwmodel_update(pwmodel_t*, pwmodel_input_t*); 52 | CAPI void pwmodel_begin(pwmodel_t*, uint64_t pc); 53 | CAPI void pwmodel_end(pwmodel_t*, uint64_t pc); 54 | CAPI void pwmodel_dump(pwmodel_t*); 55 | CAPI void pwmodel_update_inputdata(pwmodel_t*, uint8_t* inputdata, uint32_t length); 56 | // read only after pwmodel_end is called for first trace and after 57 | // i.e. pwodel_i::on_trace_done 58 | CAPI uint32_t pwmodel_get_sample_count(pwmodel_t*); 59 | CAPI void pwmodel_finit(pwmodel_t*); 60 | -------------------------------------------------------------------------------- /src/StFott.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #include 15 | 16 | #include "Trace.h" 17 | #include "StFott.h" 18 | #include "FirstOrderTTestAnalysis.h" 19 | #include "AnalysisOuput.h" 20 | #include "PWFactory.h" 21 | #include "TraceUtils.h" 22 | #include "Passes.h" 23 | 24 | struct st_fott_priv_t 25 | { 26 | analysis_output_t aos; 27 | analysis_t* fottests; 28 | traceinfo_t traceinfo; 29 | pwtermset_mode_t mode; 30 | }; 31 | 32 | st_fott_t::st_fott_t() 33 | { 34 | pimpl.init(); 35 | } 36 | void st_fott_t::init(const traceinfo_t* inti, traceinfo_t* outti) 37 | { 38 | auto p = pimpl.get(); 39 | p->traceinfo = *inti; 40 | traceinfo_print("dddd", inti); 41 | outti->nsamples = 0; 42 | 43 | std::vector outfilepath(255); 44 | snprintf(outfilepath.data(), 254, "%s-st-fottest.npy", inti->title.c_str()); 45 | p->fottests = pwfactory_t::get_instance()->new_analysis("first-order-ttest"); 46 | p->aos.init(outfilepath.data(), "numpy"); 47 | 48 | p->fottests->init(inti, &p->aos); 49 | } 50 | const trace_t* st_fott_t::process(const trace_t* trace) 51 | { 52 | auto p = pimpl.get(); 53 | //LogInfo("dd%x\n",trace->_data[0]); 54 | pwpass_moving_average(const_cast(trace)); 55 | p->fottests->trace_submit(trace); 56 | return nullptr; 57 | } 58 | void st_fott_t::finit() 59 | { 60 | auto p = pimpl.get(); 61 | 62 | p->fottests->finit(); 63 | } 64 | st_fott_t::~st_fott_t() 65 | { 66 | } 67 | -------------------------------------------------------------------------------- /src/StChisq.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #include 15 | 16 | #include "Trace.h" 17 | #include "StChisq.h" 18 | #include "FirstOrderTTestAnalysis.h" 19 | #include "AnalysisOuput.h" 20 | #include "PWFactory.h" 21 | #include "TraceUtils.h" 22 | #include "Passes.h" 23 | 24 | struct st_chisq_priv_t 25 | { 26 | analysis_output_t aos; 27 | analysis_t* chisqests; 28 | traceinfo_t traceinfo; 29 | pwtermset_mode_t mode; 30 | }; 31 | 32 | st_chisq_t::st_chisq_t() 33 | { 34 | pimpl.init(); 35 | } 36 | void st_chisq_t::init(const traceinfo_t* inti, traceinfo_t* outti) 37 | { 38 | auto p = pimpl.get(); 39 | p->traceinfo = *inti; 40 | traceinfo_print("dddd", inti); 41 | outti->nsamples = 0; 42 | 43 | std::vector outfilepath(255); 44 | snprintf(outfilepath.data(), 254, "%s-st-chisq.npy", inti->title.c_str()); 45 | p->chisqests = pwfactory_t::get_instance()->new_analysis("chisquare"); 46 | p->aos.init(outfilepath.data(), "numpy"); 47 | 48 | p->chisqests->init(inti, &p->aos); 49 | } 50 | const trace_t* st_chisq_t::process(const trace_t* trace) 51 | { 52 | auto p = pimpl.get(); 53 | //LogInfo("dd%x\n",trace->_data[0]); 54 | pwpass_moving_average(const_cast(trace)); 55 | p->chisqests->trace_submit(trace); 56 | return nullptr; 57 | } 58 | void st_chisq_t::finit() 59 | { 60 | auto p = pimpl.get(); 61 | 62 | p->chisqests->finit(); 63 | } 64 | st_chisq_t::~st_chisq_t() 65 | { 66 | } 67 | -------------------------------------------------------------------------------- /src/PWConfig.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #include "PWConfig.h" 15 | #include "Log.h" 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #define CFG_FILE "./pwconfig.conf" 22 | static std::map confmap; 23 | static bool loaded=false; 24 | void pwconfig_init() 25 | { 26 | std::ifstream conf(CFG_FILE,std::ifstream::in); 27 | LogInfo("config from file\n"); 28 | while (!conf.eof()) 29 | { 30 | std::string key, val; 31 | conf >> key >> std::ws>> val >>std::ws; 32 | LogInfo("%s=%s\n", key.c_str(), val.c_str()); 33 | confmap.insert({key, val}); 34 | } 35 | loaded = true; 36 | } 37 | void pwconfig_set_value(const char* key, const char* value) 38 | { 39 | std::string strkey(key); 40 | std::string strval(value); 41 | 42 | confmap.insert( {strkey, strval} ); 43 | LogInfo("config %s=%s\n", key, value); 44 | loaded = true; 45 | } 46 | const char* pwconfig_get_value(const char* key) 47 | { 48 | if (!loaded) 49 | { 50 | pwconfig_init(); 51 | } 52 | std::string strkey(key); 53 | if (confmap.find(strkey) != confmap.end()) 54 | { 55 | return confmap[strkey].c_str(); 56 | } 57 | return nullptr; 58 | } 59 | 60 | int pwconfig_get_value_int(const char* key) 61 | { 62 | const char* val = pwconfig_get_value(key); 63 | if (val == nullptr) 64 | { 65 | return -1; 66 | } 67 | return atoi(val); 68 | } 69 | 70 | void pwconfig_finit() 71 | { 72 | } 73 | -------------------------------------------------------------------------------- /src/CpConvert.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #include "CpConvert.h" 15 | 16 | #include "Passes.h" 17 | #include "AnalysisOuput.h" 18 | #include "WorkContext.h" 19 | #include "PWFactory.h" 20 | #include "TraceWriter.h" 21 | #include "Passes.h" 22 | struct cp_convert_priv_t 23 | { 24 | tracewriter_t* writer; 25 | traceinfo_t traceinfo; 26 | traceinfo_t wti; 27 | }; 28 | cp_convert_t::cp_convert_t() 29 | { 30 | pimpl.init(); 31 | } 32 | void cp_convert_t::init(const traceinfo_t *traceinfo, pwtermset_mode_t mode) 33 | { 34 | wc_path_gen_t pathgen(traceinfo->title); 35 | pathgen.add("conv"); 36 | std::string target = wc_gopts_get("convert_to").get_string(); 37 | pimpl.get()->writer = pwfactory_t::get_instance()->new_tracewriter(target); 38 | std::string targetext("."); 39 | targetext += target; 40 | 41 | pimpl.get()->writer->open_file(pathgen.getpath(targetext).c_str(), traceinfo, {}); 42 | pimpl.get()->traceinfo = *traceinfo; 43 | pimpl.get()->wti = *traceinfo; 44 | pimpl.get()->wti.ntraces = 0; 45 | 46 | traceinfo_print("", traceinfo); 47 | } 48 | 49 | void cp_convert_t::init(const char* filename) 50 | { 51 | } 52 | void cp_convert_t::process() 53 | { 54 | 55 | } 56 | void cp_convert_t::process(const trace_t* trace) 57 | { 58 | pwpass_moving_average(const_cast(trace)); 59 | pimpl.get()->writer->write_trace(trace); 60 | pimpl.get()->wti.ntraces++; 61 | } 62 | void cp_convert_t::finit() 63 | { 64 | pimpl.get()->writer->finit(&pimpl.get()->wti); 65 | } 66 | cp_convert_t::~cp_convert_t() 67 | {} 68 | -------------------------------------------------------------------------------- /src/TraceUtils.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | #include "Log.h" 16 | #include "Trace.h" 17 | extern int __pwtraceutils_data_groups; 18 | 19 | /* get trace group: only on standard traces that 20 | * have set the first data byte to the group */ 21 | inline int traceutils_group(const trace_t* trace) 22 | { 23 | if (__pwtraceutils_data_groups > 1) 24 | { 25 | return (int) trace->_data[0]; 26 | } 27 | else if (__pwtraceutils_data_groups == -1) 28 | { 29 | LogErrDie("data group count not initialized\n"); 30 | } 31 | return 0; 32 | } 33 | 34 | int traceutils_groups_count(); 35 | 36 | /* extract a given term from a trace */ 37 | void traceutils_extract_term(const trace_t* trace, trace_t *termtrace, uint32_t term_id, 38 | const traceinfo_t* traceinfo, const traceinfo_t* termtraceinfo); 39 | /* combine bivariate */ 40 | uint32_t traceutils_biv_combine(const trace_t *trace, trace_t *combinedtrace, 41 | const traceinfo_t* traceinfo, const traceinfo_t* combinedtraceinfo); 42 | /* combine bivariate two halves */ 43 | uint32_t traceutils_biv_combine2h(const trace_t *trace, trace_t *combinedtrace, 44 | const traceinfo_t* traceinfo, const traceinfo_t* combinedtraceinfo); 45 | /* combine trivariate */ 46 | uint32_t traceutils_triv_combine(const trace_t *trace, trace_t *combinedtrace, 47 | const traceinfo_t* traceinfo, const traceinfo_t* combinedtraceinfo); 48 | 49 | /* a = a - b */ 50 | void traceutils_diff(trace_t* a, trace_t* b); 51 | -------------------------------------------------------------------------------- /src/CpFileUnivFirstOrderTTest.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #include 15 | 16 | #include "Trace.h" 17 | #include "CpFileUnivFirstOrderTTest.h" 18 | #include "FirstOrderTTestAnalysis.h" 19 | #include "AnalysisOuput.h" 20 | #include "PWFactory.h" 21 | #include "TraceUtils.h" 22 | #include "Passes.h" 23 | 24 | struct cp_file_univ_first_order_ttest_priv_t 25 | { 26 | analysis_output_t aos; 27 | analysis_t* fottests; 28 | traceinfo_t traceinfo; 29 | pwtermset_mode_t mode; 30 | }; 31 | 32 | cp_file_univ_first_order_ttest_t::cp_file_univ_first_order_ttest_t() 33 | { 34 | pimpl.init(); 35 | } 36 | void cp_file_univ_first_order_ttest_t::init(const traceinfo_t *traceinfo, pwtermset_mode_t mode) 37 | { 38 | auto p = pimpl.get(); 39 | p->mode = mode; 40 | p->traceinfo = *traceinfo; 41 | p->mode = mode; 42 | 43 | std::vector outfilepath(255); 44 | snprintf(outfilepath.data(), 254, "%s-univ-fottest.npy", traceinfo->title.c_str()); 45 | p->fottests = pwfactory_t::get_instance()->new_analysis("first-order-ttest"); 46 | p->aos.init(outfilepath.data(), "numpy"); 47 | p->fottests->init(traceinfo, &p->aos); 48 | } 49 | void cp_file_univ_first_order_ttest_t::process(const trace_t* trace) 50 | { 51 | auto p = pimpl.get(); 52 | pwpass_moving_average(const_cast(trace)); 53 | p->fottests->trace_submit(trace); 54 | } 55 | void cp_file_univ_first_order_ttest_t::finit() 56 | { 57 | auto p = pimpl.get(); 58 | 59 | p->fottests->finit(); 60 | } 61 | cp_file_univ_first_order_ttest_t::~cp_file_univ_first_order_ttest_t() 62 | { 63 | } 64 | -------------------------------------------------------------------------------- /src/StNorm.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #include "StNorm.h" 15 | #include "MeanAnalysis.h" 16 | #include "AnalysisOuput.h" 17 | #include "StMean.h" 18 | #include "Trace.h" 19 | #include "TraceUtils.h" 20 | #include "WorkContext.h" 21 | #include "PWFactory.h" 22 | #include "TraceReader.h" 23 | struct st_norm_priv_t 24 | { 25 | st_mean_t* prerunmeans; 26 | traceinfo_t traceinfo; 27 | traceinfo_t winti; 28 | trace_t outtrace; 29 | }; 30 | st_norm_t::st_norm_t(st_mean_t* prerunmeans) 31 | { 32 | pimpl.init(); 33 | pimpl.get()->prerunmeans = prerunmeans; 34 | } 35 | 36 | 37 | static void copydata(const trace_t *fromtrace, const traceinfo_t *fromti, 38 | trace_t *totrace, const traceinfo_t *toti) 39 | { 40 | if (fromti->ndata > 0) 41 | { 42 | if (fromti->ndata == toti->ndata) 43 | { 44 | memcpy(&totrace->_data[0], &fromtrace->_data[0], toti->ndata * sizeof(uint8_t)); 45 | } 46 | else 47 | { 48 | LogErrDie("Can't copy data due to data buffer size mismatch!\n"); 49 | } 50 | } 51 | } 52 | 53 | void st_norm_t::init(const traceinfo_t* inti, traceinfo_t* outti) 54 | { 55 | pimpl.get()->traceinfo = *inti; 56 | *outti = *inti; 57 | } 58 | const trace_t* st_norm_t::process(const trace_t* trace) 59 | { 60 | auto p = pimpl.get(); 61 | p->outtrace.~trace_t(); 62 | new (&p->outtrace) trace_t(); 63 | p->outtrace.init(&p->traceinfo); 64 | int g = traceutils_group(trace); 65 | for (auto i=0u;itraceinfo.nsamples;i++) 66 | { 67 | p->outtrace._samples[i] = trace->_samples[i] - p->prerunmeans->get_mean(g, i); 68 | } 69 | copydata(trace, &pimpl.get()->traceinfo, &p->outtrace, &pimpl.get()->traceinfo); 70 | return &p->outtrace; 71 | } 72 | st_norm_t::~st_norm_t() 73 | {} 74 | -------------------------------------------------------------------------------- /src/CpCompress.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #include "CpCompress.h" 15 | #include "Variant.h" 16 | #include "WorkContext.h" 17 | #include "PWFactory.h" 18 | #include "TraceReader.h" 19 | #include "TraceWriter.h" 20 | #include "Passes.h" 21 | #include 22 | #include 23 | 24 | struct cp_compress_priv_t 25 | { 26 | std::string ext; 27 | std::string filename; 28 | tracewriter_t* writer; 29 | traceinfo_t rti; 30 | traceinfo_t wti; 31 | wc_gopts_t opts_map; 32 | int datarange_begin; 33 | int datarange_end; 34 | }; 35 | 36 | cp_compress_t::cp_compress_t() 37 | { 38 | pimpl.init(); 39 | } 40 | void cp_compress_t::init(const traceinfo_t *traceinfo, pwtermset_mode_t mode) 41 | { 42 | std::stringstream ssaofile; 43 | ssaofile<<"compressed.npy"; 44 | 45 | std::string outfilepath = wc_generate_path(traceinfo->title.c_str(), ssaofile.str().c_str()); 46 | pimpl.get()->writer = pwfactory_t::get_instance()->new_tracewriter("npy"); 47 | pimpl.get()->rti = *traceinfo; 48 | pimpl.get()->wti = *traceinfo; 49 | pimpl.get()->wti.nsamples = traceinfo->nsamples * traceinfo->nterms / 10; 50 | 51 | pimpl.get()->writer->open_file(outfilepath.data(), &pimpl.get()->wti, {{"numpy",""}}); 52 | traceinfo_print("", traceinfo); 53 | } 54 | 55 | void cp_compress_t::init(const char* filename) 56 | { 57 | } 58 | void cp_compress_t::process() 59 | { 60 | } 61 | void cp_compress_t::process(const trace_t* trace) 62 | { 63 | auto p = pimpl.get(); 64 | trace_t wtrace; 65 | wtrace.init_dataonly(trace->_data.getptr(), &p->wti); 66 | pwpass_compress(trace->_samples.getptr(), p->rti.nsamples * p->rti.nterms, 67 | wtrace._samples.getptr(), p->wti.nsamples , 15, 5); 68 | //wtrace.print(); 69 | p->writer->write_trace(&wtrace); 70 | } 71 | void cp_compress_t::finit() 72 | { 73 | pimpl.get()->writer->finit(nullptr); 74 | } 75 | cp_compress_t::~cp_compress_t() 76 | { 77 | } 78 | -------------------------------------------------------------------------------- /src/StTraceCombiner.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | #include "Trace.h" 16 | #include "Stackable.h" 17 | 18 | class trace_combiner_base_t 19 | { 20 | public: 21 | virtual traceinfo_t get_outtraceinfo() = 0; 22 | virtual void init_combined_trace(trace_t* trace) = 0; 23 | virtual void combine(const trace_t* intrace, trace_t* outtrace) = 0; 24 | virtual ~trace_combiner_base_t() {} 25 | }; 26 | 27 | template 28 | class trace_combiner_t : public trace_combiner_base_t 29 | { 30 | public: 31 | trace_combiner_t(const traceinfo_t* intraceinfo); 32 | traceinfo_t get_outtraceinfo() override; 33 | void init_combined_trace(trace_t* trace) override; 34 | void combine(const trace_t* intrace, trace_t* outtrace) override; 35 | private: 36 | traceinfo_t outti; 37 | traceinfo_t inti; 38 | }; 39 | 40 | template 41 | class trace_combiner_wind_t : public trace_combiner_base_t 42 | { 43 | public: 44 | trace_combiner_wind_t(const traceinfo_t* intraceinfo); 45 | traceinfo_t get_outtraceinfo() override; 46 | void init_combined_trace(trace_t* trace) override; 47 | void combine(const trace_t* intrace, trace_t* outtrace) override; 48 | private: 49 | traceinfo_t outti; 50 | traceinfo_t inti; 51 | }; 52 | 53 | 54 | template<> 55 | trace_combiner_t<1>::trace_combiner_t(const traceinfo_t* intraceinfo); 56 | template<> 57 | trace_combiner_t<2>::trace_combiner_t(const traceinfo_t* intraceinfo); 58 | template<> 59 | trace_combiner_t<3>::trace_combiner_t(const traceinfo_t* intraceinfo); 60 | 61 | template<> 62 | trace_combiner_wind_t<3>::trace_combiner_wind_t(const traceinfo_t* intraceinfo); 63 | 64 | 65 | class st_trace_combiner_t : public stackable_t 66 | { 67 | public: 68 | void init(const traceinfo_t* inti, traceinfo_t* outti); 69 | trace_t* process(const trace_t* trace); 70 | private: 71 | trace_t _outtrace; 72 | traceinfo_t _outti; 73 | traceinfo_t _inti; 74 | trace_combiner_base_t* _comb; 75 | }; 76 | -------------------------------------------------------------------------------- /src/Passes.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #include "Passes.h" 15 | #include "Util.h" 16 | #include "WorkContext.h" 17 | variant_t moving_avg_wind(0); 18 | 19 | void pwpass_update_properties() 20 | { 21 | moving_avg_wind = wc_gopts_get("moving_avg_wind", moving_avg_wind); 22 | } 23 | void pwpass_moving_average(trace_t *trace) 24 | { 25 | int windsamples = moving_avg_wind.get_int(); 26 | if (moving_avg_wind.get_int() == 0) 27 | return ; 28 | for (auto i=0u;i_traceinfo.nsamples - windsamples;i++) 29 | { 30 | double windsum = 0; 31 | for (auto j=i;j_samples[j]; 34 | } 35 | windsum /= windsamples; 36 | trace->_samples[i] = windsum; 37 | } 38 | 39 | } 40 | 41 | void pwpass_add_padding(const double* insamples, uint32_t nin, double* outsamples, 42 | uint32_t nout, uint16_t pad_amount, double pad_value) 43 | { 44 | PWASSERT(nout == 2*pad_amount + nin, "padding amount incompatible with traces"); 45 | for (uint32_t i=0;i\n 22 | * only 23 | ***/ 24 | 25 | bool pwdata_write_open(pwdatastream_t& pwd, const std::string& filename) 26 | { 27 | pwd.ofstream.open(filename); 28 | return pwd.ofstream.good(); 29 | } 30 | bool pwdata_read_open(pwdatastream_t& pwd, const std::string& filename, uint32_t& length) 31 | { 32 | pwd.ifstream.open(filename); 33 | if (pwd.ifstream.is_open() == false) 34 | { 35 | pwd.hasdata = false; 36 | return false; 37 | } 38 | std::string dataline; 39 | if (std::getline(pwd.ifstream, dataline).good()) 40 | { 41 | length = dataline.length()/2; 42 | pwd.length = length; 43 | pwd.ifstream.seekg(0, pwd.ifstream.beg); 44 | pwd.hasdata = true; 45 | return true; 46 | } 47 | else 48 | { 49 | pwd.hasdata = false; 50 | return false; 51 | } 52 | } 53 | void pwdata_read_data(pwdatastream_t& pwd, uint8_t* data, uint32_t length) 54 | { 55 | if (pwd.hasdata == false) 56 | return ; 57 | 58 | std::string dataline; 59 | 60 | if (std::getline(pwd.ifstream, dataline).good() == false) 61 | { 62 | LogErrDie("can not read data\n"); 63 | } 64 | 65 | PWASSERT(length * 2 == dataline.length(), "data file length mismatch"); 66 | 67 | hexstr_to_bytebuf(dataline.data(), data); 68 | 69 | } 70 | void pwdata_write_data(pwdatastream_t& pwd, uint8_t* data, uint32_t length) 71 | { 72 | 73 | } 74 | 75 | void pwdata_write_close(pwdatastream_t& pwd) 76 | { 77 | pwd.ofstream.close(); 78 | } 79 | void pwdata_read_close(pwdatastream_t& pwd) 80 | { 81 | pwd.ifstream.close(); 82 | } 83 | void pwdata_read_rewind(pwdatastream_t& pwd) 84 | { 85 | pwd.ifstream.seekg(std::ios::beg); 86 | } 87 | void pwdata_read_seek(pwdatastream_t& pwd, size_t traceid) 88 | { 89 | pwd.ifstream.seekg((pwd.length*2+1) * traceid, std::ios::beg); 90 | } 91 | -------------------------------------------------------------------------------- /src/PWArgs.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #include "PWArgs.h" 15 | #include "Log.h" 16 | #include 17 | #include 18 | #include 19 | #include 20 | static int pwargs_check(pwargs_t* arg, char* arg_val) 21 | { 22 | if (strcmp(arg->long_sw, arg_val) == 0) 23 | return 1; 24 | if (strcmp(arg->short_sw, arg_val) == 0) 25 | return 2; 26 | return 0; 27 | } 28 | 29 | void pwargs_print_options(pwargs_t *args, const char* longdescs[], int args_count) 30 | { 31 | int i=0; 32 | int j=0; 33 | while (i 1) 83 | { 84 | if (argv[1][0] != '-') 85 | *nosw_arg_start = 1; 86 | } 87 | } 88 | 89 | -------------------------------------------------------------------------------- /thirdparty/npy/npy.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #include "npy/npy.hpp" 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | namespace npy { 21 | constexpr dtype_t has_typestring::dtype; 22 | constexpr dtype_t has_typestring::dtype; 23 | constexpr dtype_t has_typestring::dtype; 24 | constexpr dtype_t has_typestring::dtype; 25 | constexpr dtype_t has_typestring::dtype; 26 | constexpr dtype_t has_typestring::dtype; 27 | constexpr dtype_t has_typestring::dtype; 28 | constexpr dtype_t has_typestring::dtype; 29 | constexpr dtype_t has_typestring::dtype; 30 | constexpr dtype_t has_typestring::dtype; 31 | constexpr dtype_t has_typestring::dtype; 32 | constexpr dtype_t has_typestring::dtype; 33 | constexpr dtype_t has_typestring::dtype; 34 | constexpr dtype_t has_typestring>::dtype; 35 | constexpr dtype_t has_typestring>::dtype; 36 | constexpr dtype_t has_typestring>::dtype; 37 | 38 | void CloseNumpy(npy_reader_t* reader) 39 | { 40 | reader->stream.close(); 41 | delete reader; 42 | } 43 | void CloseNumpy(npy_writer_t* writer) 44 | { 45 | writer->stream.close(); 46 | delete writer; 47 | } 48 | 49 | void* OpenNumpyMmap( const std::string& filename, size_t offset, size_t* size) 50 | { 51 | int fd = open(filename.c_str(), O_RDONLY); 52 | struct stat sb; 53 | if (fstat(fd,&sb) == -1) 54 | { 55 | return nullptr; 56 | } 57 | void* ptr = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE | MAP_NORESERVE, fd, 0); 58 | *size = sb.st_size; 59 | return (void*)((uint8_t*)ptr+offset); 60 | } 61 | 62 | void CloseNumpyMmap(void *ptr, size_t size) 63 | { 64 | munmap(ptr, size); 65 | } 66 | void Seek(npy_reader_t* reader, size_t offset) 67 | { 68 | reader->stream.seekg(offset, std::ios::beg); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/WorkContext.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #include "WorkContext.h" 15 | #include "PWConfig.h" 16 | #include "Log.h" 17 | 18 | #include 19 | #include 20 | 21 | #include 22 | 23 | static wc_gopts_t g_opts_map; 24 | 25 | void wc_gopts_merge(const wc_gopts_t& opts) 26 | { 27 | g_opts_map.insert(opts.begin(), opts.end()); 28 | } 29 | const variant_t& wc_gopts_get(const std::string& key, const variant_t& defaultvar) 30 | { 31 | auto it = g_opts_map.find(key); 32 | if (it != g_opts_map.end()) 33 | { 34 | return it->second; 35 | } 36 | else 37 | { 38 | return defaultvar; 39 | } 40 | } 41 | bool wc_gopts_has(const std::string& key) 42 | { 43 | return g_opts_map.end() != g_opts_map.find(key); 44 | } 45 | const variant_t& wc_gopts_get(const std::string& key) 46 | { 47 | auto it = g_opts_map.find(key); 48 | if (it != g_opts_map.end()) 49 | { 50 | return it->second; 51 | } 52 | else 53 | { 54 | LogErrDie("option not found '%s'\n", key.c_str()); 55 | } 56 | } 57 | std::string wc_generate_path(const char* title, const char* filesuffix) 58 | { 59 | std::vector path(255); 60 | const char* outputdir = pwconfig_get_value("OUTPUTDIR"); 61 | if (outputdir) 62 | { 63 | struct stat stats; 64 | 65 | stat(outputdir, &stats); 66 | 67 | if ((stats.st_mode & F_OK) == 0) 68 | { 69 | mkdir(outputdir, 0777); 70 | } 71 | 72 | snprintf(path.data(), 254, "%s/%s-%s", outputdir, title, filesuffix); 73 | } 74 | else 75 | { 76 | snprintf(path.data(), 254, "%s-%s", title, filesuffix); 77 | } 78 | return std::string(path.data()); 79 | } 80 | 81 | std::string wc_output_dir() 82 | { 83 | std::vector path(255); 84 | const char* outputdir = pwconfig_get_value("OUTPUTDIR"); 85 | if (outputdir) 86 | { 87 | struct stat stats; 88 | 89 | stat(outputdir, &stats); 90 | 91 | if ((stats.st_mode & F_OK) == 0) 92 | { 93 | mkdir(outputdir, 0777); 94 | } 95 | 96 | return std::string(outputdir); 97 | } 98 | else 99 | { 100 | return std::string(""); 101 | } 102 | } 103 | 104 | -------------------------------------------------------------------------------- /src/CpUnivFirstOrderTTest.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #include 15 | #include "Trace.h" 16 | #include "FirstOrderTTestAnalysis.h" 17 | #include "AnalysisOuput.h" 18 | #include "PWFactory.h" 19 | #include "TraceUtils.h" 20 | #include "WorkContext.h" 21 | #include "CpUnivFirstOrderTTest.h" 22 | 23 | struct cp_univ_first_order_ttest_priv_t 24 | { 25 | std::vector aos; 26 | std::vector fottests; 27 | traceinfo_t traceinfo; 28 | pwtermset_mode_t mode; 29 | }; 30 | 31 | cp_univ_first_order_ttest_t::~cp_univ_first_order_ttest_t() 32 | { 33 | } 34 | cp_univ_first_order_ttest_t::cp_univ_first_order_ttest_t() 35 | { 36 | pimpl.init(); 37 | } 38 | void cp_univ_first_order_ttest_t::init(const traceinfo_t *traceinfo, pwtermset_mode_t mode) 39 | { 40 | 41 | auto p = pimpl.get(); 42 | p->aos.resize(traceinfo->nterms); 43 | p->fottests.resize(traceinfo->nterms); 44 | p->mode = mode; 45 | p->traceinfo = *traceinfo; 46 | if (p->mode == TS_RECORD && traceinfo->title == "power") 47 | { 48 | p->mode = TS_ONLINE; 49 | } 50 | 51 | if (p->mode == TS_RECORD) 52 | { 53 | return; 54 | } 55 | for (auto i=0u;interms;i++) 56 | { 57 | std::vector outsuffix(255); 58 | snprintf(outsuffix.data(), 254, "fottest-%d.npy", i); 59 | 60 | std::string filename = wc_generate_path(traceinfo->title.c_str(), outsuffix.data()); 61 | p->aos[i].init(filename.data(), "numpy"); 62 | 63 | p->fottests[i].init(traceinfo, &p->aos[i]); 64 | } 65 | } 66 | void cp_univ_first_order_ttest_t::process(const trace_t* trace) 67 | { 68 | auto p = pimpl.get(); 69 | if (p->mode == TS_RECORD) 70 | return; 71 | for (auto i=0u;itraceinfo.nterms;i++) 72 | { 73 | traceinfo_t term0traceinfo = p->traceinfo; 74 | term0traceinfo.nterms = 1; 75 | 76 | trace_t term0trace(&term0traceinfo); 77 | traceutils_extract_term(trace, &term0trace, i, &p->traceinfo , &term0traceinfo); 78 | 79 | p->fottests[i].trace_submit(&term0trace); 80 | } 81 | } 82 | void cp_univ_first_order_ttest_t::finit() 83 | { 84 | auto p = pimpl.get(); 85 | if (p->mode == TS_RECORD) 86 | { 87 | return; 88 | } 89 | 90 | 91 | for (auto i=0u;itraceinfo.nterms;i++) 92 | { 93 | p->fottests[i].finit(); 94 | } 95 | } 96 | 97 | -------------------------------------------------------------------------------- /src/transposer.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #include "../thirdparty/npy/npy.hpp" 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | void transpose(float* dest, float* src, long cols, long rows) 22 | { 23 | #ifdef PARALLEL 24 | omp_set_dynamic(0); 25 | omp_set_num_threads(8); 26 | #endif 27 | long block_size = 128; 28 | for (long a=0;aoffset; 52 | size_t size = 0; 53 | std::stringstream ss(reader->header.other); 54 | std::string magic; 55 | long nd,ns,nt; 56 | ss>>magic>>nd>>ns>>nt; 57 | unsigned long shape[] = { (unsigned long) ns*nd, (unsigned long) nt }; 58 | auto writer = npy::WriteNumpyHeader(outfile, false, 2, shape, reader->header.other); 59 | size_t header_offset = writer->offset; 60 | npy::CloseNumpy(writer); 61 | 62 | float* src = (float*) npy::OpenNumpyMmap(infile, offset, &size); 63 | npy::CloseNumpy(reader); 64 | int fd = open(outfile.c_str(), O_RDWR, (mode_t) 0777); 65 | printf("%lu\n", size); 66 | if (lseek (fd, size, SEEK_SET) == -1) 67 | { 68 | printf ("lseek error"); 69 | return -1; 70 | } 71 | 72 | if (write (fd, "", 1) != 1) 73 | { 74 | printf ("write error"); 75 | return -1; 76 | } 77 | 78 | sync(); 79 | void* mmaped = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); 80 | float* dest = (float*)((uint8_t*)mmaped +header_offset); 81 | if (dest == (void*)-1) 82 | { 83 | perror(strerror(errno)); 84 | return -1; 85 | } 86 | //dest[0]=0; 87 | transpose(dest, src, ns*nd, nt); 88 | munmap(mmaped, size); 89 | npy::CloseNumpyMmap(src, size); 90 | return 0; 91 | } 92 | -------------------------------------------------------------------------------- /src/BivMergeOutput.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #include "Vec2.h" 15 | #include "TraceWriterNpy.h" 16 | 17 | #include "../thirdparty/npy/npy.hpp" 18 | 19 | #include 20 | 21 | struct block_t 22 | { 23 | float* _data; 24 | size_t _readhead; 25 | block_t() : 26 | _data(nullptr) 27 | ,_readhead(0) 28 | {} 29 | }; 30 | void biv_merge_output(const std::string& inppathtempl, const std::string& outpath, int splits, uint64_t nsamples, uint64_t ntraces) 31 | { 32 | Vec2 blocks; 33 | blocks.init(splits, splits); 34 | // all blocks 35 | for (int i=0;i outfilepath(255); 40 | snprintf(outfilepath.data(), 254, inppathtempl.c_str(), i, j); 41 | auto reader = npy::LoadHeaderFromNumpy(outfilepath.data()); 42 | size_t offset = reader->offset; 43 | npy::CloseNumpy(reader); 44 | size_t sz = 0; 45 | blocks.at(i, j)._data = (float*)npy::OpenNumpyMmap(outfilepath.data(), offset, &sz); 46 | } 47 | } 48 | 49 | int ns = nsamples / splits; 50 | tracewriter_npy_t writer; 51 | traceinfo_t traceinfo; 52 | traceinfo.ndata = 0; 53 | traceinfo.nsamples = nsamples * (nsamples - 1) /2; 54 | traceinfo.nterms = 1; 55 | traceinfo.ntraces = ntraces; 56 | 57 | writer.open_file(outpath.c_str(), &traceinfo, {{"numpy",""}}); 58 | for (auto t=0u;t outfilepath(255); 82 | snprintf(outfilepath.data(), 254, inppathtempl.c_str(), i, j); 83 | if (std::remove(outfilepath.data()) != 0) 84 | { 85 | LogErr("failed to delete file %s\n", outfilepath.data()); 86 | } 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/CpUnivSecondOrderTTest.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #include 15 | #include "Trace.h" 16 | #include "AnalysisOuput.h" 17 | #include "PWFactory.h" 18 | #include "TraceUtils.h" 19 | #include "WorkContext.h" 20 | #include "SecondOrderTTestAnalysis.h" 21 | #include "CpUnivSecondOrderTTest.h" 22 | 23 | struct cp_univ_second_order_ttest_priv_t 24 | { 25 | std::vector aos; 26 | std::vector fottests; 27 | traceinfo_t traceinfo; 28 | pwtermset_mode_t mode; 29 | }; 30 | 31 | cp_univ_second_order_ttest_t::~cp_univ_second_order_ttest_t() 32 | { 33 | } 34 | cp_univ_second_order_ttest_t::cp_univ_second_order_ttest_t() 35 | { 36 | pimpl.init(); 37 | } 38 | void cp_univ_second_order_ttest_t::init(const traceinfo_t *traceinfo, pwtermset_mode_t mode) 39 | { 40 | 41 | auto p = pimpl.get(); 42 | p->aos.resize(traceinfo->nterms); 43 | p->fottests.resize(traceinfo->nterms); 44 | p->mode = mode; 45 | p->traceinfo = *traceinfo; 46 | p->mode = mode; 47 | if (p->mode == TS_RECORD && traceinfo->title == "power") 48 | { 49 | p->mode = TS_ONLINE; 50 | } 51 | 52 | if (p->mode == TS_RECORD) 53 | { 54 | return; 55 | } 56 | for (auto i=0u;interms;i++) 57 | { 58 | std::vector outsuffix(255); 59 | snprintf(outsuffix.data(), 254, "sottest-%d.npy", i); 60 | 61 | std::string filename = wc_generate_path(traceinfo->title.c_str(), outsuffix.data()); 62 | p->aos[i].init(filename.data(), "numpy"); 63 | 64 | p->fottests[i].init(traceinfo, &p->aos[i]); 65 | } 66 | } 67 | void cp_univ_second_order_ttest_t::process(const trace_t* trace) 68 | { 69 | auto p = pimpl.get(); 70 | if (p->mode == TS_RECORD) 71 | return; 72 | for (auto i=0u;itraceinfo.nterms;i++) 73 | { 74 | traceinfo_t term0traceinfo = p->traceinfo; 75 | term0traceinfo.nterms = 1; 76 | 77 | trace_t term0trace(&term0traceinfo); 78 | traceutils_extract_term(trace, &term0trace, i, &p->traceinfo , &term0traceinfo); 79 | 80 | p->fottests[i].trace_submit(&term0trace); 81 | } 82 | } 83 | void cp_univ_second_order_ttest_t::finit() 84 | { 85 | auto p = pimpl.get(); 86 | if (p->mode == TS_RECORD) 87 | { 88 | return; 89 | } 90 | 91 | 92 | for (auto i=0u;itraceinfo.nterms;i++) 93 | { 94 | p->fottests[i].finit(); 95 | } 96 | } 97 | 98 | -------------------------------------------------------------------------------- /src/Util.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #include "Util.h" 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | int pwutil_get_tracecount(const char* execfile) 24 | { 25 | char* exec_file_cp = strdup(execfile); 26 | char* exec_dir = dirname(exec_file_cp); 27 | char tracecount_buf[256]; 28 | snprintf(tracecount_buf, 255, "%s/tracecount.txt", exec_dir); 29 | free(exec_file_cp); 30 | FILE *ft = fopen(tracecount_buf, "r"); 31 | if (!ft) 32 | { 33 | printf("place tracecount.txt with traces count in exec dir\n"); 34 | exit(-1); 35 | } 36 | int tracecount; 37 | fscanf(ft,"%d",&tracecount); 38 | printf("%d\n",tracecount); 39 | fclose(ft); 40 | return tracecount; 41 | } 42 | 43 | char* pwutil_dirname(char *path) 44 | { 45 | return dirname(path); 46 | } 47 | 48 | int pwutil_abspath(const char* relpath, char* abspath, int abspathlen) 49 | { 50 | char actualpath[PATH_MAX+1]; 51 | char *resolvpath = realpath(relpath, actualpath); 52 | if (resolvpath) 53 | { 54 | strncpy(abspath, resolvpath, abspathlen); 55 | return 0; 56 | } 57 | return -1; 58 | } 59 | int hexchar_to_int(char hex) 60 | { 61 | if ((hex >= 'a') && (hex <= 'z')) 62 | { 63 | return 10 + hex - 'a'; 64 | } 65 | else 66 | { 67 | return hex - '0'; 68 | } 69 | } 70 | char int_to_hexchar(uint8_t ival) 71 | { 72 | if (ival <10) 73 | { 74 | return '0' + ival; 75 | } 76 | else 77 | { 78 | return 'a' + (ival - 10); 79 | } 80 | } 81 | void byte_to_hex(uint8_t byte, char* hex) 82 | { 83 | hex[0] = int_to_hexchar((byte & 0xF0) >> 4); 84 | hex[1] = int_to_hexchar((byte & 0x0F)); 85 | } 86 | uint8_t hex_to_byte(const char hex[2]) 87 | { 88 | char a = tolower(hex[0]); 89 | char b = tolower(hex[1]); 90 | 91 | return hexchar_to_int(a) << 4 | hexchar_to_int(b); 92 | } 93 | void hexstr_to_bytebuf(const char* hexstr, uint8_t* bytebuf) 94 | { 95 | while (*hexstr != '\0') 96 | { 97 | *bytebuf = hex_to_byte(hexstr); 98 | hexstr += 2; 99 | bytebuf += 1; 100 | } 101 | } 102 | 103 | void bytebuf_to_hexstr(const uint8_t* bytebuf, int bytebuflen, char* hexstr) 104 | { 105 | for (int i=0;i 15 | #include 16 | #include 17 | #include "tracewriter.h" 18 | #define XRC_HEADER_LIMIT 4096 19 | void tw_open(struct TraceWriter* tw, const char* file, int mode) 20 | { 21 | tw->impl = NULL; 22 | if (mode == TW_M_CONT) 23 | { 24 | tw->file = fopen(file, "a"); 25 | } 26 | else if (mode == TW_M_NEW) 27 | { 28 | tw->file = fopen(file, "w"); 29 | } 30 | else if (mode == TW_M_READ) 31 | { 32 | tw->fd = open(file, O_RDONLY); 33 | /* Get the size of the file. */ 34 | struct stat s; 35 | int status = fstat (tw->fd, &s); 36 | 37 | tw->impl = mmap(0, s.st_size, PROT_READ, MAP_PRIVATE, tw->fd, 0); 38 | tw->size = s.st_size; 39 | } 40 | } 41 | 42 | void tw_set_property(struct TraceWriter* tw, int prop, uint32_t value) 43 | { 44 | if (!tw->impl) 45 | { 46 | fseek(tw->file, prop * sizeof(uint32_t), SEEK_SET); 47 | fwrite(&value, sizeof(uint32_t), 1, tw->file); 48 | } 49 | else 50 | { 51 | ((uint32_t*)tw->impl)[ prop ] = value; 52 | } 53 | } 54 | void tw_get_property(struct TraceWriter* tw, int prop, uint32_t* value) 55 | { 56 | if (!tw->impl) 57 | { 58 | fseek(tw->file, prop * sizeof(uint32_t), SEEK_SET); 59 | fread(value, sizeof(uint32_t), 1, tw->file); 60 | } 61 | else 62 | { 63 | *value = ((uint32_t*)tw->impl)[ prop ]; 64 | } 65 | } 66 | ssize_t tw_read_samples(struct TraceWriter* tw, tw_t** samples) 67 | { 68 | if (tw->impl) 69 | { 70 | *samples = (tw_t*) &((char*)tw->impl)[XRC_HEADER_LIMIT]; 71 | return tw->size - XRC_HEADER_LIMIT; 72 | } 73 | else 74 | { 75 | return (ssize_t)-1; 76 | } 77 | } 78 | ssize_t tw_write_samples(struct TraceWriter* tw, tw_t* samples, int count) 79 | { 80 | if (ftell(tw->file) < XRC_HEADER_LIMIT) 81 | { 82 | fseek(tw->file, 0, SEEK_END); 83 | if (ftell(tw->file) < XRC_HEADER_LIMIT) 84 | { 85 | fseek(tw->file, XRC_HEADER_LIMIT, SEEK_SET); 86 | } 87 | } 88 | 89 | return fwrite(samples, sizeof(tw_t), count, tw->file); 90 | } 91 | void tw_close(struct TraceWriter* tw) 92 | { 93 | if (tw->impl) 94 | { 95 | struct stat s; 96 | int status = fstat (tw->fd, &s); 97 | 98 | munmap(tw->impl, s.st_size); 99 | } 100 | else 101 | { 102 | fclose(tw->file); 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /src/PWTermSet.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "PWTermSetMode.h" 16 | #include "IPWTermSetProc.h" 17 | #include "PWTermSet.h" 18 | #include "PWConfig.h" 19 | #include "TraceWriter.h" 20 | #include "PWFactory.h" 21 | #include "CmdPipeline.h" 22 | #include "WorkContext.h" 23 | #include "Log.h" 24 | #include "Util.h" 25 | 26 | struct _pwtermset_impl_t 27 | { 28 | std::string _termsetfile; 29 | pwtermset_mode_t _mode; 30 | tracewriter_t* _writer; 31 | traceinfo_t _traceinfo; 32 | int _forcecalc; 33 | cmd_pipeline_t* _pipeline; 34 | 35 | _pwtermset_impl_t(): 36 | _writer(nullptr), 37 | _pipeline(nullptr) 38 | {} 39 | }; 40 | 41 | void pwtermset_init(pwtermset_t** pt, const traceinfo_t* traceinfo, const char* tsdumpfile) 42 | { 43 | *pt = new pwtermset_t; 44 | auto ptptr = *pt; 45 | ptptr->impl = new _pwtermset_impl_t(); 46 | auto pti = ptptr->impl; 47 | 48 | pti->_traceinfo = *traceinfo; 49 | pti->_writer = nullptr; 50 | 51 | wc_gopts_t opts = {{"at_each_ntraces", 5000}}; 52 | wc_gopts_merge(opts); 53 | std::string analysis = pwconfig_get_value("ANALYSIS"); 54 | pti->_pipeline = pwfactory_t::get_instance()->new_cmdpipeline(analysis); 55 | if (analysis.find("rosita,univ") != std::string::npos) 56 | { 57 | pti->_mode = TS_ONLINE; 58 | } 59 | else if (analysis.find("rosita,biv") != std::string::npos) 60 | { 61 | pti->_mode = TS_RECORD; 62 | } 63 | else if (analysis.find("rosita,triv") != std::string::npos) 64 | { 65 | pti->_mode = TS_RECORD; 66 | } 67 | else 68 | { 69 | LogErrDie("unsupported analysis\n"); 70 | } 71 | pti->_pipeline->init(traceinfo, pti->_mode); 72 | 73 | } 74 | void pwtermset_init_from_file(pwtermset_t **pt, const char* termsetfile) 75 | { 76 | } 77 | void pwtermset_process_file(pwtermset_t* pt) 78 | { 79 | } 80 | void pwtermset_set_leakyindexes(pwtermset_t* pt, int* leakyinds, int leakyindscount) 81 | { 82 | } 83 | void pwtermset_bulk_process(pwtermset_t* pt, double* alltermsamples) 84 | { 85 | } 86 | void pwtermset_trace_submit(pwtermset_t* pt, trace_t* trace) 87 | { 88 | auto pti = pt->impl; 89 | PWASSERT(trace->_traceinfo.ndata > 0, "data required"); 90 | PWASSERT(trace->_data.getptr() != nullptr, "data not init"); 91 | // data required due to its usage in differentiation of traces to groups 92 | 93 | pti->_pipeline->process(trace); 94 | } 95 | void pwtermset_dump_output(pwtermset_t* pt, const char* outputfile) 96 | { 97 | } 98 | void pwtermset_finit(pwtermset_t* pt) 99 | { 100 | if (pt->impl->_pipeline) 101 | { 102 | pt->impl->_pipeline->finit(); 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /src/TraceWriterWrapper.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #include "TraceWriterWrapper.h" 15 | #include "Log.h" 16 | #include "Trace.h" 17 | #include "WorkContext.h" 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | namespace fs = boost::filesystem; 25 | class fsuse_t 26 | { 27 | public: 28 | static fsuse_t *get_instance() 29 | { 30 | static fsuse_t singleton; 31 | return &singleton; 32 | } 33 | fsuse_t() 34 | { 35 | LogInfo("fsuse init\n"); 36 | _total = 0; 37 | _checked = false; 38 | } 39 | void add(size_t filesize) 40 | { 41 | std::lock_guard guard(_lock); 42 | _total += filesize; 43 | } 44 | inline void test_fsusage() 45 | { 46 | std::lock_guard guard(_lock); 47 | if (_checked) 48 | return; 49 | fs::space_info si = fs::space(fs::current_path()); 50 | LogInfo("disk available: %lu, required: %lu\n", si.available, _total); 51 | if ( si.available < _total) 52 | { 53 | LogErrDie("Not enough space\n"); 54 | } 55 | _checked = true; 56 | } 57 | private: 58 | std::mutex _lock; 59 | size_t _total; 60 | std::atomic _checked; 61 | }; 62 | tracewriter_wrapper_t::tracewriter_wrapper_t(tracewriter_t* base) 63 | { 64 | _base = base; 65 | }; 66 | 67 | void tracewriter_wrapper_t::open_file(const char* tracepath, 68 | const traceinfo_t* info, 69 | const std::vector& opts) 70 | { 71 | _base->open_file(tracepath, info, opts); 72 | _active = true; 73 | if (wc_gopts_has("force_space")) 74 | { 75 | _active = false; 76 | return; 77 | } 78 | size_t unitsize = 4; 79 | if (traceopt_has_key(opts, "datatype")) 80 | { 81 | auto dtype = traceopt_get_value(opts, "datatype"); 82 | if (dtype == "double") 83 | { 84 | unitsize = 8; 85 | } 86 | } 87 | auto filesize = ((size_t) info->nsamples )* info->ntraces * info->nterms * unitsize; 88 | fsuse_t::get_instance()->add(filesize); 89 | } 90 | void tracewriter_wrapper_t::update_traceinfo(const traceinfo_t* newtraceinfo) 91 | { 92 | _base->update_traceinfo(newtraceinfo); 93 | } 94 | int tracewriter_wrapper_t::write_trace(const trace_t* trace) 95 | { 96 | if (_active) 97 | fsuse_t::get_instance()->test_fsusage(); 98 | 99 | return _base->write_trace(trace); 100 | } 101 | void tracewriter_wrapper_t::finit(const traceinfo_t* finaltraceinfo) 102 | { 103 | _base->finit(finaltraceinfo); 104 | } 105 | tracewriter_wrapper_t::~tracewriter_wrapper_t() 106 | { 107 | delete _base; 108 | } 109 | -------------------------------------------------------------------------------- /src/CpStackFactory.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #include "CpStack.h" 15 | #include "StMean.h" 16 | #include "StNorm.h" 17 | #include "StCorr.h" 18 | #include "StFott.h" 19 | #include "StChisq.h" 20 | #include "StTraceCombiner.h" 21 | #include "StNormCrossCorr.h" 22 | #include "StPattern.h" 23 | #include "StStaticAlign.h" 24 | static cp_stack_t* make_normcombcorr() 25 | { 26 | auto stmean = new st_mean_t(); 27 | auto stnorm = new st_norm_t(stmean); 28 | auto stcorr = new st_corr_t(); 29 | auto stcomb = new st_trace_combiner_t(); 30 | 31 | auto cps = new cp_stack_t(); 32 | cps->stack_add(stmean, 0); 33 | cps->stack_add(stnorm, 1); 34 | cps->stack_add(stcomb, 1); 35 | cps->stack_add(stcorr, 1); 36 | return cps; 37 | } 38 | static cp_stack_t* make_corr() 39 | { 40 | auto stcorr = new st_corr_t(); 41 | 42 | auto cps = new cp_stack_t(); 43 | cps->stack_add(stcorr, 0); 44 | return cps; 45 | } 46 | static cp_stack_t* make_normcombfott() 47 | { 48 | auto stfott = new st_fott_t(); 49 | auto stmean = new st_mean_t(); 50 | auto stnorm = new st_norm_t(stmean); 51 | auto stcomb = new st_trace_combiner_t(); 52 | auto cps = new cp_stack_t(); 53 | 54 | cps->stack_add(stmean, 0); 55 | cps->stack_add(stnorm, 1); 56 | cps->stack_add(stcomb, 1); 57 | cps->stack_add(stfott, 1); 58 | return cps; 59 | } 60 | static cp_stack_t* make_chisq() 61 | { 62 | auto stchisq = new st_chisq_t(); 63 | auto cps = new cp_stack_t(); 64 | 65 | cps->stack_add(stchisq, 0); 66 | return cps; 67 | } 68 | static cp_stack_t* make_patternmatch() 69 | { 70 | auto stcorr = new st_norm_cross_corr_t(); 71 | auto stpat = new st_pattern_t(); 72 | auto cps = new cp_stack_t(); 73 | cps->stack_add(stcorr, 0); 74 | cps->stack_add(stpat, 0); 75 | return cps; 76 | } 77 | static cp_stack_t* make_staticalign() 78 | { 79 | auto stcorr = new st_norm_cross_corr_t(); 80 | auto stalign = new st_static_align_t(); 81 | auto cps = new cp_stack_t(); 82 | cps->stack_add(stcorr, 0); 83 | cps->stack_add(stalign, 0); 84 | return cps; 85 | } 86 | cp_stack_t* cp_stack_t::make_instance(const std::string& name) 87 | { 88 | if (name == "normcombcorr") 89 | { 90 | return make_normcombcorr(); 91 | } 92 | else if (name == "corr") 93 | { 94 | return make_corr(); 95 | } 96 | else if (name == "normcombfott") 97 | { 98 | return make_normcombfott(); 99 | } 100 | else if (name == "chisq") 101 | { 102 | return make_chisq(); 103 | } 104 | else if (name == "staticalign") 105 | { 106 | return make_staticalign(); 107 | } 108 | else if (name == "patternmatch") 109 | { 110 | return make_patternmatch(); 111 | } 112 | return nullptr; 113 | } 114 | 115 | -------------------------------------------------------------------------------- /src/AnalysisOuput.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #include 15 | #include 16 | #include "AnalysisOuput.h" 17 | #include "PWFactory.h" 18 | #include "Log.h" 19 | 20 | struct analysis_output_priv_t 21 | { 22 | std::string outputfile; 23 | tracewriter_t* writer; 24 | traceinfo_t traceinfo; 25 | size_t finaltracecount; 26 | bool issub; 27 | std::vector children; 28 | analysis_output_priv_t() : 29 | writer(nullptr) 30 | ,finaltracecount(0) 31 | ,issub(false) 32 | {} 33 | 34 | }; 35 | 36 | analysis_output_t::analysis_output_t(const analysis_output_t&) = default; 37 | analysis_output_t::analysis_output_t(analysis_output_t&&) = default; 38 | analysis_output_t::analysis_output_t() 39 | { 40 | pimpl.init(); 41 | } 42 | void analysis_output_t::init(const char* outputfile, 43 | const std::string& kind) 44 | { 45 | pimpl.get()->writer = pwfactory_t::get_instance()->new_tracewriter(kind); 46 | pimpl.get()->outputfile = outputfile; 47 | pimpl.get()->finaltracecount = 0; 48 | } 49 | void analysis_output_t::init(const traceinfo_t* traceinfo) 50 | { 51 | PWASSERT(pimpl.get()->writer != nullptr, "writer not init"); 52 | pimpl.get()->writer->open_file(pimpl.get()->outputfile.c_str(), 53 | traceinfo, {{"numpy",""}}); 54 | pimpl.get()->traceinfo = *traceinfo; 55 | } 56 | analysis_output_t* analysis_output_t::add_sub_output(const std::string& id, const std::string& kind) 57 | { 58 | auto dotpos = pimpl.get()->outputfile.find_last_of('.'); 59 | auto afterdot = pimpl.get()->outputfile.substr(dotpos+1); 60 | auto beforedot = pimpl.get()->outputfile.substr(0, dotpos); 61 | std::stringstream ss; 62 | ss << beforedot; 63 | ss << "-" << id << "."; 64 | ss << afterdot; 65 | auto ao = new analysis_output_t(); 66 | ao->init(ss.str().c_str(), kind); 67 | pimpl.get()->children.push_back(ao); 68 | return ao; 69 | } 70 | analysis_output_t* analysis_output_t::get_sub_output(size_t index) 71 | { 72 | return pimpl.get()->children[index]; 73 | } 74 | void analysis_output_t::on_result_trace(const trace_t* trace) 75 | { 76 | pimpl.get()->writer->write_trace(trace); 77 | pimpl.get()->finaltracecount++; 78 | } 79 | void analysis_output_t::update_written_count() 80 | { 81 | auto p = pimpl.get(); 82 | auto ti = p->traceinfo; 83 | ti.ntraces = p->finaltracecount; 84 | p->writer->update_traceinfo(&ti); 85 | } 86 | size_t analysis_output_t::get_written_count() 87 | { 88 | return pimpl.get()->finaltracecount; 89 | } 90 | size_t analysis_output_t::finit() 91 | { 92 | auto p = pimpl.get(); 93 | 94 | for (auto& child : p->children) 95 | { 96 | child->finit(); 97 | delete child; 98 | } 99 | p->children.clear(); 100 | 101 | p->traceinfo.ntraces = p->finaltracecount; 102 | p->writer->finit(&p->traceinfo); 103 | return p->finaltracecount; 104 | } 105 | analysis_output_t::~analysis_output_t() 106 | { 107 | } 108 | -------------------------------------------------------------------------------- /src/CpDynLib.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #include "CpDynLib.h" 15 | #include "AnalysisOuput.h" 16 | #include "Log.h" 17 | #include "Variant.h" 18 | #include "WorkContext.h" 19 | #include "PWFactory.h" 20 | #include "TraceReader.h" 21 | #include "TraceWriter.h" 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | struct cp_dynlib_priv_t 28 | { 29 | analysis_output_t* ao; 30 | void* libhandle; 31 | std::string ext; 32 | std::string filename; 33 | tracereader_t* reader; 34 | tracewriter_t* writer; 35 | traceinfo_t traceinfo; 36 | traceinfo_t winti; 37 | wc_gopts_t opts_map; 38 | 39 | void (*pwdl_on_init)(uint32_t ntraces, uint32_t nsamples, uint32_t ndata); 40 | void (*pwdl_on_trace)(const double* tracein, const uint8_t* tracedatain, double** traceout, uint8_t** tracedataout); 41 | void (*pwdl_on_finit)(); 42 | }; 43 | 44 | cp_dynlib_t::cp_dynlib_t() 45 | { 46 | pimpl.init(); 47 | } 48 | void cp_dynlib_t::init(const traceinfo_t *traceinfo, pwtermset_mode_t mode) 49 | { 50 | pimpl.get()->ao = new analysis_output_t[1]; 51 | std::string libname = wc_gopts_get("library_name").get_string(); 52 | auto& lh = pimpl.get()->libhandle; 53 | lh = dlopen(libname.c_str(), RTLD_NOW); 54 | dlerror(); 55 | char *error=nullptr; 56 | pimpl.get()->pwdl_on_init = (decltype(pimpl.get()->pwdl_on_init))dlsym(lh, "pwdl_on_init"); 57 | pimpl.get()->pwdl_on_trace = (decltype(pimpl.get()->pwdl_on_trace))dlsym(lh, "pwdl_on_trace"); 58 | pimpl.get()->pwdl_on_finit = (decltype(pimpl.get()->pwdl_on_finit))dlsym(lh, "pwdl_on_finit"); 59 | error = dlerror(); 60 | if (error) 61 | { 62 | LogErrDie("%s\n", error); 63 | } 64 | pimpl.get()->pwdl_on_init(traceinfo->ntraces, 65 | traceinfo->nsamples * traceinfo->nterms, 66 | traceinfo->ndata); 67 | pimpl.get()->writer = pwfactory_t::get_instance()->new_tracewriter("npy"); 68 | /* 69 | for (int i=r_begin;i<=r_end;i++) 70 | { 71 | int normidx = i; 72 | std::stringstream ssaofile; 73 | ssaofile<<"dynlibout-"<title.c_str(), ssaofile.str().c_str()); 76 | pimpl.get()->ao[normidx].init(outfilepath.c_str(),"numpy"); 77 | pimpl.get()->corr[normidx].init(traceinfo, &pimpl.get()->ao[normidx], {{"corr_data_index", i}}); 78 | }*/ 79 | traceinfo_print("", traceinfo); 80 | } 81 | 82 | void cp_dynlib_t::init(const char* filename) 83 | { 84 | } 85 | void cp_dynlib_t::process() 86 | { 87 | } 88 | void cp_dynlib_t::process(const trace_t* trace) 89 | { 90 | double* outsamples=nullptr; 91 | uint8_t* outdata=nullptr; 92 | pimpl.get()->pwdl_on_trace(trace->_samples.getptr(), trace->_data.getptr(), 93 | &outsamples, 94 | &outdata); 95 | if (outsamples) 96 | { 97 | 98 | } 99 | } 100 | void cp_dynlib_t::finit() 101 | { 102 | pimpl.get()->pwdl_on_finit(); 103 | dlclose(pimpl.get()->libhandle); 104 | pimpl.get()->writer->finit(nullptr); 105 | } 106 | cp_dynlib_t::~cp_dynlib_t() 107 | { 108 | } 109 | -------------------------------------------------------------------------------- /src/TraceReaderXrc.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #include "TraceReaderXrc.h" 15 | #include "DataFile.h" 16 | #include "../thirdparty/tracewriter/tracewriter.h" 17 | 18 | struct tracereader_xrc_priv_t 19 | { 20 | pwdatastream_t datastream; 21 | traceinfo_t traceinfo; 22 | TraceWriter tw; 23 | double frac; 24 | uint64_t trace_id; 25 | std::vector dsamples; 26 | }; 27 | 28 | tracereader_xrc_t::tracereader_xrc_t() 29 | { 30 | pimpl.init(); 31 | } 32 | void tracereader_xrc_t::open_file(const char* tracepath, traceinfo_t* info) 33 | { 34 | auto p = pimpl.get(); 35 | tw_open(&p->tw, tracepath, TW_M_READ); 36 | 37 | uint32_t tp_fmt, tp_samples, tp_rounds, tp_caps, tp_num, tp_den; 38 | tw_get_property(&p->tw, TW_P_SAMPLES_PER_CAP, &tp_samples); 39 | tw_get_property(&p->tw, TW_P_FMT, &tp_fmt); 40 | tw_get_property(&p->tw, TW_P_ROUNDS, &tp_rounds); 41 | tw_get_property(&p->tw, TW_P_CAPS_PER_ROUND, &tp_caps); 42 | 43 | tw_get_property(&p->tw, TW_P_FRAC_NUM, &tp_num); 44 | tw_get_property(&p->tw, TW_P_FRAC_DENO, &tp_den); 45 | 46 | p->frac = ((float)tp_num)/((float)tp_den); 47 | uint32_t ntraces = tp_caps * tp_rounds; 48 | 49 | p->traceinfo.ntraces = (int) ntraces; 50 | p->traceinfo.nsamples = (int) tp_samples; 51 | p->traceinfo.nterms = 1; 52 | std::string stracepath(tracepath); 53 | auto dotpos = stracepath.find_last_of("."); 54 | auto slashpos = stracepath.find_last_of("/"); 55 | if (slashpos == std::string::npos) 56 | { 57 | slashpos = 0; 58 | } 59 | else 60 | { 61 | slashpos +=1; 62 | } 63 | 64 | p->traceinfo.title = stracepath.substr(slashpos, dotpos - slashpos); 65 | 66 | std::vector datapath(256); 67 | snprintf(datapath.data(), datapath.size(), "%s.data", tracepath); 68 | 69 | pwdata_read_open(p->datastream, datapath.data(), p->traceinfo.ndata); 70 | 71 | p->dsamples.resize(tp_samples); 72 | p->trace_id = 0; 73 | *info = p->traceinfo; 74 | } 75 | void tracereader_xrc_t::seek(size_t traceid) 76 | { 77 | pimpl.get()->trace_id = traceid; 78 | pwdata_read_seek(pimpl.get()->datastream, traceid); 79 | } 80 | void tracereader_xrc_t::rewind() 81 | { 82 | pimpl.get()->trace_id = 0; 83 | pwdata_read_rewind(pimpl.get()->datastream); 84 | } 85 | int tracereader_xrc_t::read_trace(trace_t* trace) 86 | { 87 | auto p = pimpl.get(); 88 | if (p->trace_id >= (uint64_t) p->traceinfo.ntraces) 89 | { 90 | return 0; 91 | } 92 | 93 | tw_t *samples; 94 | tw_read_samples(&p->tw, &samples); 95 | 96 | for (auto i=0u;itraceinfo.nsamples;i++) 97 | { 98 | p->dsamples[i] = p->frac * samples[p->trace_id * p->traceinfo.nsamples + i]; 99 | } 100 | 101 | if (p->datastream.hasdata) 102 | { 103 | std::vector bytedata(p->traceinfo.ndata); 104 | pwdata_read_data(p->datastream, bytedata.data(), p->traceinfo.ndata); 105 | 106 | trace->init_copy(p->dsamples.data(), 107 | bytedata.data(), &p->traceinfo); 108 | } 109 | else 110 | { 111 | trace->init_view(p->dsamples.data(), nullptr, &p->traceinfo); 112 | } 113 | 114 | p->trace_id++; 115 | return 1; 116 | } 117 | tracereader_xrc_t::~tracereader_xrc_t() 118 | { 119 | auto p = pimpl.get(); 120 | pwdata_read_close(p->datastream); 121 | tw_close(&p->tw); 122 | } 123 | -------------------------------------------------------------------------------- /src/TraceWriterTrs.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #include 15 | #include 16 | #include 17 | #include "../thirdparty/trs/trs.h" 18 | #include "TraceWriterTrs.h" 19 | #include "PImpl.h" 20 | #include "WorkContext.h" 21 | #include "Util.h" 22 | #include "Log.h" 23 | 24 | struct tracewriter_trs_priv_t 25 | { 26 | size_t sz; 27 | double* samples; 28 | traceinfo_t traceinfo; 29 | trs_set trsset; 30 | int trace_id; 31 | std::ofstream ofdata; 32 | bool hasdata; 33 | std::vector fsamples; 34 | std::vector opts; 35 | std::string tracepath; 36 | long written; 37 | }; 38 | 39 | tracewriter_trs_t::tracewriter_trs_t() 40 | { 41 | pimpl.init(); 42 | } 43 | void tracewriter_trs_t::open_file(const char* tracepath, const traceinfo_t* info, const std::vector& opts) 44 | { 45 | auto p = pimpl.get(); 46 | p->opts = opts; 47 | p->tracepath = tracepath; 48 | p->hasdata = false; 49 | if (info->ndata > 0) 50 | { 51 | p->hasdata = true; 52 | } 53 | int failed=0; 54 | auto& trsset = pimpl.get()->trsset; 55 | trs_open_file(&trsset, tracepath, "wb"); 56 | trs_add_header_int(&trsset, NUMBER_TRACES, (int) info->ntraces); 57 | trs_add_header_int(&trsset, NUMBER_SAMPLES, (int) (info->nsamples * info->nterms)); 58 | trs_add_header_int(&trsset, LENGTH_DATA, (int) info->ndata); 59 | trs_add_header_int(&trsset, SAMPLE_CODING, (int) trs_sc_float); 60 | trs_write_headers(&trsset, &failed); 61 | PWASSERT(failed == 0, "writing headers failed!"); 62 | p->fsamples.resize(info->nsamples*info->nterms); 63 | p->traceinfo = *info; 64 | p->written = 0; 65 | } 66 | 67 | void tracewriter_trs_t::finit(const traceinfo_t* finaltraceinfo) 68 | { 69 | if (finaltraceinfo) 70 | { 71 | trs_clear_header(&pimpl.get()->trsset); 72 | auto& trsset = pimpl.get()->trsset; 73 | int failed=0; 74 | auto info = finaltraceinfo; 75 | trs_add_header_int(&trsset, NUMBER_TRACES, (int) info->ntraces); 76 | trs_add_header_int(&trsset, NUMBER_SAMPLES, (int) (info->nsamples * info->nterms)); 77 | trs_add_header_int(&trsset, LENGTH_DATA, (int) info->ndata); 78 | trs_add_header_int(&trsset, SAMPLE_CODING, (int) trs_sc_float); 79 | trs_write_headers(&trsset, &failed); 80 | PWASSERT(failed == 0, "writing headers failed!"); 81 | } 82 | LogInfo("aa %ld\n", pimpl.get()->written); 83 | trs_close(&pimpl.get()->trsset); 84 | } 85 | int tracewriter_trs_t::write_trace(const trace_t* trace) 86 | { 87 | auto p = pimpl.get(); 88 | 89 | for (auto i=0u; itraceinfo.nsamples*p->traceinfo.nterms;i++) 90 | { 91 | p->fsamples[i] = (float) trace->_samples[i]; 92 | } 93 | 94 | trs_trace trstrace; 95 | trstrace.data = const_cast (trace->_data.getptr()); 96 | trstrace.samples = p->fsamples.data(); 97 | trs_write_trace(&p->trsset, &trstrace); 98 | p->written++; 99 | return 0; 100 | } 101 | void tracewriter_trs_t::update_traceinfo(const traceinfo_t* newtraceinfo) 102 | { 103 | trs_clear_header(&pimpl.get()->trsset); 104 | auto& trsset = pimpl.get()->trsset; 105 | int failed=0; 106 | auto info = newtraceinfo; 107 | trs_add_header_int(&trsset, NUMBER_TRACES, (int) info->ntraces); 108 | trs_add_header_int(&trsset, NUMBER_SAMPLES, (int) (info->nsamples * info->nterms)); 109 | trs_add_header_int(&trsset, LENGTH_DATA, (int) info->ndata); 110 | trs_add_header_int(&trsset, SAMPLE_CODING, (int) trs_sc_float); 111 | trs_write_headers(&trsset, &failed); 112 | PWASSERT(failed == 0, "writing headers failed!"); 113 | } 114 | tracewriter_trs_t::~tracewriter_trs_t() 115 | { 116 | finit(nullptr); 117 | } 118 | -------------------------------------------------------------------------------- /thirdparty/trs/trs.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | 16 | #include 17 | #include 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | typedef enum _trs_datatype_t 23 | { 24 | trs_int, 25 | trs_float, 26 | trs_short, 27 | trs_byte, 28 | trs_bool, 29 | trs_str, 30 | trs_none, 31 | trs_samplecoding 32 | } trs_datatype; 33 | 34 | typedef struct _trs_tag_def 35 | { 36 | uint8_t tagid; 37 | char tagcode[3]; 38 | int is_mandatory; 39 | trs_datatype type; 40 | int length; 41 | const char *desc; 42 | } trs_tag_def; 43 | 44 | typedef struct _trs_sc_def 45 | { 46 | uint8_t scid; 47 | uint8_t length; 48 | } trs_sc_def; 49 | 50 | typedef enum _trs_sc 51 | { 52 | trs_sc_byte = 0, 53 | trs_sc_short, 54 | trs_sc_int, 55 | trs_sc_float 56 | } trs_sc; 57 | 58 | extern trs_sc_def scdefs[]; 59 | extern trs_tag_def tagdefs[]; 60 | 61 | typedef enum _trs_tag { 62 | NUMBER_TRACES = 0, 63 | NUMBER_SAMPLES, 64 | SAMPLE_CODING, 65 | LENGTH_DATA, 66 | TITLE_SPACE, 67 | TRACE_TITLE, 68 | DESCRIPTION, 69 | OFFSET_X, 70 | LABEL_X, 71 | LABEL_Y, 72 | SCALE_X, 73 | SCALE_Y, 74 | TRACE_OFFSET, 75 | LOGARITHMIC_SCALE, 76 | ACQUISITION_RANGE_OF_SCOPE, 77 | ACQUISITION_COUPLING_OF_SCOPE, 78 | ACQUISITION_OFFSET_OF_SCOPE, 79 | ACQUISITION_INPUT_IMPEDANCE, 80 | ACQUISITION_DEVICE_ID, 81 | ACQUISITION_TYPE_FILTER, 82 | ACQUISITION_FREQUENCY_FILTER, 83 | ACQUISITION_RANGE_FILTER, 84 | TRACE_BLOCK, 85 | EXTERNAL_CLOCK_USED, 86 | EXTERNAL_CLOCK_THRESHOLD, 87 | EXTERNAL_CLOCK_MULTIPLIER, 88 | EXTERNAL_CLOCK_PHASE_SHIFT, 89 | EXTERNAL_CLOCK_RESAMPLER_MASK, 90 | EXTERNAL_CLOCK_RESAMPLER_ENABLED, 91 | EXTERNAL_CLOCK_FREQUENCY, 92 | EXTERNAL_CLOCK_BASE, 93 | NUMBER_VIEW, 94 | TRACE_OVERLAP, 95 | GO_LAST_TRACE, 96 | INPUT_OFFSET, 97 | OUTPUT_OFFSET, 98 | KEY_OFFSET, 99 | INPUT_LENGTH, 100 | OUTPUT_LENGTH, 101 | KEY_LENGTH, 102 | NUMBER_OF_ENABLED_CHANNELS, 103 | NUMBER_OF_USED_OSCILLOSCOPES, 104 | XY_SCAN_WIDTH, 105 | XY_SCAN_HEIGHT, 106 | XY_MEASUREMENTS_PER_SPOT 107 | } trs_tag; 108 | 109 | 110 | typedef struct _trace { 111 | void *samples; 112 | uint8_t *data; 113 | } trs_trace; 114 | 115 | typedef struct _trs_header_data { 116 | trs_tag tag; 117 | char *chrdata; 118 | int intdata; 119 | float fltdata; 120 | struct _trs_header_data *next; 121 | } trs_header_data; 122 | 123 | typedef struct _trs_set { 124 | FILE *fp; 125 | int NT; 126 | int NS; 127 | trs_sc SC; 128 | int DS; 129 | uint8_t TS; 130 | trs_trace *traces; 131 | // only allow write when value is 3 (all mandatory fields are filled in) 132 | int write_ok; 133 | trs_header_data *headerdata_start; 134 | trs_header_data *headerdata_current; 135 | long data_start; 136 | long last_write; 137 | } trs_set; 138 | 139 | void trs_open_file(trs_set *trs, const char *filename, const char* mode); 140 | void trs_add_header_int(trs_set* trs, trs_tag tag, int val); 141 | void trs_add_header_str(trs_set* trs, trs_tag tag, char* val); 142 | void trs_add_header_float(trs_set* trs, trs_tag tag, float val); 143 | void trs_clear_header(trs_set* trs); 144 | void trs_write_headers(trs_set* trs, int *failed); 145 | void trs_parse_header(trs_set *trs, int *failed); 146 | void trs_write_trace(trs_set *trs, trs_trace *trace); 147 | void trs_read_trace(trs_set *trs, trs_trace* trace); 148 | void trs_seekto_trace(trs_set *trs, unsigned traceid); 149 | trs_trace trs_make_trace(trs_set* trs); 150 | void trs_del_trace(trs_trace trace); 151 | void trs_close(trs_set* trs); 152 | void trs_rewind(trs_set* trs); 153 | #ifdef __cplusplus 154 | } 155 | #endif 156 | -------------------------------------------------------------------------------- /src/MeanAnalysis.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #include 15 | 16 | #include "Trace.h" 17 | #include "TraceUtils.h" 18 | #include "Log.h" 19 | #include "WorkContext.h" 20 | #include "AnalysisOuput.h" 21 | #include "MeanAnalysis.h" 22 | struct mean_analysis_priv_t 23 | { 24 | traceinfo_t traceinfo; 25 | traceinfo_t meantrinfo; 26 | std::vector meantraces; 27 | std::vector copymeantraces; 28 | std::vector n; 29 | bool hasdata; 30 | size_t m; 31 | }; 32 | 33 | void mean_analysis_t::init(const traceinfo_t *traceinfo, 34 | analysis_output_t* output, 35 | const analysis_opts_t& opts) 36 | { 37 | pimpl.get()->traceinfo = *traceinfo; 38 | pimpl.get()->hasdata = traceinfo->ndata != 0; 39 | traceinfo_print("mean::init", traceinfo); 40 | pimpl.get()->meantrinfo = *traceinfo; 41 | pimpl.get()->meantrinfo.ntraces = 1; 42 | 43 | int groups = traceutils_groups_count(); 44 | pimpl.get()->meantraces.resize(groups); 45 | pimpl.get()->copymeantraces.resize(groups); 46 | for (int i=0;imeantraces[i].init(&pimpl.get()->meantrinfo); 49 | pimpl.get()->copymeantraces[i].init(&pimpl.get()->meantrinfo); 50 | } 51 | 52 | pimpl.get()->n.resize(groups); 53 | LogInfo("mean %p %s\n", this, traceinfo->title.c_str()); 54 | pimpl.get()->m = wc_gopts_get("at_each_ntraces").get_int(); 55 | 56 | } 57 | void mean_analysis_t::trace_submit(const trace_t *trace) 58 | { 59 | auto p = pimpl.get(); 60 | uint8_t gid = 0; 61 | if (p->hasdata) 62 | { 63 | gid = traceutils_group(trace); 64 | auto oldsize = p->meantraces.size(); 65 | if (gid >= p->meantraces.size()) 66 | { 67 | p->meantraces.resize(gid+1); 68 | p->n.resize(gid+1); 69 | p->copymeantraces.resize(gid+1); 70 | for (auto i=oldsize;imeantraces.size();i++) 71 | { 72 | p->meantraces[gid].init(&p->meantrinfo); 73 | p->copymeantraces[gid].init(&p->meantrinfo); 74 | } 75 | } 76 | } 77 | if ((p->n[gid] % p->m) == 0) 78 | { 79 | p->copymeantraces[gid].copyfrom(&p->meantraces[gid]); 80 | } 81 | size_t n = p->n[gid]; 82 | for (auto i=0u;itraceinfo.nsamples*p->traceinfo.nterms;i++) 83 | { 84 | p->meantraces[gid]._samples[i] = (p->meantraces[gid]._samples[i] * n + trace->_samples[i])/(n+1); 85 | } 86 | p->n[gid] ++; 87 | } 88 | 89 | double mean_analysis_t::getmean(int groupid, int sampleid) 90 | { 91 | auto p = pimpl.get(); 92 | return p->meantraces[groupid]._samples[sampleid]; 93 | } 94 | void mean_analysis_t::finit() 95 | { 96 | auto p = pimpl.get(); 97 | for (auto g=0u;gn.size();g++) 98 | { 99 | analysis_output_t ao; 100 | for (auto i=0u;imeantrinfo.nsamples*p->meantrinfo.nterms;i++) 101 | { 102 | p->copymeantraces[g]._samples[i] = p->meantraces[g]._samples[i]; 103 | } 104 | LogInfo("mean group %lu count %lu\n", (unsigned long) g, (unsigned long) p->n[g]); 105 | std::vector fsuffix(32); 106 | snprintf(fsuffix.data(), 31, "means-%lu.npy", (unsigned long) g); 107 | 108 | std::string outputfilepath = wc_generate_path(p->meantrinfo.title.c_str(), fsuffix.data()); 109 | 110 | LogInfo("%s\n", outputfilepath.c_str()); 111 | ao.init(outputfilepath.c_str(),"numpy"); 112 | ao.init(&p->meantrinfo); 113 | ao.on_result_trace(&p->copymeantraces[g]); 114 | p->copymeantraces[g].print(); 115 | ao.finit(); 116 | } 117 | } 118 | 119 | mean_analysis_t::mean_analysis_t() 120 | { 121 | pimpl.init(); 122 | } 123 | mean_analysis_t::~mean_analysis_t() 124 | { 125 | 126 | } 127 | 128 | -------------------------------------------------------------------------------- /src/CpFileBivFirstOrderTTestMt.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #include "CpFileBivFirstOrderTTestMt.h" 15 | #include "FirstOrderTTestAnalysis.h" 16 | #include "MeanAnalysis.h" 17 | #include "AnalysisOuput.h" 18 | #include "TraceUtils.h" 19 | #include "PWFactory.h" 20 | #include "TraceWriter.h" 21 | #include "TraceReader.h" 22 | #include "Log.h" 23 | #include "Passes.h" 24 | #include "Trace.h" 25 | #include "WorkContext.h" 26 | #include "Perf.h" 27 | #include "BivMergeOutput.h" 28 | #include 29 | struct cp_file_biv_first_order_ttest_mt_priv_t 30 | { 31 | traceinfo_t traceinfo; 32 | traceinfo_t windowtrinfo; 33 | traceinfo_t fottesttraceinfo; 34 | analysis_t* fottest; 35 | analysis_output_t ao; 36 | mean_analysis_t meanana; 37 | pwtermset_mode_t mode; 38 | //trace_t temptrace; 39 | trace_t combinedtr; 40 | int pass; 41 | uint32_t trid; 42 | }; 43 | cp_file_biv_first_order_ttest_mt_t::cp_file_biv_first_order_ttest_mt_t() 44 | { 45 | pimpl.init(); 46 | } 47 | void cp_file_biv_first_order_ttest_mt_t::get_info(cmd_pipeline_info_t& info) 48 | { 49 | info = cmd_pipeline_info_t{2}; 50 | } 51 | void cp_file_biv_first_order_ttest_mt_t::init(const traceinfo_t *traceinfo, pwtermset_mode_t mode) 52 | { 53 | pimpl.get()->traceinfo = *traceinfo; 54 | pimpl.get()->windowtrinfo = *traceinfo; 55 | pimpl.get()->meanana.init(traceinfo, nullptr); 56 | //pimpl.get()->temptrace.init(traceinfo); 57 | } 58 | void cp_file_biv_first_order_ttest_mt_t::init(const char* filename) 59 | { 60 | } 61 | void cp_file_biv_first_order_ttest_mt_t::pass_begin(int pass) 62 | { 63 | pimpl.get()->pass = pass; 64 | } 65 | void cp_file_biv_first_order_ttest_mt_t::process() 66 | { 67 | } 68 | void cp_file_biv_first_order_ttest_mt_t::process(const trace_t* trace) 69 | { 70 | auto p = pimpl.get(); 71 | 72 | if (p->pass == 0) 73 | { 74 | // submit to mean calc 75 | //trace_t meantr(&p->windowtrinfo); 76 | //preprocess_trace(&meantr, trace); 77 | //meantr.print(); 78 | trace_t temptrace(&p->windowtrinfo); 79 | trace->copyto(&temptrace, 0); 80 | pwpass_moving_average(&temptrace); 81 | p->meanana.trace_submit(&temptrace); 82 | } 83 | else if (p->pass == 1) 84 | { 85 | int g = traceutils_group(trace); 86 | trace_t temptrace(&p->traceinfo); 87 | 88 | trace->copyto(&temptrace, 0); 89 | pwpass_moving_average(&temptrace); 90 | for (auto i=0u;iwindowtrinfo.nsamples;i++) 91 | { 92 | temptrace._samples[i] -= p->meanana.getmean(g, i); 93 | } 94 | p->fottest->trace_submit(&temptrace); 95 | p->trid ++; 96 | } 97 | 98 | } 99 | void cp_file_biv_first_order_ttest_mt_t::pass_end(int pass) 100 | { 101 | auto p = pimpl.get(); 102 | 103 | p->trid = 0; 104 | if (p->pass == 0) 105 | { 106 | 107 | p->meanana.finit(); 108 | 109 | p->fottesttraceinfo = p->traceinfo; 110 | //p->fottesttraceinfo.nsamples = (p->traceinfo.nsamples - 1) * p->traceinfo.nsamples / 2; 111 | p->fottesttraceinfo.nterms = 1; 112 | 113 | p->combinedtr.init(&p->fottesttraceinfo); 114 | 115 | wc_path_gen_t pgen(p->traceinfo.title); 116 | pgen.add("biv-fottest"); 117 | p->ao.init(pgen.getpath(".npy").c_str(),"numpy"); 118 | p->fottest = pwfactory_t::get_instance()->new_analysis("mt,first-order-ttest"); 119 | p->fottest->init(&p->fottesttraceinfo, &p->ao); 120 | traceinfo_print("out",&p->fottesttraceinfo); 121 | traceinfo_print("in",&p->traceinfo); 122 | traceinfo_print("in",&p->windowtrinfo); 123 | } 124 | else if (p->pass == 1) 125 | { 126 | p->fottest->finit(); 127 | } 128 | } 129 | void cp_file_biv_first_order_ttest_mt_t::finit() 130 | { 131 | LogInfo("starting merge\n"); 132 | } 133 | 134 | cp_file_biv_first_order_ttest_mt_t::~cp_file_biv_first_order_ttest_mt_t() 135 | { 136 | 137 | } 138 | -------------------------------------------------------------------------------- /src/RefCountedPtr.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | #include "Log.h" 16 | #include "Util.h" 17 | #include "Allocator.h" 18 | #include 19 | #ifdef DEBUG 20 | #include 21 | #endif 22 | template 23 | class refcountedptr_t 24 | { 25 | public: 26 | refcountedptr_t() : 27 | _ptr(nullptr) 28 | ,_refcountptr(nullptr) 29 | #ifdef DEBUG 30 | ,_length(0) 31 | ,_tid(std::this_thread::get_id()) 32 | #endif 33 | { 34 | } 35 | void init(size_t length) 36 | { 37 | PWASSERT(_refcountptr == nullptr, "double init"); 38 | _ptr = allocator_t::get_instance()->allocate(length); 39 | LogInfoV(2, "init %p\n", _ptr); 40 | _refcountptr = allocator_t::get_instance()->allocate(1); 41 | *_refcountptr = 1; 42 | #ifdef DEBUG 43 | _length = length; 44 | PWASSERT(_tid == std::this_thread::get_id(), "tid mismatch!"); 45 | _tid = std::this_thread::get_id(); 46 | #endif 47 | } 48 | refcountedptr_t(const refcountedptr_t& other) 49 | { 50 | _refcountptr = other._refcountptr; 51 | #ifdef DEBUG 52 | _length = other._length; 53 | _tid = std::this_thread::get_id(); 54 | if ((*_refcountptr % 100 == 0) && (*_refcountptr > 100)) 55 | { 56 | LogInfo("rr %p %lu\n", other._ptr, *_refcountptr); 57 | } 58 | #endif 59 | LogInfoV(2, "copy %p\n", other._ptr); 60 | if (_refcountptr) 61 | { 62 | (*_refcountptr) ++; 63 | } 64 | else 65 | { 66 | LogErr("copying empty ref\n"); 67 | } 68 | _ptr = other._ptr; 69 | } 70 | refcountedptr_t(refcountedptr_t&& other) noexcept 71 | { 72 | _refcountptr = other._refcountptr; 73 | #ifdef DEBUG 74 | _length = other._length; 75 | _tid = std::this_thread::get_id(); 76 | #endif 77 | if (_refcountptr == nullptr) 78 | { 79 | LogErr("copying empty ref\n"); 80 | } 81 | 82 | LogInfoV(1, "move %p\n", other._ptr); 83 | other._refcountptr = nullptr; 84 | _ptr = other._ptr; 85 | } 86 | T* operator->() 87 | { 88 | PWASSERT(_refcountptr != nullptr, ""); 89 | return _ptr; 90 | } 91 | const T* operator->() const 92 | { 93 | PWASSERT(_refcountptr != nullptr, ""); 94 | return _ptr; 95 | } 96 | inline T& operator[](size_t index) 97 | { 98 | PWASSERT(_refcountptr != nullptr, ""); 99 | #ifdef DEBUG 100 | PWASSERT(index < _length, "out of bound access"); 101 | #endif 102 | return _ptr[index]; 103 | } 104 | inline const T& operator[](size_t index) const 105 | { 106 | PWASSERT(_refcountptr != nullptr, ""); 107 | #ifdef DEBUG 108 | PWASSERT(index < _length, "out of bound access"); 109 | #endif 110 | return _ptr[index]; 111 | } 112 | T* getptr() 113 | { 114 | PWASSERT(_refcountptr != nullptr, ""); 115 | return _ptr; 116 | } 117 | const T* getptr() const 118 | { 119 | PWASSERT(_refcountptr != nullptr, ""); 120 | return _ptr; 121 | } 122 | ~refcountedptr_t() 123 | { 124 | if (_refcountptr == nullptr) 125 | { 126 | LogInfoV(1,"delete empty ref %s:%u\n", __FILE__, __LINE__); 127 | return; 128 | } 129 | 130 | if (*_refcountptr == 1) 131 | { 132 | LogInfoV(2, "release %p\n", _ptr); 133 | #ifdef DEBUG 134 | PWASSERT(_tid == std::this_thread::get_id(), "tid mismatch!"); 135 | #endif 136 | allocator_t::get_instance()->deallocate(_ptr); 137 | allocator_t::get_instance()->deallocate(_refcountptr); 138 | } 139 | else 140 | { 141 | (*_refcountptr) --; 142 | } 143 | } 144 | 145 | private: 146 | T* _ptr; 147 | size_t *_refcountptr; 148 | #ifdef DEBUG 149 | size_t _length; 150 | std::thread::id _tid; 151 | #endif 152 | }; 153 | -------------------------------------------------------------------------------- /src/Variant.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | 16 | #include 17 | 18 | class funcbase_t 19 | { 20 | public: 21 | virtual funcbase_t* copy() = 0; 22 | virtual ~funcbase_t() {} 23 | }; 24 | template 25 | class func_t : public funcbase_t 26 | { 27 | public: 28 | typedef std::function fn_t; 29 | func_t(const func_t& oth) = default; 30 | func_t(func_t&& func) = default; 31 | func_t(fn_t& fn) 32 | { 33 | _fn=fn; 34 | } 35 | funcbase_t* copy() override 36 | { 37 | return new func_t(_fn); 38 | } 39 | T call(Args&... args) 40 | { 41 | return _fn(args...); 42 | } 43 | T call(Args&&... args) 44 | { 45 | return _fn(args...); 46 | } 47 | fn_t& get_func() 48 | { 49 | return _fn; 50 | } 51 | private: 52 | fn_t _fn; 53 | }; 54 | 55 | struct variant_t 56 | { 57 | std::string strval; 58 | funcbase_t* funcval; 59 | double dblval; 60 | int intval; 61 | void* ptrval; 62 | 63 | template 64 | variant_t(std::function func) 65 | { 66 | init(); 67 | funcval = new func_t(func); 68 | } 69 | variant_t(void* ptr) 70 | { 71 | init(); 72 | ptrval = ptr; 73 | } 74 | variant_t(const char* str) 75 | { 76 | init(); 77 | strval = std::string(str); 78 | } 79 | variant_t(const std::string& str) 80 | { 81 | init(); 82 | strval = str; 83 | } 84 | variant_t(double dbl) 85 | { 86 | init(); 87 | dblval = dbl; 88 | } 89 | variant_t(int i) 90 | { 91 | init(); 92 | intval = i; 93 | } 94 | void init() 95 | { 96 | strval = ""; 97 | funcval = nullptr; 98 | dblval = 0.0; 99 | intval = 0; 100 | ptrval = nullptr; 101 | } 102 | void* get_void_ptr() const { return ptrval; } 103 | int get_int() const { return intval; } 104 | double get_double() const { return dblval; } 105 | const std::string& get_string() const { return strval; } 106 | template 107 | std::function& get_func() const 108 | { 109 | PWASSERT(funcval != nullptr, "no func!"); 110 | auto ptr = dynamic_cast*>(funcval); 111 | PWASSERT(ptr != nullptr, "dynamic_cast failed"); 112 | return ptr->get_func(); 113 | } 114 | variant_t() = default; 115 | variant_t(const variant_t& oth) 116 | { 117 | strval = oth.strval; 118 | dblval = oth.dblval; 119 | intval = oth.intval; 120 | ptrval = oth.ptrval; 121 | funcval = nullptr; 122 | if (oth.funcval != nullptr) 123 | { 124 | funcval = oth.funcval->copy(); 125 | } 126 | } 127 | variant_t(variant_t&& oth) 128 | { 129 | strval = std::move(oth.strval); 130 | dblval = oth.dblval; 131 | intval = oth.intval; 132 | funcval = oth.funcval; 133 | oth.funcval = nullptr; 134 | } 135 | template 136 | T call(Args&&... args) 137 | { 138 | auto ptr = dynamic_cast*>(funcval); 139 | PWASSERT(ptr != nullptr, "dynamic_cast failed"); 140 | return ptr->call(args...); 141 | } 142 | 143 | template 144 | T call(Args&... args) 145 | { 146 | auto ptr = dynamic_cast*>(funcval); 147 | PWASSERT(ptr != nullptr, "dynamic_cast failed"); 148 | return ptr->call(args...); 149 | } 150 | void operator=(const variant_t& oth) 151 | { 152 | dblval = oth.dblval; 153 | intval = oth.intval; 154 | funcval = oth.funcval; 155 | strval = oth.strval; 156 | } 157 | ~variant_t() 158 | { 159 | if (funcval) 160 | { 161 | delete funcval; 162 | } 163 | } 164 | }; 165 | -------------------------------------------------------------------------------- /src/TraceUtils.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 University of Adelaide 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #include "TraceUtils.h" 15 | #include "Log.h" 16 | #include "Trace.h" 17 | #include "WorkContext.h" 18 | 19 | int __pwtraceutils_data_groups = -1; 20 | 21 | 22 | static void copydata(const trace_t *fromtrace, const traceinfo_t *fromti, 23 | trace_t *totrace, const traceinfo_t *toti) 24 | { 25 | if (fromti->ndata > 0) 26 | { 27 | if (fromti->ndata == toti->ndata) 28 | { 29 | memcpy(&totrace->_data[0], &fromtrace->_data[0], toti->ndata * sizeof(uint8_t)); 30 | } 31 | else 32 | { 33 | LogErrDie("Can't copy data due to data buffer size mismatch!\n"); 34 | } 35 | } 36 | } 37 | 38 | int traceutils_groups_count() 39 | { 40 | if (__pwtraceutils_data_groups == -1) 41 | { 42 | if (wc_gopts_has("data_groups_count")) 43 | { 44 | __pwtraceutils_data_groups = wc_gopts_get("data_groups_count").get_int(); 45 | /*if (__pwtraceutils_data_groups == 0) 46 | { 47 | LogErrDie("Group count must be non zero\n"); 48 | }*/ 49 | } 50 | else 51 | { 52 | __pwtraceutils_data_groups = 2; 53 | } 54 | } 55 | return __pwtraceutils_data_groups; 56 | } 57 | void traceutils_extract_term(const trace_t* trace, trace_t *termtrace, uint32_t term_id, 58 | const traceinfo_t* traceinfo, const traceinfo_t* termtraceinfo) 59 | { 60 | auto nsamples = traceinfo->nsamples; 61 | if (term_id >= traceinfo->nterms) 62 | { 63 | LogErr("invalid term id\n"); 64 | } 65 | 66 | for (auto i=0u;i_samples[i] = trace->_samples[nsamples*term_id + i]; 69 | } 70 | 71 | copydata(trace, traceinfo, termtrace, termtraceinfo); 72 | } 73 | uint32_t traceutils_biv_combine(const trace_t *trace, trace_t *combinedtrace, 74 | const traceinfo_t* traceinfo, const traceinfo_t* combinedtraceinfo) 75 | { 76 | uint32_t nsamples = traceinfo->nsamples; 77 | uint32_t cc=0; 78 | 79 | for (auto i=0u;i_samples[cc] = trace->_samples[i]*trace->_samples[j]; 84 | cc ++; 85 | } 86 | } 87 | 88 | copydata(trace, traceinfo, combinedtrace, combinedtraceinfo); 89 | return cc; 90 | } 91 | uint32_t traceutils_triv_combine(const trace_t *trace, trace_t *combinedtrace, 92 | const traceinfo_t* traceinfo, const traceinfo_t* combinedtraceinfo) 93 | { 94 | uint32_t nsamples = traceinfo->nsamples; 95 | uint32_t cc=0; 96 | 97 | for (auto i=0u;i_samples[cc] = trace->_samples[i]*trace->_samples[j]*trace->_samples[k]; 104 | cc ++; 105 | } 106 | } 107 | } 108 | copydata(trace, traceinfo, combinedtrace, combinedtraceinfo); 109 | return cc; 110 | } 111 | 112 | uint32_t traceutils_biv_combine2h(const trace_t *trace, trace_t *combinedtrace, 113 | const traceinfo_t* traceinfo, const traceinfo_t* combinedtraceinfo) 114 | { 115 | uint32_t nsamples = traceinfo->nsamples; 116 | uint32_t nsamples_mid = nsamples/2; 117 | uint32_t cc=0; 118 | for (auto i=0u;i_samples[cc] = trace->_samples[i]*trace->_samples[nsamples_mid+j]; 123 | cc ++; 124 | } 125 | } 126 | copydata(trace, traceinfo, combinedtrace, combinedtraceinfo); 127 | return cc; 128 | } 129 | void traceutils_diff(trace_t* a, trace_t* b) 130 | { 131 | uint32_t nsamples = a->_traceinfo.nsamples; 132 | for (auto i=0u;i_samples[i] = a->_samples[i] - b->_samples[i]; 135 | } 136 | } 137 | --------------------------------------------------------------------------------