Skip to content

Commit 33f80dd

Browse files
committed
lib: cmetrics: upgrade to git 38e98f657
Signed-off-by: Eduardo Silva <[email protected]>
1 parent c7195dc commit 33f80dd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+3228
-198
lines changed

lib/cmetrics/.github/workflows/build.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
max-parallel: 48
1616
fail-fast: false
1717
matrix:
18-
os: [windows-latest]
18+
os: [windows-latest, windows-2019]
1919
steps:
2020
- uses: actions/checkout@v2
2121
- name: Build on ${{ matrix.os }} with vs-2019
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
on:
2+
push:
3+
branches:
4+
- master
5+
6+
name: Build packages for master
7+
jobs:
8+
build-distro-packages:
9+
name: build packages
10+
strategy:
11+
fail-fast: true
12+
matrix:
13+
format: [ rpm, deb ]
14+
15+
runs-on: [ ubuntu-latest ]
16+
steps:
17+
- uses: actions/checkout@v2
18+
- name: Build the ${{matrix.format}} packages
19+
run: |
20+
cmake .
21+
echo ${{ matrix.format }} | awk '{print toupper($0)}' | xargs -I{} cpack -G {}
22+
23+
- name: Store the master package artifacts
24+
uses: actions/upload-artifact@v2
25+
with:
26+
name: ${{ matrix.format }}
27+
path: |
28+
./*.${{matrix.format}}

lib/cmetrics/CMakeLists.txt

+150-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
cmake_minimum_required(VERSION 2.8)
22
project(cmetrics C)
3+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
4+
5+
# Define macro to identify Windows system (without Cygwin)
6+
if(CMAKE_SYSTEM_NAME MATCHES "Windows")
7+
set(CMT_SYSTEM_WINDOWS On)
8+
add_definitions(-DCMT_SYSTEM_WINDOWS)
9+
endif()
310

411
# CMetrics Version
512
set(CMT_VERSION_MAJOR 0)
@@ -10,10 +17,12 @@ set(CMT_VERSION_STR "${CMT_VERSION_MAJOR}.${CMT_VERSION_MINOR}.${CMT_VERSION_PAT
1017
# Include helpers
1118
include(cmake/macros.cmake)
1219
include(CheckCSourceCompiles)
20+
include(GNUInstallDirs)
1321

1422
# Configuration options
15-
option(CMT_DEV "Enable development mode" No)
16-
option(CMT_TESTS "Enable unit testing" No)
23+
option(CMT_DEV "Enable development mode" No)
24+
option(CMT_TESTS "Enable unit testing" No)
25+
option(CMT_INSTALL_TARGETS "Enable subdirectory library installations" Yes)
1726

1827
if(CMT_DEV)
1928
set(CMT_TESTS Yes)
@@ -37,6 +46,30 @@ if(CMT_HAVE_TIMESPEC_GET)
3746
CMT_DEFINITION(CMT_HAVE_TIMESPEC_GET)
3847
endif()
3948

49+
# gmtime_r() support
50+
check_c_source_compiles("
51+
#include <time.h>
52+
int main() {
53+
struct tm tm;
54+
struct timespec tms;
55+
return gmtime_r(&tms.tv_sec, &tm);
56+
}" CMT_HAVE_GMTIME_R)
57+
if(CMT_HAVE_GMTIME_R)
58+
CMT_DEFINITION(CMT_HAVE_GMTIME_R)
59+
endif()
60+
61+
# gmtime_s() support
62+
check_c_source_compiles("
63+
#include <time.h>
64+
int main() {
65+
struct tm tm;
66+
struct timespec tms;
67+
return gmtime_s(&tm, &tms.tv_sec);
68+
}" CMT_HAVE_GMTIME_S)
69+
if(CMT_HAVE_GMTIME_S)
70+
CMT_DEFINITION(CMT_HAVE_GMTIME_S)
71+
endif()
72+
4073
# clock_get_time() support for macOS.
4174
check_c_source_compiles("
4275
#include <mach/clock.h>
@@ -66,26 +99,141 @@ configure_file(
6699
"${PROJECT_SOURCE_DIR}/include/cmetrics/cmt_info.h"
67100
)
68101

102+
# Installation Directories
103+
# ========================
104+
if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
105+
set(CMT_INSTALL_LIBDIR "lib")
106+
set(CMT_INSTALL_INCLUDEDIR "include")
107+
else()
108+
set(CMT_INSTALL_LIBDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
109+
set(CMT_INSTALL_INCLUDEDIR "${CMAKE_INSTALL_PREFIX}/include")
110+
endif()
111+
69112
# xxHash
70113
if(NOT TARGET xxhash)
71114
# Do something when target found
72115
set(XXHASH_BUILD_ENABLE_INLINE_API OFF)
73116
set(XXHASH_BUILD_XXHSUM OFF)
74117
set(BUILD_SHARED_LIBS OFF)
75118
add_subdirectory(lib/xxHash-0.8.0/cmake_unofficial EXCLUDE_FROM_ALL)
119+
120+
if (CMT_INSTALL_TARGETS)
121+
install(TARGETS xxhash
122+
RUNTIME DESTINATION ${CMT_INSTALL_BINDIR}
123+
LIBRARY DESTINATION ${CMT_INSTALL_LIBDIR}
124+
ARCHIVE DESTINATION ${CMT_INSTALL_LIBDIR}
125+
COMPONENT library)
126+
endif()
76127
endif()
77128

78129
# mpack
79130
if(NOT TARGET mpack-static)
80131
include_directories(lib/mpack/src/)
81132
add_subdirectory(lib/mpack EXCLUDE_FROM_ALL)
133+
134+
if (CMT_INSTALL_TARGETS)
135+
install(TARGETS mpack-static
136+
RUNTIME DESTINATION ${CMT_INSTALL_BINDIR}
137+
LIBRARY DESTINATION ${CMT_INSTALL_LIBDIR}
138+
ARCHIVE DESTINATION ${CMT_INSTALL_LIBDIR}
139+
COMPONENT library)
140+
141+
install(FILES lib/mpack/src/mpack/mpack.h
142+
DESTINATION ${CMT_INSTALL_INCLUDEDIR}/mpack
143+
COMPONENT headers
144+
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
145+
endif()
82146
endif()
83147

84148
# Source code
149+
add_subdirectory(include)
85150
add_subdirectory(src)
151+
add_subdirectory(lib/monkey/include)
86152

87153
# Tests
88154
if(CMT_TESTS)
89155
enable_testing()
90156
add_subdirectory(tests)
91157
endif()
158+
159+
# Installer Generation (Cpack)
160+
# ============================
161+
162+
set(CPACK_PACKAGE_VERSION ${CMT_VERSION_STR})
163+
set(CPACK_PACKAGE_NAME "cmetrics")
164+
set(CPACK_PACKAGE_RELEASE 1)
165+
set(CPACK_PACKAGE_CONTACT "Eduardo Silva <[email protected]>")
166+
set(CPACK_PACKAGE_VENDOR "Calyptia")
167+
set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")
168+
set(CPACK_PACKAGING_INSTALL_PREFIX "/")
169+
170+
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_PACKAGE_RELEASE}.${CMAKE_SYSTEM_PROCESSOR}")
171+
172+
if(CMT_SYSTEM_WINDOWS)
173+
set(CPACK_GENERATOR "ZIP")
174+
175+
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
176+
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-win64")
177+
else()
178+
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-win32")
179+
endif()
180+
endif()
181+
182+
183+
# Enable components
184+
set(CPACK_DEB_COMPONENT_INSTALL ON)
185+
set(CPACK_RPM_COMPONENT_INSTALL ON)
186+
set(CPACK_COMPONENTS_ALL ${CPACK_COMPONENTS_ALL} binary library headers)
187+
set(CPACK_COMPONENTS_GROUPING "ONE_PER_GROUP")
188+
189+
set(CPACK_COMPONENT_BINARY_GROUP "RUNTIME")
190+
set(CPACK_COMPONENT_LIBRARY_GROUP "RUNTIME")
191+
192+
# Debian package setup and name sanitizer
193+
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
194+
195+
find_program(DPKG_PROGRAM dpkg DOC "dpkg program of Debian-based systems")
196+
if(DPKG_PROGRAM)
197+
execute_process(
198+
COMMAND ${DPKG_PROGRAM} --print-architecture
199+
OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE
200+
OUTPUT_STRIP_TRAILING_WHITESPACE
201+
)
202+
203+
set(CPACK_DEBIAN_HEADERS_FILE_NAME "${CPACK_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}-headers.deb")
204+
set(CPACK_DEBIAN_RUNTIME_PACKAGE_NAME "${CPACK_PACKAGE_NAME}")
205+
set(CPACK_DEBIAN_RUNTIME_FILE_NAME "${CPACK_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}.deb")
206+
set(CPACK_DEBIAN_RUNTIME_PACKAGE_CONTROL_EXTRA
207+
${CMAKE_CURRENT_SOURCE_DIR}/debian/conffiles
208+
)
209+
endif()
210+
211+
# RPM Generation information
212+
set(CPACK_RPM_PACKAGE_GROUP "System Environment/Daemons")
213+
set(CPACK_RPM_PACKAGE_LICENSE "Apache v2.0")
214+
set(CPACK_RPM_PACKAGE_RELEASE ${CPACK_PACKAGE_RELEASE})
215+
set(CPACK_PACKAGE_DESCRIPTION_FILE "${PROJECT_SOURCE_DIR}/cpack/description")
216+
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Fast data collector for Linux")
217+
set(CPACK_RPM_SPEC_MORE_DEFINE "%define ignore \#")
218+
set(CPACK_RPM_USER_FILELIST
219+
"%ignore /lib"
220+
"%ignore /lib64"
221+
"%ignore /lib64/pkgconfig"
222+
"%ignore /usr/local"
223+
"%ignore /usr/local/bin")
224+
225+
set(CPACK_RPM_PACKAGE_AUTOREQ ON)
226+
set(CPACK_RPM_RUNTIME_PACKAGE_NAME "${CPACK_PACKAGE_NAME}")
227+
set(CPACK_RPM_HEADERS_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_PACKAGE_RELEASE}.${CMAKE_SYSTEM_PROCESSOR}-headers.rpm")
228+
set(CPACK_RPM_RUNTIME_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_PACKAGE_RELEASE}.${CMAKE_SYSTEM_PROCESSOR}.rpm")
229+
230+
# CPack: DEB
231+
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
232+
233+
# CPack: Windows System
234+
if(CPACK_GENERATOR MATCHES "ZIP")
235+
set(CPACK_MONOLITHIC_INSTALL 1)
236+
set(CPACK_PACKAGE_INSTALL_DIRECTORY "cmetrics")
237+
endif()
238+
239+
include(CPack)

lib/cmetrics/appveyor.yml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
version: v1-winbuild-{build}
2+
3+
image: Visual Studio 2019
4+
5+
platform:
6+
- Win32
7+
- x64
8+
9+
environment:
10+
vspath: 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Community'
11+
12+
configuration:
13+
- Release
14+
15+
skip_commits:
16+
message: /workflows/
17+
files:
18+
- '.github/**'
19+
20+
before_build:
21+
- if %PLATFORM%==Win32 call "%vspath%\VC\Auxiliary\Build\vcvars32.bat"
22+
- if %PLATFORM%==x64 call "%vspatH%\VC\Auxiliary\Build\vcvars64.bat"
23+
24+
build_script:
25+
- .\scripts\win_build.bat
26+
- ctest -C Debug --test-dir .\tests\

lib/cmetrics/cpack/description

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
A standalone library to create and manipulate metrics in C.

lib/cmetrics/include/CMakeLists.txt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
file(GLOB headers "cmetrics/*.h")
2+
install(FILES ${headers}
3+
DESTINATION ${CMT_INSTALL_INCLUDEDIR}/cmetrics
4+
COMPONENT headers
5+
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)

lib/cmetrics/include/cmetrics/cmetrics.h

+8
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,30 @@
3333
#include <monkey/mk_core/mk_list.h>
3434

3535
#include <cmetrics/cmt_info.h>
36+
#include <cmetrics/cmt_compat.h>
3637
#include <cmetrics/cmt_math.h>
3738
#include <cmetrics/cmt_time.h>
3839
#include <cmetrics/cmt_sds.h>
40+
#include <cmetrics/cmt_label.h>
3941

4042
struct cmt {
4143
/* logging */
4244
int log_level;
4345
void (*log_cb)(void *, int, const char *, int, const char *);
4446

47+
/* static labels */
48+
struct cmt_labels *static_labels;
49+
4550
/* Metrics list */
4651
struct mk_list counters;
4752
struct mk_list gauges;
4853
struct mk_list histograms;
4954
};
5055

56+
void cmt_initialize();
57+
5158
struct cmt *cmt_create();
5259
void cmt_destroy(struct cmt *cmt);
60+
int cmt_label_add(struct cmt *cmt, char *key, char *val);
5361

5462
#endif
+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2+
3+
/* CMetrics
4+
* ========
5+
* Copyright 2021 Eduardo Silva <[email protected]>
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
#ifndef CMT_COMPAT_H
21+
#define CMT_COMPAT_H
22+
23+
#include <time.h>
24+
#ifdef _WIN32
25+
#include <windows.h>
26+
#endif
27+
28+
static inline struct tm *cmt_platform_gmtime_r(const time_t *timep, struct tm *result)
29+
{
30+
#ifdef CMT_HAVE_GMTIME_S
31+
if (gmtime_s(result, timep)) {
32+
return NULL;
33+
}
34+
35+
return result;
36+
#else
37+
/* FIXME: Need to handle gmtime_r(3) lacking platform? */
38+
return gmtime_r(timep, result) ;
39+
#endif
40+
}
41+
42+
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2+
3+
/* CMetrics
4+
* ========
5+
* Copyright 2021 Eduardo Silva <[email protected]>
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
21+
#ifndef CMT_DECODE_MSGPACK_H
22+
#define CMT_DECODE_MSGPACK_H
23+
24+
#include <cmetrics/cmetrics.h>
25+
#include <cmetrics/cmt_mpack_utils.h>
26+
27+
#define CMT_DECODE_MSGPACK_SUCCESS CMT_MPACK_SUCCESS
28+
#define CMT_DECODE_MSGPACK_INVALID_ARGUMENT_ERROR CMT_MPACK_INVALID_ARGUMENT_ERROR
29+
#define CMT_DECODE_MSGPACK_ALLOCATION_ERROR CMT_MPACK_ALLOCATION_ERROR
30+
#define CMT_DECODE_MSGPACK_CORRUPT_INPUT_DATA_ERROR CMT_MPACK_CORRUPT_INPUT_DATA_ERROR
31+
#define CMT_DECODE_MSGPACK_CONSUME_ERROR CMT_MPACK_CONSUME_ERROR
32+
#define CMT_DECODE_MSGPACK_ENGINE_ERROR CMT_MPACK_ENGINE_ERROR
33+
#define CMT_DECODE_MSGPACK_PENDING_MAP_ENTRIES CMT_MPACK_PENDING_MAP_ENTRIES
34+
#define CMT_DECODE_MSGPACK_PENDING_ARRAY_ENTRIES CMT_MPACK_PENDING_ARRAY_ENTRIES
35+
#define CMT_DECODE_MSGPACK_UNEXPECTED_KEY_ERROR CMT_MPACK_UNEXPECTED_KEY_ERROR
36+
#define CMT_DECODE_MSGPACK_UNEXPECTED_DATA_TYPE_ERROR CMT_MPACK_UNEXPECTED_DATA_TYPE_ERROR
37+
38+
#define CMT_DECODE_MSGPACK_DICTIONARY_LOOKUP_ERROR CMT_MPACK_ERROR_CUTOFF + 1
39+
40+
struct cmt_msgpack_decode_context {
41+
struct cmt *cmt;
42+
struct cmt_map *map;
43+
struct cmt_metric *metric;
44+
struct mk_list unique_label_list;
45+
};
46+
47+
int cmt_decode_msgpack(struct cmt **out_cmt, void *in_buf, size_t in_size);
48+
49+
#endif

0 commit comments

Comments
 (0)