Skip to content

Commit 5575327

Browse files
committed
optimize version print
1 parent 229e31c commit 5575327

File tree

15 files changed

+108
-57
lines changed

15 files changed

+108
-57
lines changed

.github/workflows/cpp_full_node_workflow.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ jobs:
6666
export GCC='gcc-10'
6767
export CXX='g++-10'
6868
sudo bash -x cpp/tools/install_depends.sh -o ubuntu
69-
mkdir -p cpp/build && cd cpp/build && cmake -DTESTS=ON -DCOVERAGE=ON -DCMAKE_TOOLCHAIN_FILE=${{ env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake ../
69+
mkdir -p cpp/build && cd cpp/build && cmake -DBUILD_STATIC=ON -DTESTS=ON -DCOVERAGE=ON -DCMAKE_TOOLCHAIN_FILE=${{ env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake ../
7070
make -j3
7171
- name: Build for macOS
7272
if: runner.os == 'macOS'
7373
run: |
7474
bash -x cpp/tools/install_depends.sh -o macos
75-
mkdir -p cpp/build && cd cpp/build && cmake -DTESTS=ON -DCOVERAGE=ON -DCMAKE_TOOLCHAIN_FILE=${{ env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake ../
75+
mkdir -p cpp/build && cd cpp/build && cmake -DBUILD_STATIC=ON -DTESTS=ON -DCOVERAGE=ON -DCMAKE_TOOLCHAIN_FILE=${{ env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake ../
7676
make -j3
7777
- uses: actions/upload-artifact@v4
7878
if: runner.os == 'macOS'
@@ -163,7 +163,7 @@ jobs:
163163
rm -rf python
164164
mkdir -p cpp/build
165165
cd cpp/build
166-
cmake3 -DCMAKE_BUILD_TYPE=Release -DTESTS=ON -DCMAKE_TOOLCHAIN_FILE=/usr/local/share/vcpkg/scripts/buildsystems/vcpkg.cmake ../
166+
cmake3 -DBUILD_STATIC=ON -DCMAKE_BUILD_TYPE=Release -DTESTS=ON -DCMAKE_TOOLCHAIN_FILE=/usr/local/share/vcpkg/scripts/buildsystems/vcpkg.cmake ../
167167
- name: FreeDiskSpace
168168
run: |
169169
df -lh

cpp/cmake/CompilerSettings.cmake

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,12 @@ if (("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") OR ("${CMAKE_CXX_COMPILER_ID}" MA
9595
if (NOT (GCC_VERSION VERSION_GREATER ${GCC_MIN_VERSION} OR GCC_VERSION VERSION_EQUAL ${GCC_MIN_VERSION}))
9696
message(FATAL_ERROR "${PROJECT_NAME} requires g++ ${GCC_MIN_VERSION} or greater. Current is ${GCC_VERSION}")
9797
endif ()
98-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MARCH_TYPE}")
98+
if(BUILD_STATIC)
99+
# solve multiple definition of `__lll_lock_wait_private'
100+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MARCH_TYPE} -ftree-parallelize-loops=2 -flto")
101+
else()
102+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MARCH_TYPE}")
103+
endif()
99104
set(CMAKE_C_FLAGS "-std=c99 -fexceptions ${CMAKE_C_FLAGS} ${MARCH_TYPE}")
100105

101106
# Strong stack protection was only added in GCC 4.9.

cpp/ppc-framework/protocol/GrpcConfig.h

Lines changed: 53 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,6 @@
2626

2727
namespace ppc::protocol
2828
{
29-
class GrpcServerConfig
30-
{
31-
public:
32-
using Ptr = std::shared_ptr<GrpcServerConfig>;
33-
GrpcServerConfig() = default;
34-
GrpcServerConfig(EndPoint endPoint, bool enableHealthCheck)
35-
: m_endPoint(std::move(endPoint)), m_enableHealthCheck(enableHealthCheck)
36-
{}
37-
std::string listenEndPoint() const { return m_endPoint.listenEndPoint(); }
38-
39-
void setEndPoint(EndPoint endPoint) { m_endPoint = endPoint; }
40-
void setEnableHealthCheck(bool enableHealthCheck) { m_enableHealthCheck = enableHealthCheck; }
41-
42-
EndPoint const& endPoint() const { return m_endPoint; }
43-
EndPoint& mutableEndPoint() { return m_endPoint; }
44-
bool enableHealthCheck() const { return m_enableHealthCheck; }
45-
46-
protected:
47-
ppc::protocol::EndPoint m_endPoint;
48-
bool m_enableHealthCheck = true;
49-
};
5029
class GrpcConfig
5130
{
5231
public:
@@ -71,10 +50,22 @@ class GrpcConfig
7150

7251
void setMaxSendMessageSize(uint64_t maxSendMessageSize)
7352
{
53+
if (maxSendMessageSize > c_maxMsgSize)
54+
{
55+
BOOST_THROW_EXCEPTION(
56+
WeDPRException() << bcos::errinfo_comment(
57+
"The MaxSendMessageSize limit is " + std::to_string(c_maxMsgSize)));
58+
}
7459
m_maxSendMessageSize = maxSendMessageSize;
7560
}
7661
void setMaxReceivedMessageSize(uint64_t maxReceivedMessageSize)
7762
{
63+
if (maxReceivedMessageSize > c_maxMsgSize)
64+
{
65+
BOOST_THROW_EXCEPTION(
66+
WeDPRException() << bcos::errinfo_comment(
67+
"The MaxReceivedMessageSize limit is " + std::to_string(c_maxMsgSize)));
68+
}
7869
m_maxReceivedMessageSize = maxReceivedMessageSize;
7970
}
8071

@@ -103,13 +94,52 @@ class GrpcConfig
10394
std::string m_loadBalancePolicy = "round_robin";
10495
bool m_enableDnslookup = false;
10596

97+
uint64_t const c_maxMsgSize = 1024 * 1024 * 1024;
98+
10699
// the max send message size in bytes
107-
uint64_t m_maxSendMessageSize = 1024 * 1024 * 1024;
100+
uint64_t m_maxSendMessageSize = c_maxMsgSize;
108101
// the max received message size in bytes
109-
uint64_t m_maxReceivedMessageSize = 1024 * 1024 * 1024;
102+
uint64_t m_maxReceivedMessageSize = c_maxMsgSize;
110103
int m_compressAlgorithm = 0;
111104
};
112105

106+
class GrpcServerConfig : public GrpcConfig
107+
{
108+
public:
109+
using Ptr = std::shared_ptr<GrpcServerConfig>;
110+
GrpcServerConfig() = default;
111+
GrpcServerConfig(EndPoint endPoint, bool enableHealthCheck)
112+
: m_endPoint(std::move(endPoint)), m_enableHealthCheck(enableHealthCheck)
113+
{}
114+
~GrpcServerConfig() override = default;
115+
116+
std::string listenEndPoint() const { return m_endPoint.listenEndPoint(); }
117+
118+
void setEndPoint(EndPoint endPoint) { m_endPoint = endPoint; }
119+
void setEnableHealthCheck(bool enableHealthCheck) { m_enableHealthCheck = enableHealthCheck; }
120+
121+
EndPoint const& endPoint() const { return m_endPoint; }
122+
EndPoint& mutableEndPoint() { return m_endPoint; }
123+
bool enableHealthCheck() const { return m_enableHealthCheck; }
124+
125+
uint64_t maxMsgSize() const { return m_maxMsgSize; }
126+
void setMaxMsgSize(uint64_t maxMsgSize)
127+
{
128+
if (maxMsgSize > c_maxMsgSize)
129+
{
130+
BOOST_THROW_EXCEPTION(WeDPRException() << bcos::errinfo_comment(
131+
"The maxMsgSize limit is " + std::to_string(c_maxMsgSize)));
132+
}
133+
m_maxMsgSize = maxMsgSize;
134+
}
135+
136+
protected:
137+
ppc::protocol::EndPoint m_endPoint;
138+
bool m_enableHealthCheck = true;
139+
uint64_t m_maxMsgSize = c_maxMsgSize;
140+
};
141+
142+
113143
inline std::string printGrpcConfig(ppc::protocol::GrpcConfig::Ptr const& grpcConfig)
114144
{
115145
if (!grpcConfig)

cpp/wedpr-helper/libhelper/CommandHelper.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@
2626

2727
using namespace ppc;
2828

29-
void ppc::printVersion()
29+
void ppc::printVersion(std::string const& binaryName)
3030
{
31-
std::cout << "PPCS-Core Version : " << PPC_PROJECT_VERSION << std::endl;
31+
std::cout << binaryName << " Version : " << PPC_PROJECT_VERSION << std::endl;
3232
std::cout << "Build Time : " << PPC_BUILD_TIME << std::endl;
3333
std::cout << "Build Type : " << PPC_BUILD_PLATFORM << "/" << PPC_BUILD_TYPE
3434
<< std::endl;
3535
std::cout << "Git Branch : " << PPC_BUILD_BRANCH << std::endl;
3636
std::cout << "Git Commit : " << PPC_COMMIT_HASH << std::endl;
3737
}
3838

39-
CommandLineParam ppc::initCommandLine(int argc, const char* argv[])
39+
CommandLineParam ppc::initCommandLine(std::string const& binaryName, int argc, const char* argv[])
4040
{
4141
boost::program_options::options_description main_options("Usage of PPC");
4242
main_options.add_options()("help,h", "print help information")("version,v", "version of PPC")(
@@ -49,7 +49,7 @@ CommandLineParam ppc::initCommandLine(int argc, const char* argv[])
4949
}
5050
catch (...)
5151
{
52-
printVersion();
52+
printVersion(binaryName);
5353
}
5454
/// help information
5555
if (vm.count("help") || vm.count("h"))
@@ -60,7 +60,7 @@ CommandLineParam ppc::initCommandLine(int argc, const char* argv[])
6060
/// version information
6161
if (vm.count("version") || vm.count("v"))
6262
{
63-
printVersion();
63+
printVersion(binaryName);
6464
exit(0);
6565
}
6666
std::string configPath("./config.ini");

cpp/wedpr-helper/libhelper/CommandHelper.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ struct CommandLineParam
2727
{
2828
std::string configFilePath;
2929
};
30-
void printVersion();
31-
CommandLineParam initCommandLine(int argc, const char* argv[]);
30+
void printVersion(std::string const& binaryName);
31+
CommandLineParam initCommandLine(std::string const& binaryName, int argc, const char* argv[]);
3232
} // namespace ppc

cpp/wedpr-main/air-node/main.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222

2323
int main(int argc, const char* argv[])
2424
{
25-
auto initializer = std::make_shared<ppc::node::AirNodeInitializer>();
26-
startProgram(argc, argv, "ppc-psi", initializer);
25+
std::string binaryName = "ppc-psi";
26+
auto initializer = std::make_shared<ppc::node::AirNodeInitializer>();
27+
auto ret = startProgram(argc, argv, binaryName, initializer);
28+
initializer.reset();
29+
std::cout << "[" << bcos::getCurrentDateTime() << "] ";
30+
std::cout << "The " << binaryName << " program exit normally." << std::endl;
31+
return ret;
2732
}

cpp/wedpr-main/cem-node/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,19 @@ int main(int argc, const char* argv[])
5353
auto initializer = std::make_shared<ppc::cem::CEMInitializer>();
5454
try
5555
{
56-
auto param = initCommandLine(argc, argv);
56+
auto param = initCommandLine("wedpr-cem", argc, argv);
5757
initializer->init(param.configFilePath);
5858
initializer->start();
5959
}
6060
catch (std::exception const& e)
6161
{
62-
printVersion();
62+
printVersion("wedpr-cem");
6363
std::cout << "[" << bcos::getCurrentDateTime() << "] ";
6464
std::cout << "start ppc-cem failed, error:" << boost::diagnostic_information(e)
6565
<< std::endl;
6666
return -1;
6767
}
68-
printVersion();
68+
printVersion("wedpr-cem");
6969
std::cout << "[" << bcos::getCurrentDateTime() << "] ";
7070
std::cout << "The ppc-cem is running..." << std::endl;
7171
while (!exitHandler.shouldExit())

cpp/wedpr-main/common/NodeStarter.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ int startProgram(
3434
/// set LC_ALL
3535
setDefaultOrCLocale();
3636
std::set_terminate([]() {
37-
std::cerr << "terminate handler called, print stacks" << std::endl;
37+
std::cout << "terminate handler called, print stacks" << std::endl;
3838
void* trace_elems[20];
3939
int trace_elem_count(backtrace(trace_elems, 20));
4040
char** stack_syms(backtrace_symbols(trace_elems, trace_elem_count));
@@ -43,7 +43,7 @@ int startProgram(
4343
std::cout << stack_syms[i] << "\n";
4444
}
4545
free(stack_syms);
46-
std::cerr << "terminate handler called, print stack end" << std::endl;
46+
std::cout << "terminate handler called, print stack end" << std::endl;
4747
abort();
4848
});
4949
// get datetime and output welcome info
@@ -55,27 +55,25 @@ int startProgram(
5555
// Note: the initializer must exist in the life time of the whole program
5656
try
5757
{
58-
auto param = ppc::initCommandLine(argc, argv);
58+
auto param = ppc::initCommandLine(binaryName, argc, argv);
5959
starter->init(param.configFilePath);
6060
starter->start();
6161
}
6262
catch (std::exception const& e)
6363
{
64-
printVersion();
64+
printVersion(binaryName);
6565
std::cout << "[" << bcos::getCurrentDateTime() << "] ";
6666
std::cout << "start " + binaryName + " failed, error:" << boost::diagnostic_information(e)
6767
<< std::endl;
6868
return -1;
6969
}
70-
printVersion();
70+
printVersion(binaryName);
7171
std::cout << "[" << bcos::getCurrentDateTime() << "] ";
7272
std::cout << "The " + binaryName + " is running..." << std::endl;
7373
while (!exitHandler.shouldExit())
7474
{
7575
std::this_thread::sleep_for(std::chrono::milliseconds(200));
7676
}
77-
starter.reset();
78-
std::cout << "[" << bcos::getCurrentDateTime() << "] ";
79-
std::cout << "The " + binaryName + " program exit normally." << std::endl;
77+
return 0;
8078
}
8179
} // namespace ppc::node

cpp/wedpr-main/gateway/main.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323
using namespace ppc::node;
2424
int main(int argc, const char* argv[])
2525
{
26+
std::string binaryName = "ppc-gateway-service";
2627
auto initializer = std::make_shared<ppc::gateway::GatewayInitializer>();
27-
startProgram(argc, argv, "ppc-gateway-service", initializer);
28+
auto ret = startProgram(argc, argv, binaryName, initializer);
29+
initializer.reset();
30+
std::cout << "[" << bcos::getCurrentDateTime() << "] ";
31+
std::cout << "The " << binaryName << " program exit normally." << std::endl;
32+
return ret;
2833
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
aux_source_directory(. SRC_LIST)
22

33
add_executable(${MPC_BINARY_NAME} ${SRC_LIST})
4-
target_link_libraries(${MPC_BINARY_NAME} PUBLIC ${MPC_TARGET} ${RPC_TARGET} ${HELPER_TARGET} ${WEDPR_TRANSPORT_SDK_TARGET} TBB::tbb)
4+
target_link_libraries(${MPC_BINARY_NAME} PUBLIC ${WEDPR_TRANSPORT_SDK_TARGET} ${MPC_TARGET} ${RPC_TARGET} ${HELPER_TARGET} TBB::tbb)

0 commit comments

Comments
 (0)