# HG changeset patch # User František Kučera # Date 1580079807 -3600 # Node ID 7ba9d703fadb1679623c6e1585b38cc9a642605d # Parent 8c6885543e2c75f033487d5df9816d47c08c2f62 streamlet examples: pid diff -r 8c6885543e2c -r 7ba9d703fadb streamlet-examples/pid.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/streamlet-examples/pid.cpp Mon Jan 27 00:03:27 2020 +0100 @@ -0,0 +1,53 @@ +/** + * Relational pipes + * Copyright © 2020 František Kučera (Frantovo.cz, GlobalCode.info) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "streamlet-common.h" + +#include + +/** + * This streamlet is useful only for debugging or study purposes. + * + * It provides two attributes: + * - pid_streamlet: getpid() + * - pid_worker: getppid() + * + * Can be used for studying how the parallelism works: + * - Each instance of streamlet (each --streamlet pid) will have different pid_streamlet. + * - Each worker (their number = X in --parallelism X) will have different pid_worker. + * + * So we can check how evenly the work has been distributed across processes (e.g. do some GROUP BY in SQL). + */ +class PidStreamlet : public Streamlet { + + std::vector getOutputAttributesMetadata() override { + std::vector oam; + int i = 0; + oam.push_back({getAlias(i++, L"pid_streamlet"), INTEGER}); + oam.push_back({getAlias(i++, L"pid_worker"), INTEGER}); + return oam; + } + + std::vector getOutputAttributes() override { + std::vector oa; + oa.push_back({std::to_wstring(getpid()), false}); + oa.push_back({std::to_wstring(getppid()), false}); + return oa; + } +}; + +STREAMLET_RUN(PidStreamlet)