Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
6e378345
T
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
6e378345
编写于
3月 10, 2022
作者:
wafwerar
提交者:
GitHub
3月 10, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #10676 from taosdata/fix/ZhiqiangWang/TD-13769-modify-sysinfo-code
[TD-13769]<fix>: modify sysinfo code.
上级
7bef44aa
306dbdc0
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
510 addition
and
451 deletion
+510
-451
source/os/src/osSysinfo.c
source/os/src/osSysinfo.c
+510
-451
未找到文件。
source/os/src/osSysinfo.c
浏览文件 @
6e378345
...
@@ -16,15 +16,6 @@
...
@@ -16,15 +16,6 @@
#define _DEFAULT_SOURCE
#define _DEFAULT_SOURCE
#include "os.h"
#include "os.h"
bool
taosCheckSystemIsSmallEnd
()
{
union
check
{
int16_t
i
;
char
ch
[
2
];
}
c
;
c
.
i
=
1
;
return
c
.
ch
[
0
]
==
1
;
}
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
/*
/*
...
@@ -48,115 +39,6 @@ bool taosCheckSystemIsSmallEnd() {
...
@@ -48,115 +39,6 @@ bool taosCheckSystemIsSmallEnd() {
#include <DbgHelp.h>
#include <DbgHelp.h>
#pragma warning(pop)
#pragma warning(pop)
int32_t
taosGetTotalMemory
(
int64_t
*
totalKB
)
{
MEMORYSTATUSEX
memsStat
;
memsStat
.
dwLength
=
sizeof
(
memsStat
);
if
(
!
GlobalMemoryStatusEx
(
&
memsStat
))
{
return
-
1
;
}
*
totalKB
=
memsStat
.
ullTotalPhys
/
1024
;
return
0
;
}
int32_t
taosGetSysMemory
(
int64_t
*
usedKB
)
{
MEMORYSTATUSEX
memsStat
;
memsStat
.
dwLength
=
sizeof
(
memsStat
);
if
(
!
GlobalMemoryStatusEx
(
&
memsStat
))
{
return
-
1
;
}
int64_t
nMemFree
=
memsStat
.
ullAvailPhys
/
1024
;
int64_t
nMemTotal
=
memsStat
.
ullTotalPhys
/
1024
.
0
;
*
usedKB
=
nMemTotal
-
nMemFree
;
return
0
;
}
int32_t
taosGetProcMemory
(
int64_t
*
usedKB
)
{
unsigned
bytes_used
=
0
;
#if defined(_WIN64) && defined(_MSC_VER)
PROCESS_MEMORY_COUNTERS
pmc
;
HANDLE
cur_proc
=
GetCurrentProcess
();
if
(
GetProcessMemoryInfo
(
cur_proc
,
&
pmc
,
sizeof
(
pmc
)))
{
bytes_used
=
(
unsigned
)(
pmc
.
WorkingSetSize
+
pmc
.
PagefileUsage
);
}
#endif
*
usedKB
=
bytes_used
/
1024
;
return
0
;
}
int32_t
taosGetCpuCores
(
float
*
numOfCores
)
{
SYSTEM_INFO
info
;
GetSystemInfo
(
&
info
);
*
numOfCores
=
info
.
dwNumberOfProcessors
;
return
0
;
}
int32_t
taosGetCpuUsage
(
double
*
sysCpuUsage
,
double
*
procCpuUsage
)
{
*
sysCpuUsage
=
0
;
*
procCpuUsage
=
0
;
return
0
;
}
int32_t
taosGetDiskSize
(
char
*
dataDir
,
SDiskSize
*
diskSize
)
{
unsigned
_int64
i64FreeBytesToCaller
;
unsigned
_int64
i64TotalBytes
;
unsigned
_int64
i64FreeBytes
;
BOOL
fResult
=
GetDiskFreeSpaceExA
(
dataDir
,
(
PULARGE_INTEGER
)
&
i64FreeBytesToCaller
,
(
PULARGE_INTEGER
)
&
i64TotalBytes
,
(
PULARGE_INTEGER
)
&
i64FreeBytes
);
if
(
fResult
)
{
diskSize
->
tsize
=
(
int64_t
)(
i64TotalBytes
);
diskSize
->
avail
=
(
int64_t
)(
i64FreeBytesToCaller
);
diskSize
->
used
=
(
int64_t
)(
i64TotalBytes
-
i64FreeBytes
);
return
0
;
}
else
{
// printf("failed to get disk size, dataDir:%s errno:%s", tsDataDir, strerror(errno));
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
-
1
;
}
}
int32_t
taosGetCardInfo
(
int64_t
*
receive_bytes
,
int64_t
*
transmit_bytes
)
{
*
receive_bytes
=
0
;
*
transmit_bytes
=
0
;
return
0
;
}
int32_t
taosGetProcIO
(
int64_t
*
rchars
,
int64_t
*
wchars
,
int64_t
*
read_bytes
,
int64_t
*
write_bytes
)
{
IO_COUNTERS
io_counter
;
if
(
GetProcessIoCounters
(
GetCurrentProcess
(),
&
io_counter
))
{
if
(
rchars
)
*
rchars
=
io_counter
.
ReadTransferCount
;
if
(
wchars
)
*
wchars
=
io_counter
.
WriteTransferCount
;
if
(
read_bytes
)
*
read_bytes
=
0
;
if
(
write_bytes
)
*
write_bytes
=
0
;
return
0
;
}
return
-
1
;
}
void
taosGetSystemInfo
()
{
taosGetCpuCores
(
&
tsNumOfCores
);
taosGetTotalMemory
(
&
tsTotalMemoryKB
);
double
tmp1
,
tmp2
,
tmp3
,
tmp4
;
taosGetCpuUsage
(
&
tmp1
,
&
tmp2
);
}
void
taosKillSystem
()
{
// printf("function taosKillSystem, exit!");
exit
(
0
);
}
int
taosSystem
(
const
char
*
cmd
)
{
// printf("taosSystem not support");
return
-
1
;
}
LONG
WINAPI
FlCrashDump
(
PEXCEPTION_POINTERS
ep
)
{
LONG
WINAPI
FlCrashDump
(
PEXCEPTION_POINTERS
ep
)
{
typedef
BOOL
(
WINAPI
*
FxMiniDumpWriteDump
)(
IN
HANDLE
hProcess
,
IN
DWORD
ProcessId
,
IN
HANDLE
hFile
,
typedef
BOOL
(
WINAPI
*
FxMiniDumpWriteDump
)(
IN
HANDLE
hProcess
,
IN
DWORD
ProcessId
,
IN
HANDLE
hFile
,
IN
MINIDUMP_TYPE
DumpType
,
IN
MINIDUMP_TYPE
DumpType
,
...
@@ -193,124 +75,13 @@ LONG WINAPI FlCrashDump(PEXCEPTION_POINTERS ep) {
...
@@ -193,124 +75,13 @@ LONG WINAPI FlCrashDump(PEXCEPTION_POINTERS ep) {
return
EXCEPTION_CONTINUE_SEARCH
;
return
EXCEPTION_CONTINUE_SEARCH
;
}
}
void
taosSetCoreDump
()
{
SetUnhandledExceptionFilter
(
&
FlCrashDump
);
}
int32_t
taosGetSystemUUID
(
char
*
uid
,
int32_t
uidlen
)
{
GUID
guid
;
CoCreateGuid
(
&
guid
);
sprintf
(
uid
,
"%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X"
,
guid
.
Data1
,
guid
.
Data2
,
guid
.
Data3
,
guid
.
Data4
[
0
],
guid
.
Data4
[
1
],
guid
.
Data4
[
2
],
guid
.
Data4
[
3
],
guid
.
Data4
[
4
],
guid
.
Data4
[
5
],
guid
.
Data4
[
6
],
guid
.
Data4
[
7
]);
return
0
;
}
char
*
taosGetCmdlineByPID
(
int
pid
)
{
return
""
;
}
#elif defined(_TD_DARWIN_64)
#elif defined(_TD_DARWIN_64)
/*
* darwin implementation
*/
#include <errno.h>
#include <errno.h>
#include <libproc.h>
#include <libproc.h>
void
taosKillSystem
()
{
// printf("function taosKillSystem, exit!");
exit
(
0
);
}
int32_t
taosGetCpuCores
(
float
*
numOfCores
)
{
*
numOfCores
=
sysconf
(
_SC_NPROCESSORS_ONLN
);
return
0
;
}
void
taosGetSystemInfo
()
{
long
physical_pages
=
sysconf
(
_SC_PHYS_PAGES
);
long
page_size
=
sysconf
(
_SC_PAGESIZE
);
tsTotalMemoryKB
=
physical_pages
*
page_size
/
1024
;
tsPageSizeKB
=
page_size
/
1024
;
tsNumOfCores
=
sysconf
(
_SC_NPROCESSORS_ONLN
);
}
int32_t
taosGetProcIO
(
int64_t
*
rchars
,
int64_t
*
wchars
,
int64_t
*
read_bytes
,
int64_t
*
write_bytes
)
{
if
(
rchars
)
*
rchars
=
0
;
if
(
wchars
)
*
wchars
=
0
;
if
(
read_bytes
)
*
read_bytes
=
0
;
if
(
write_bytes
)
*
write_bytes
=
0
;
return
0
;
}
int32_t
taosGetCardInfo
(
int64_t
*
receive_bytes
,
int64_t
*
transmit_bytes
)
{
*
receive_bytes
=
0
;
*
transmit_bytes
=
0
;
return
0
;
}
int32_t
taosGetCpuUsage
(
double
*
sysCpuUsage
,
double
*
procCpuUsage
)
{
*
sysCpuUsage
=
0
;
*
procCpuUsage
=
0
;
return
0
;
}
int32_t
taosGetProcMemory
(
int64_t
*
usedKB
)
{
*
usedKB
=
0
;
return
0
;
}
int32_t
taosGetSysMemory
(
int64_t
*
usedKB
)
{
*
usedKB
=
0
;
return
0
;
}
int
taosSystem
(
const
char
*
cmd
)
{
// printf("un support funtion");
return
-
1
;
}
void
taosSetCoreDump
()
{}
int32_t
taosGetDiskSize
(
char
*
dataDir
,
SDiskSize
*
diskSize
)
{
struct
statvfs
info
;
if
(
statvfs
(
dataDir
,
&
info
))
{
// printf("failed to get disk size, dataDir:%s errno:%s", tsDataDir, strerror(errno));
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
-
1
;
}
else
{
diskSize
->
tsize
=
info
.
f_blocks
*
info
.
f_frsize
;
diskSize
->
avail
=
info
.
f_bavail
*
info
.
f_frsize
;
diskSize
->
used
=
(
info
.
f_blocks
-
info
.
f_bfree
)
*
info
.
f_frsize
;
return
0
;
}
}
int32_t
taosGetSystemUUID
(
char
*
uid
,
int32_t
uidlen
)
{
uuid_t
uuid
=
{
0
};
uuid_generate
(
uuid
);
// it's caller's responsibility to make enough space for `uid`, that's 36-char + 1-null
uuid_unparse_lower
(
uuid
,
uid
);
return
0
;
}
char
*
taosGetCmdlineByPID
(
int
pid
)
{
static
char
cmdline
[
1024
];
errno
=
0
;
if
(
proc_pidpath
(
pid
,
cmdline
,
sizeof
(
cmdline
))
<=
0
)
{
fprintf
(
stderr
,
"PID is %d, %s"
,
pid
,
strerror
(
errno
));
return
strerror
(
errno
);
}
return
cmdline
;
}
#else
#else
/*
* linux implementation
*/
#include <argp.h>
#include <argp.h>
#include <linux/sysctl.h>
#include <linux/sysctl.h>
#include <sys/file.h>
#include <sys/file.h>
...
@@ -354,108 +125,263 @@ static void taosGetProcIOnfos() {
...
@@ -354,108 +125,263 @@ static void taosGetProcIOnfos() {
snprintf
(
tsProcIOFile
,
sizeof
(
tsProcIOFile
),
"/proc/%d/io"
,
tsProcId
);
snprintf
(
tsProcIOFile
,
sizeof
(
tsProcIOFile
),
"/proc/%d/io"
,
tsProcId
);
}
}
int32_t
taosGetTotalMemory
(
int64_t
*
totalKB
)
{
static
int32_t
taosGetSysCpuInfo
(
SysCpuInfo
*
cpuInfo
)
{
*
totalKB
=
(
int64_t
)(
sysconf
(
_SC_PHYS_PAGES
)
*
tsPageSizeKB
);
TdFilePtr
pFile
=
taosOpenFile
(
tsSysCpuFile
,
TD_FILE_READ
|
TD_FILE_STREAM
);
return
0
;
}
int32_t
taosGetSysMemory
(
int64_t
*
usedKB
)
{
*
usedKB
=
sysconf
(
_SC_AVPHYS_PAGES
)
*
tsPageSizeKB
;
return
0
;
}
int32_t
taosGetProcMemory
(
int64_t
*
usedKB
)
{
TdFilePtr
pFile
=
taosOpenFile
(
tsProcMemFile
,
TD_FILE_READ
|
TD_FILE_STREAM
);
if
(
pFile
==
NULL
)
{
if
(
pFile
==
NULL
)
{
// printf("open file:%s failed", ts
ProcMem
File);
// printf("open file:%s failed", ts
SysCpu
File);
return
-
1
;
return
-
1
;
}
}
ssize_t
_bytes
=
0
;
char
*
line
=
NULL
;
char
*
line
=
NULL
;
while
(
!
taosEOFFile
(
pFile
))
{
ssize_t
_bytes
=
taosGetLineFile
(
pFile
,
&
line
);
_bytes
=
taosGetLineFile
(
pFile
,
&
line
);
if
((
_bytes
<
0
)
||
(
line
==
NULL
))
{
if
((
_bytes
<
0
)
||
(
line
==
NULL
))
{
// printf("read file:%s failed", tsSysCpuFile);
break
;
}
if
(
strstr
(
line
,
"VmRSS:"
)
!=
NULL
)
{
break
;
}
}
if
(
line
==
NULL
)
{
// printf("read file:%s failed", tsProcMemFile);
taosCloseFile
(
&
pFile
);
taosCloseFile
(
&
pFile
);
return
-
1
;
return
-
1
;
}
}
char
tmp
[
10
];
char
cpu
[
10
]
=
{
0
};
sscanf
(
line
,
"%s %"
PRId64
,
tmp
,
usedKB
);
sscanf
(
line
,
"%s %"
PRIu64
" %"
PRIu64
" %"
PRIu64
" %"
PRIu64
,
cpu
,
&
cpuInfo
->
user
,
&
cpuInfo
->
nice
,
&
cpuInfo
->
system
,
&
cpuInfo
->
idle
);
if
(
line
!=
NULL
)
tfree
(
line
);
if
(
line
!=
NULL
)
tfree
(
line
);
taosCloseFile
(
&
pFile
);
taosCloseFile
(
&
pFile
);
return
0
;
return
0
;
}
}
static
int32_t
taosGet
SysCpuInfo
(
Sys
CpuInfo
*
cpuInfo
)
{
static
int32_t
taosGet
ProcCpuInfo
(
Proc
CpuInfo
*
cpuInfo
)
{
TdFilePtr
pFile
=
taosOpenFile
(
ts
Sys
CpuFile
,
TD_FILE_READ
|
TD_FILE_STREAM
);
TdFilePtr
pFile
=
taosOpenFile
(
ts
Proc
CpuFile
,
TD_FILE_READ
|
TD_FILE_STREAM
);
if
(
pFile
==
NULL
)
{
if
(
pFile
==
NULL
)
{
// printf("open file:%s failed", ts
Sys
CpuFile);
// printf("open file:%s failed", ts
Proc
CpuFile);
return
-
1
;
return
-
1
;
}
}
char
*
line
=
NULL
;
char
*
line
=
NULL
;
ssize_t
_bytes
=
taosGetLineFile
(
pFile
,
&
line
);
ssize_t
_bytes
=
taosGetLineFile
(
pFile
,
&
line
);
if
((
_bytes
<
0
)
||
(
line
==
NULL
))
{
if
((
_bytes
<
0
)
||
(
line
==
NULL
))
{
// printf("read file:%s failed", ts
Sys
CpuFile);
// printf("read file:%s failed", ts
Proc
CpuFile);
taosCloseFile
(
&
pFile
);
taosCloseFile
(
&
pFile
);
return
-
1
;
return
-
1
;
}
}
char
cpu
[
10
]
=
{
0
};
for
(
int
i
=
0
,
blank
=
0
;
line
[
i
]
!=
0
;
++
i
)
{
sscanf
(
line
,
"%s %"
PRIu64
" %"
PRIu64
" %"
PRIu64
" %"
PRIu64
,
cpu
,
&
cpuInfo
->
user
,
&
cpuInfo
->
nice
,
&
cpuInfo
->
system
,
if
(
line
[
i
]
==
' '
)
blank
++
;
&
cpuInfo
->
idle
);
if
(
blank
==
PROCESS_ITEM
)
{
sscanf
(
line
+
i
+
1
,
"%"
PRIu64
" %"
PRIu64
" %"
PRIu64
" %"
PRIu64
,
&
cpuInfo
->
utime
,
&
cpuInfo
->
stime
,
&
cpuInfo
->
cutime
,
&
cpuInfo
->
cstime
);
break
;
}
}
if
(
line
!=
NULL
)
tfree
(
line
);
if
(
line
!=
NULL
)
tfree
(
line
);
taosCloseFile
(
&
pFile
);
taosCloseFile
(
&
pFile
);
return
0
;
return
0
;
}
}
static
int32_t
taosGetProcCpuInfo
(
ProcCpuInfo
*
cpuInfo
)
{
#endif
TdFilePtr
pFile
=
taosOpenFile
(
tsProcCpuFile
,
TD_FILE_READ
|
TD_FILE_STREAM
);
if
(
pFile
==
NULL
)
{
bool
taosCheckSystemIsSmallEnd
()
{
// printf("open file:%s failed", tsProcCpuFile);
union
check
{
int16_t
i
;
char
ch
[
2
];
}
c
;
c
.
i
=
1
;
return
c
.
ch
[
0
]
==
1
;
}
void
taosGetSystemInfo
()
{
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
taosGetCpuCores
(
&
tsNumOfCores
);
taosGetTotalMemory
(
&
tsTotalMemoryKB
);
double
tmp1
,
tmp2
,
tmp3
,
tmp4
;
taosGetCpuUsage
(
&
tmp1
,
&
tmp2
);
#elif defined(_TD_DARWIN_64)
long
physical_pages
=
sysconf
(
_SC_PHYS_PAGES
);
long
page_size
=
sysconf
(
_SC_PAGESIZE
);
tsTotalMemoryKB
=
physical_pages
*
page_size
/
1024
;
tsPageSizeKB
=
page_size
/
1024
;
tsNumOfCores
=
sysconf
(
_SC_NPROCESSORS_ONLN
);
#else
taosGetProcIOnfos
();
taosGetCpuCores
(
&
tsNumOfCores
);
taosGetTotalMemory
(
&
tsTotalMemoryKB
);
double
tmp1
,
tmp2
,
tmp3
,
tmp4
;
taosGetCpuUsage
(
&
tmp1
,
&
tmp2
);
#endif
}
int32_t
taosGetEmail
(
char
*
email
,
int32_t
maxLen
)
{
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#elif defined(_TD_DARWIN_64)
const
char
*
filepath
=
"/usr/local/taos/email"
;
TdFilePtr
pFile
=
taosOpenFile
(
filepath
,
TD_FILE_READ
);
if
(
pFile
==
NULL
)
return
false
;
if
(
taosReadFile
(
pFile
,
(
void
*
)
email
,
maxLen
)
<
0
)
{
taosCloseFile
(
&
pFile
);
return
-
1
;
return
-
1
;
}
}
char
*
line
=
NULL
;
taosCloseFile
(
&
pFile
);
ssize_t
_bytes
=
taosGetLineFile
(
pFile
,
&
line
);
return
0
;
if
((
_bytes
<
0
)
||
(
line
==
NULL
))
{
#else
// printf("read file:%s failed", tsProcCpuFile);
const
char
*
filepath
=
"/usr/local/taos/email"
;
TdFilePtr
pFile
=
taosOpenFile
(
filepath
,
TD_FILE_READ
);
if
(
pFile
==
NULL
)
return
false
;
if
(
taosReadFile
(
pFile
,
(
void
*
)
email
,
maxLen
)
<
0
)
{
taosCloseFile
(
&
pFile
);
taosCloseFile
(
&
pFile
);
return
-
1
;
return
-
1
;
}
}
for
(
int
i
=
0
,
blank
=
0
;
line
[
i
]
!=
0
;
++
i
)
{
taosCloseFile
(
&
pFile
);
if
(
line
[
i
]
==
' '
)
blank
++
;
return
0
;
if
(
blank
==
PROCESS_ITEM
)
{
#endif
sscanf
(
line
+
i
+
1
,
"%"
PRIu64
" %"
PRIu64
" %"
PRIu64
" %"
PRIu64
,
&
cpuInfo
->
utime
,
&
cpuInfo
->
stime
,
}
&
cpuInfo
->
cutime
,
&
cpuInfo
->
cstime
);
int32_t
taosGetOsReleaseName
(
char
*
releaseName
,
int32_t
maxLen
)
{
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#elif defined(_TD_DARWIN_64)
char
*
line
=
NULL
;
size_t
size
=
0
;
int32_t
code
=
-
1
;
TdFilePtr
pFile
=
taosOpenFile
(
"/etc/os-release"
,
TD_FILE_READ
|
TD_FILE_STREAM
);
if
(
pFile
==
NULL
)
return
false
;
while
((
size
=
taosGetLineFile
(
pFile
,
&
line
))
!=
-
1
)
{
line
[
size
-
1
]
=
'\0'
;
if
(
strncmp
(
line
,
"PRETTY_NAME"
,
11
)
==
0
)
{
const
char
*
p
=
strchr
(
line
,
'='
)
+
1
;
if
(
*
p
==
'"'
)
{
p
++
;
line
[
size
-
2
]
=
0
;
}
tstrncpy
(
releaseName
,
p
,
maxLen
);
code
=
0
;
break
;
break
;
}
}
}
}
if
(
line
!=
NULL
)
t
free
(
line
);
if
(
line
!=
NULL
)
free
(
line
);
taosCloseFile
(
&
pFile
);
taosCloseFile
(
&
pFile
);
return
0
;
return
code
;
#else
char
*
line
=
NULL
;
size_t
size
=
0
;
int32_t
code
=
-
1
;
TdFilePtr
pFile
=
taosOpenFile
(
"/etc/os-release"
,
TD_FILE_READ
|
TD_FILE_STREAM
);
if
(
pFile
==
NULL
)
return
false
;
while
((
size
=
taosGetLineFile
(
pFile
,
&
line
))
!=
-
1
)
{
line
[
size
-
1
]
=
'\0'
;
if
(
strncmp
(
line
,
"PRETTY_NAME"
,
11
)
==
0
)
{
const
char
*
p
=
strchr
(
line
,
'='
)
+
1
;
if
(
*
p
==
'"'
)
{
p
++
;
line
[
size
-
2
]
=
0
;
}
tstrncpy
(
releaseName
,
p
,
maxLen
);
code
=
0
;
break
;
}
}
if
(
line
!=
NULL
)
free
(
line
);
taosCloseFile
(
&
pFile
);
return
code
;
#endif
}
int32_t
taosGetCpuInfo
(
char
*
cpuModel
,
int32_t
maxLen
,
float
*
numOfCores
)
{
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#elif defined(_TD_DARWIN_64)
char
*
line
=
NULL
;
size_t
size
=
0
;
int32_t
done
=
0
;
int32_t
code
=
-
1
;
TdFilePtr
pFile
=
taosOpenFile
(
"/proc/cpuinfo"
,
TD_FILE_READ
|
TD_FILE_STREAM
);
if
(
pFile
==
NULL
)
return
false
;
while
(
done
!=
3
&&
(
size
=
taosGetLineFile
(
pFile
,
&
line
))
!=
-
1
)
{
line
[
size
-
1
]
=
'\0'
;
if
(((
done
&
1
)
==
0
)
&&
strncmp
(
line
,
"model name"
,
10
)
==
0
)
{
const
char
*
v
=
strchr
(
line
,
':'
)
+
2
;
tstrncpy
(
cpuModel
,
v
,
maxLen
);
code
=
0
;
done
|=
1
;
}
else
if
(((
done
&
2
)
==
0
)
&&
strncmp
(
line
,
"cpu cores"
,
9
)
==
0
)
{
const
char
*
v
=
strchr
(
line
,
':'
)
+
2
;
*
numOfCores
=
atof
(
v
);
done
|=
2
;
}
}
if
(
line
!=
NULL
)
free
(
line
);
taosCloseFile
(
&
pFile
);
return
code
;
#else
char
*
line
=
NULL
;
size_t
size
=
0
;
int32_t
done
=
0
;
int32_t
code
=
-
1
;
TdFilePtr
pFile
=
taosOpenFile
(
"/proc/cpuinfo"
,
TD_FILE_READ
|
TD_FILE_STREAM
);
if
(
pFile
==
NULL
)
return
false
;
while
(
done
!=
3
&&
(
size
=
taosGetLineFile
(
pFile
,
&
line
))
!=
-
1
)
{
line
[
size
-
1
]
=
'\0'
;
if
(((
done
&
1
)
==
0
)
&&
strncmp
(
line
,
"model name"
,
10
)
==
0
)
{
const
char
*
v
=
strchr
(
line
,
':'
)
+
2
;
tstrncpy
(
cpuModel
,
v
,
maxLen
);
code
=
0
;
done
|=
1
;
}
else
if
(((
done
&
2
)
==
0
)
&&
strncmp
(
line
,
"cpu cores"
,
9
)
==
0
)
{
const
char
*
v
=
strchr
(
line
,
':'
)
+
2
;
*
numOfCores
=
atof
(
v
);
done
|=
2
;
}
}
if
(
line
!=
NULL
)
free
(
line
);
taosCloseFile
(
&
pFile
);
return
code
;
#endif
}
}
int32_t
taosGetCpuCores
(
float
*
numOfCores
)
{
int32_t
taosGetCpuCores
(
float
*
numOfCores
)
{
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
SYSTEM_INFO
info
;
GetSystemInfo
(
&
info
);
*
numOfCores
=
info
.
dwNumberOfProcessors
;
return
0
;
#elif defined(_TD_DARWIN_64)
*
numOfCores
=
sysconf
(
_SC_NPROCESSORS_ONLN
);
*
numOfCores
=
sysconf
(
_SC_NPROCESSORS_ONLN
);
return
0
;
return
0
;
#else
*
numOfCores
=
sysconf
(
_SC_NPROCESSORS_ONLN
);
return
0
;
#endif
}
}
int32_t
taosGetCpuUsage
(
double
*
cpu_system
,
double
*
cpu_engine
)
{
int32_t
taosGetCpuUsage
(
double
*
cpu_system
,
double
*
cpu_engine
)
{
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
*
sysCpuUsage
=
0
;
*
procCpuUsage
=
0
;
return
0
;
#elif defined(_TD_DARWIN_64)
*
sysCpuUsage
=
0
;
*
procCpuUsage
=
0
;
return
0
;
#else
static
uint64_t
lastSysUsed
=
0
;
static
uint64_t
lastSysUsed
=
0
;
static
uint64_t
lastSysTotal
=
0
;
static
uint64_t
lastSysTotal
=
0
;
static
uint64_t
lastProcTotal
=
0
;
static
uint64_t
lastProcTotal
=
0
;
...
@@ -492,66 +418,162 @@ int32_t taosGetCpuUsage(double *cpu_system, double *cpu_engine) {
...
@@ -492,66 +418,162 @@ int32_t taosGetCpuUsage(double *cpu_system, double *cpu_engine) {
lastProcTotal
=
curProcTotal
;
lastProcTotal
=
curProcTotal
;
return
0
;
return
0
;
#endif
}
}
int32_t
taosGetDiskSize
(
char
*
dataDir
,
SDiskSize
*
diskSize
)
{
int32_t
taosGetTotalMemory
(
int64_t
*
totalKB
)
{
struct
statvfs
info
;
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
if
(
statvfs
(
dataDir
,
&
info
))
{
MEMORYSTATUSEX
memsStat
;
memsStat
.
dwLength
=
sizeof
(
memsStat
);
if
(
!
GlobalMemoryStatusEx
(
&
memsStat
))
{
return
-
1
;
return
-
1
;
}
else
{
diskSize
->
total
=
info
.
f_blocks
*
info
.
f_frsize
;
diskSize
->
avail
=
info
.
f_bavail
*
info
.
f_frsize
;
diskSize
->
used
=
diskSize
->
total
-
diskSize
->
avail
;
return
0
;
}
}
*
totalKB
=
memsStat
.
ullTotalPhys
/
1024
;
return
0
;
#elif defined(_TD_DARWIN_64)
return
0
;
#else
*
totalKB
=
(
int64_t
)(
sysconf
(
_SC_PHYS_PAGES
)
*
tsPageSizeKB
);
return
0
;
#endif
}
}
int32_t
taosGetCardInfo
(
int64_t
*
receive_bytes
,
int64_t
*
transmit_bytes
)
{
int32_t
taosGetProcMemory
(
int64_t
*
usedKB
)
{
TdFilePtr
pFile
=
taosOpenFile
(
tsSysNetFile
,
TD_FILE_READ
|
TD_FILE_STREAM
);
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
if
(
pFile
==
NULL
)
return
-
1
;
unsigned
bytes_used
=
0
;
#if defined(_WIN64) && defined(_MSC_VER)
PROCESS_MEMORY_COUNTERS
pmc
;
HANDLE
cur_proc
=
GetCurrentProcess
();
if
(
GetProcessMemoryInfo
(
cur_proc
,
&
pmc
,
sizeof
(
pmc
)))
{
bytes_used
=
(
unsigned
)(
pmc
.
WorkingSetSize
+
pmc
.
PagefileUsage
);
}
#endif
*
usedKB
=
bytes_used
/
1024
;
return
0
;
#elif defined(_TD_DARWIN_64)
*
usedKB
=
0
;
return
0
;
#else
TdFilePtr
pFile
=
taosOpenFile
(
tsProcMemFile
,
TD_FILE_READ
|
TD_FILE_STREAM
);
if
(
pFile
==
NULL
)
{
// printf("open file:%s failed", tsProcMemFile);
return
-
1
;
}
ssize_t
_bytes
=
0
;
ssize_t
_bytes
=
0
;
char
*
line
=
NULL
;
char
*
line
=
NULL
;
while
(
!
taosEOFFile
(
pFile
))
{
while
(
!
taosEOFFile
(
pFile
))
{
int64_t
o_rbytes
=
0
;
int64_t
rpackts
=
0
;
int64_t
o_tbytes
=
0
;
int64_t
tpackets
=
0
;
int64_t
nouse1
=
0
;
int64_t
nouse2
=
0
;
int64_t
nouse3
=
0
;
int64_t
nouse4
=
0
;
int64_t
nouse5
=
0
;
int64_t
nouse6
=
0
;
char
nouse0
[
200
]
=
{
0
};
_bytes
=
taosGetLineFile
(
pFile
,
&
line
);
_bytes
=
taosGetLineFile
(
pFile
,
&
line
);
if
(
_bytes
<
0
)
{
if
(
(
_bytes
<
0
)
||
(
line
==
NULL
)
)
{
break
;
break
;
}
}
if
(
strstr
(
line
,
"VmRSS:"
)
!=
NULL
)
{
line
[
_bytes
-
1
]
=
0
;
break
;
if
(
strstr
(
line
,
"lo:"
)
!=
NULL
)
{
continue
;
}
}
}
sscanf
(
line
,
if
(
line
==
NULL
)
{
"%s %"
PRId64
" %"
PRId64
" %"
PRId64
" %"
PRId64
" %"
PRId64
" %"
PRId64
" %"
PRId64
" %"
PRId64
" %"
PRId64
// printf("read file:%s failed", tsProcMemFile);
" %"
PRId64
,
taosCloseFile
(
&
pFile
);
nouse0
,
&
o_rbytes
,
&
rpackts
,
&
nouse1
,
&
nouse2
,
&
nouse3
,
&
nouse4
,
&
nouse5
,
&
nouse6
,
&
o_tbytes
,
&
tpackets
);
return
-
1
;
*
receive_bytes
=
o_rbytes
;
*
transmit_bytes
=
o_tbytes
;
}
}
char
tmp
[
10
];
sscanf
(
line
,
"%s %"
PRId64
,
tmp
,
usedKB
);
if
(
line
!=
NULL
)
tfree
(
line
);
if
(
line
!=
NULL
)
tfree
(
line
);
taosCloseFile
(
&
pFile
);
taosCloseFile
(
&
pFile
);
return
0
;
#endif
}
int32_t
taosGetSysMemory
(
int64_t
*
usedKB
)
{
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
MEMORYSTATUSEX
memsStat
;
memsStat
.
dwLength
=
sizeof
(
memsStat
);
if
(
!
GlobalMemoryStatusEx
(
&
memsStat
))
{
return
-
1
;
}
int64_t
nMemFree
=
memsStat
.
ullAvailPhys
/
1024
;
int64_t
nMemTotal
=
memsStat
.
ullTotalPhys
/
1024
.
0
;
*
usedKB
=
nMemTotal
-
nMemFree
;
return
0
;
#elif defined(_TD_DARWIN_64)
*
usedKB
=
0
;
return
0
;
#else
*
usedKB
=
sysconf
(
_SC_AVPHYS_PAGES
)
*
tsPageSizeKB
;
return
0
;
return
0
;
#endif
}
int32_t
taosGetDiskSize
(
char
*
dataDir
,
SDiskSize
*
diskSize
)
{
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
unsigned
_int64
i64FreeBytesToCaller
;
unsigned
_int64
i64TotalBytes
;
unsigned
_int64
i64FreeBytes
;
BOOL
fResult
=
GetDiskFreeSpaceExA
(
dataDir
,
(
PULARGE_INTEGER
)
&
i64FreeBytesToCaller
,
(
PULARGE_INTEGER
)
&
i64TotalBytes
,
(
PULARGE_INTEGER
)
&
i64FreeBytes
);
if
(
fResult
)
{
diskSize
->
tsize
=
(
int64_t
)(
i64TotalBytes
);
diskSize
->
avail
=
(
int64_t
)(
i64FreeBytesToCaller
);
diskSize
->
used
=
(
int64_t
)(
i64TotalBytes
-
i64FreeBytes
);
return
0
;
}
else
{
// printf("failed to get disk size, dataDir:%s errno:%s", tsDataDir, strerror(errno));
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
-
1
;
}
#elif defined(_TD_DARWIN_64)
struct
statvfs
info
;
if
(
statvfs
(
dataDir
,
&
info
))
{
// printf("failed to get disk size, dataDir:%s errno:%s", tsDataDir, strerror(errno));
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
-
1
;
}
else
{
diskSize
->
tsize
=
info
.
f_blocks
*
info
.
f_frsize
;
diskSize
->
avail
=
info
.
f_bavail
*
info
.
f_frsize
;
diskSize
->
used
=
(
info
.
f_blocks
-
info
.
f_bfree
)
*
info
.
f_frsize
;
return
0
;
}
#else
struct
statvfs
info
;
if
(
statvfs
(
dataDir
,
&
info
))
{
return
-
1
;
}
else
{
diskSize
->
total
=
info
.
f_blocks
*
info
.
f_frsize
;
diskSize
->
avail
=
info
.
f_bavail
*
info
.
f_frsize
;
diskSize
->
used
=
diskSize
->
total
-
diskSize
->
avail
;
return
0
;
}
#endif
}
}
int32_t
taosGetProcIO
(
int64_t
*
rchars
,
int64_t
*
wchars
,
int64_t
*
read_bytes
,
int64_t
*
write_bytes
)
{
int32_t
taosGetProcIO
(
int64_t
*
rchars
,
int64_t
*
wchars
,
int64_t
*
read_bytes
,
int64_t
*
write_bytes
)
{
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
IO_COUNTERS
io_counter
;
if
(
GetProcessIoCounters
(
GetCurrentProcess
(),
&
io_counter
))
{
if
(
rchars
)
*
rchars
=
io_counter
.
ReadTransferCount
;
if
(
wchars
)
*
wchars
=
io_counter
.
WriteTransferCount
;
if
(
read_bytes
)
*
read_bytes
=
0
;
if
(
write_bytes
)
*
write_bytes
=
0
;
return
0
;
}
return
-
1
;
#elif defined(_TD_DARWIN_64)
if
(
rchars
)
*
rchars
=
0
;
if
(
wchars
)
*
wchars
=
0
;
if
(
read_bytes
)
*
read_bytes
=
0
;
if
(
write_bytes
)
*
write_bytes
=
0
;
return
0
;
#else
TdFilePtr
pFile
=
taosOpenFile
(
tsProcIOFile
,
TD_FILE_READ
|
TD_FILE_STREAM
);
TdFilePtr
pFile
=
taosOpenFile
(
tsProcIOFile
,
TD_FILE_READ
|
TD_FILE_STREAM
);
if
(
pFile
==
NULL
)
return
-
1
;
if
(
pFile
==
NULL
)
return
-
1
;
...
@@ -580,35 +602,83 @@ int32_t taosGetProcIO(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, int
...
@@ -580,35 +602,83 @@ int32_t taosGetProcIO(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, int
}
else
{
}
else
{
}
}
if
(
readIndex
>=
4
)
break
;
if
(
readIndex
>=
4
)
break
;
}
if
(
line
!=
NULL
)
tfree
(
line
);
taosCloseFile
(
&
pFile
);
if
(
readIndex
<
4
)
{
return
-
1
;
}
return
0
;
#endif
}
int32_t
taosGetCardInfo
(
int64_t
*
receive_bytes
,
int64_t
*
transmit_bytes
)
{
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
*
receive_bytes
=
0
;
*
transmit_bytes
=
0
;
return
0
;
#elif defined(_TD_DARWIN_64)
*
receive_bytes
=
0
;
*
transmit_bytes
=
0
;
return
0
;
#else
TdFilePtr
pFile
=
taosOpenFile
(
tsSysNetFile
,
TD_FILE_READ
|
TD_FILE_STREAM
);
if
(
pFile
==
NULL
)
return
-
1
;
ssize_t
_bytes
=
0
;
char
*
line
=
NULL
;
while
(
!
taosEOFFile
(
pFile
))
{
int64_t
o_rbytes
=
0
;
int64_t
rpackts
=
0
;
int64_t
o_tbytes
=
0
;
int64_t
tpackets
=
0
;
int64_t
nouse1
=
0
;
int64_t
nouse2
=
0
;
int64_t
nouse3
=
0
;
int64_t
nouse4
=
0
;
int64_t
nouse5
=
0
;
int64_t
nouse6
=
0
;
char
nouse0
[
200
]
=
{
0
};
_bytes
=
taosGetLineFile
(
pFile
,
&
line
);
if
(
_bytes
<
0
)
{
break
;
}
line
[
_bytes
-
1
]
=
0
;
if
(
strstr
(
line
,
"lo:"
)
!=
NULL
)
{
continue
;
}
sscanf
(
line
,
"%s %"
PRId64
" %"
PRId64
" %"
PRId64
" %"
PRId64
" %"
PRId64
" %"
PRId64
" %"
PRId64
" %"
PRId64
" %"
PRId64
" %"
PRId64
,
nouse0
,
&
o_rbytes
,
&
rpackts
,
&
nouse1
,
&
nouse2
,
&
nouse3
,
&
nouse4
,
&
nouse5
,
&
nouse6
,
&
o_tbytes
,
&
tpackets
);
*
receive_bytes
=
o_rbytes
;
*
transmit_bytes
=
o_tbytes
;
}
}
if
(
line
!=
NULL
)
tfree
(
line
);
if
(
line
!=
NULL
)
tfree
(
line
);
taosCloseFile
(
&
pFile
);
taosCloseFile
(
&
pFile
);
if
(
readIndex
<
4
)
{
return
-
1
;
}
return
0
;
return
0
;
}
#endif
void
taosGetSystemInfo
()
{
taosGetProcIOnfos
();
taosGetCpuCores
(
&
tsNumOfCores
);
taosGetTotalMemory
(
&
tsTotalMemoryKB
);
double
tmp1
,
tmp2
,
tmp3
,
tmp4
;
taosGetCpuUsage
(
&
tmp1
,
&
tmp2
);
}
void
taosKillSystem
()
{
// SIGINT
// printf("taosd will shut down soon");
kill
(
tsProcId
,
2
);
}
}
int
taosSystem
(
const
char
*
cmd
)
{
int
taosSystem
(
const
char
*
cmd
)
{
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
printf
(
"taosSystem not support"
);
return
-
1
;
#elif defined(_TD_DARWIN_64)
printf
(
"no support funtion"
);
return
-
1
;
#else
FILE
*
fp
;
FILE
*
fp
;
int
res
;
int
res
;
char
buf
[
1024
];
char
buf
[
1024
];
...
@@ -633,9 +703,100 @@ int taosSystem(const char *cmd) {
...
@@ -633,9 +703,100 @@ int taosSystem(const char *cmd) {
return
res
;
return
res
;
}
}
#endif
}
void
taosKillSystem
()
{
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
printf
(
"function taosKillSystem, exit!"
);
exit
(
0
);
#elif defined(_TD_DARWIN_64)
printf
(
"function taosKillSystem, exit!"
);
exit
(
0
);
#else
// SIGINT
printf
(
"taosd will shut down soon"
);
kill
(
tsProcId
,
2
);
#endif
}
int32_t
taosGetSystemUUID
(
char
*
uid
,
int32_t
uidlen
)
{
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
GUID
guid
;
CoCreateGuid
(
&
guid
);
sprintf
(
uid
,
"%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X"
,
guid
.
Data1
,
guid
.
Data2
,
guid
.
Data3
,
guid
.
Data4
[
0
],
guid
.
Data4
[
1
],
guid
.
Data4
[
2
],
guid
.
Data4
[
3
],
guid
.
Data4
[
4
],
guid
.
Data4
[
5
],
guid
.
Data4
[
6
],
guid
.
Data4
[
7
]);
return
0
;
#elif defined(_TD_DARWIN_64)
uuid_t
uuid
=
{
0
};
uuid_generate
(
uuid
);
// it's caller's responsibility to make enough space for `uid`, that's 36-char + 1-null
uuid_unparse_lower
(
uuid
,
uid
);
return
0
;
#else
int
len
=
0
;
// fd = open("/proc/sys/kernel/random/uuid", 0);
TdFilePtr
pFile
=
taosOpenFile
(
"/proc/sys/kernel/random/uuid"
,
TD_FILE_READ
);
if
(
pFile
==
NULL
)
{
return
-
1
;
}
else
{
len
=
taosReadFile
(
pFile
,
uid
,
uidlen
);
taosCloseFile
(
&
pFile
);
}
if
(
len
>=
36
)
{
uid
[
36
]
=
0
;
return
0
;
}
return
0
;
#endif
}
char
*
taosGetCmdlineByPID
(
int
pid
)
{
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
return
""
;
#elif defined(_TD_DARWIN_64)
static
char
cmdline
[
1024
];
errno
=
0
;
if
(
proc_pidpath
(
pid
,
cmdline
,
sizeof
(
cmdline
))
<=
0
)
{
fprintf
(
stderr
,
"PID is %d, %s"
,
pid
,
strerror
(
errno
));
return
strerror
(
errno
);
}
return
cmdline
;
#else
static
char
cmdline
[
1024
];
sprintf
(
cmdline
,
"/proc/%d/cmdline"
,
pid
);
// int fd = open(cmdline, O_RDONLY);
TdFilePtr
pFile
=
taosOpenFile
(
cmdline
,
TD_FILE_READ
);
if
(
pFile
!=
NULL
)
{
int
n
=
taosReadFile
(
pFile
,
cmdline
,
sizeof
(
cmdline
)
-
1
);
if
(
n
<
0
)
n
=
0
;
if
(
n
>
0
&&
cmdline
[
n
-
1
]
==
'\n'
)
--
n
;
cmdline
[
n
]
=
0
;
taosCloseFile
(
&
pFile
);
}
else
{
cmdline
[
0
]
=
0
;
}
return
cmdline
;
#endif
}
}
void
taosSetCoreDump
(
bool
enable
)
{
void
taosSetCoreDump
(
bool
enable
)
{
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
SetUnhandledExceptionFilter
(
&
FlCrashDump
);
#elif defined(_TD_DARWIN_64)
#else
if
(
!
enable
)
return
;
if
(
!
enable
)
return
;
// 1. set ulimit -c unlimited
// 1. set ulimit -c unlimited
...
@@ -708,55 +869,12 @@ void taosSetCoreDump(bool enable) {
...
@@ -708,55 +869,12 @@ void taosSetCoreDump(bool enable) {
// printf("The new core_uses_pid[%" PRIu64 "]: %d", old_len, old_usespid);
// printf("The new core_uses_pid[%" PRIu64 "]: %d", old_len, old_usespid);
#endif
#endif
}
int32_t
taosGetSystemUUID
(
char
*
uid
,
int32_t
uidlen
)
{
int
len
=
0
;
// fd = open("/proc/sys/kernel/random/uuid", 0);
TdFilePtr
pFile
=
taosOpenFile
(
"/proc/sys/kernel/random/uuid"
,
TD_FILE_READ
);
if
(
pFile
==
NULL
)
{
return
-
1
;
}
else
{
len
=
taosReadFile
(
pFile
,
uid
,
uidlen
);
taosCloseFile
(
&
pFile
);
}
if
(
len
>=
36
)
{
uid
[
36
]
=
0
;
return
0
;
}
return
0
;
}
char
*
taosGetCmdlineByPID
(
int
pid
)
{
static
char
cmdline
[
1024
];
sprintf
(
cmdline
,
"/proc/%d/cmdline"
,
pid
);
// int fd = open(cmdline, O_RDONLY);
TdFilePtr
pFile
=
taosOpenFile
(
cmdline
,
TD_FILE_READ
);
if
(
pFile
!=
NULL
)
{
int
n
=
taosReadFile
(
pFile
,
cmdline
,
sizeof
(
cmdline
)
-
1
);
if
(
n
<
0
)
n
=
0
;
if
(
n
>
0
&&
cmdline
[
n
-
1
]
==
'\n'
)
--
n
;
cmdline
[
n
]
=
0
;
taosCloseFile
(
&
pFile
);
}
else
{
cmdline
[
0
]
=
0
;
}
return
cmdline
;
}
#endif
#endif
}
#if !(defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32))
SysNameInfo
taosGetSysNameInfo
()
{
SysNameInfo
taosGetSysNameInfo
()
{
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#elif defined(_TD_DARWIN_64)
SysNameInfo
info
=
{
0
};
SysNameInfo
info
=
{
0
};
struct
utsname
uts
;
struct
utsname
uts
;
...
@@ -769,77 +887,18 @@ SysNameInfo taosGetSysNameInfo() {
...
@@ -769,77 +887,18 @@ SysNameInfo taosGetSysNameInfo() {
}
}
return
info
;
return
info
;
}
#else
SysNameInfo
info
=
{
0
};
int32_t
taosGetEmail
(
char
*
email
,
int32_t
maxLen
)
{
const
char
*
filepath
=
"/usr/local/taos/email"
;
TdFilePtr
pFile
=
taosOpenFile
(
filepath
,
TD_FILE_READ
);
if
(
pFile
==
NULL
)
return
false
;
if
(
taosReadFile
(
pFile
,
(
void
*
)
email
,
maxLen
)
<
0
)
{
taosCloseFile
(
&
pFile
);
return
-
1
;
}
taosCloseFile
(
&
pFile
);
return
0
;
}
int32_t
taosGetOsReleaseName
(
char
*
releaseName
,
int32_t
maxLen
)
{
char
*
line
=
NULL
;
size_t
size
=
0
;
int32_t
code
=
-
1
;
TdFilePtr
pFile
=
taosOpenFile
(
"/etc/os-release"
,
TD_FILE_READ
|
TD_FILE_STREAM
);
if
(
pFile
==
NULL
)
return
false
;
while
((
size
=
taosGetLineFile
(
pFile
,
&
line
))
!=
-
1
)
{
line
[
size
-
1
]
=
'\0'
;
if
(
strncmp
(
line
,
"PRETTY_NAME"
,
11
)
==
0
)
{
const
char
*
p
=
strchr
(
line
,
'='
)
+
1
;
if
(
*
p
==
'"'
)
{
p
++
;
line
[
size
-
2
]
=
0
;
}
tstrncpy
(
releaseName
,
p
,
maxLen
);
code
=
0
;
break
;
}
}
if
(
line
!=
NULL
)
free
(
line
);
taosCloseFile
(
&
pFile
);
return
code
;
}
int32_t
taosGetCpuInfo
(
char
*
cpuModel
,
int32_t
maxLen
,
float
*
numOfCores
)
{
char
*
line
=
NULL
;
size_t
size
=
0
;
int32_t
done
=
0
;
int32_t
code
=
-
1
;
TdFilePtr
pFile
=
taosOpenFile
(
"/proc/cpuinfo"
,
TD_FILE_READ
|
TD_FILE_STREAM
);
if
(
pFile
==
NULL
)
return
false
;
while
(
done
!=
3
&&
(
size
=
taosGetLineFile
(
pFile
,
&
line
))
!=
-
1
)
{
struct
utsname
uts
;
line
[
size
-
1
]
=
'\0'
;
if
(
!
uname
(
&
uts
))
{
if
(((
done
&
1
)
==
0
)
&&
strncmp
(
line
,
"model name"
,
10
)
==
0
)
{
tstrncpy
(
info
.
sysname
,
uts
.
sysname
,
sizeof
(
info
.
sysname
));
const
char
*
v
=
strchr
(
line
,
':'
)
+
2
;
tstrncpy
(
info
.
nodename
,
uts
.
nodename
,
sizeof
(
info
.
nodename
));
tstrncpy
(
cpuModel
,
v
,
maxLen
);
tstrncpy
(
info
.
release
,
uts
.
release
,
sizeof
(
info
.
release
));
code
=
0
;
tstrncpy
(
info
.
version
,
uts
.
version
,
sizeof
(
info
.
version
));
done
|=
1
;
tstrncpy
(
info
.
machine
,
uts
.
machine
,
sizeof
(
info
.
machine
));
}
else
if
(((
done
&
2
)
==
0
)
&&
strncmp
(
line
,
"cpu cores"
,
9
)
==
0
)
{
const
char
*
v
=
strchr
(
line
,
':'
)
+
2
;
*
numOfCores
=
atof
(
v
);
done
|=
2
;
}
}
}
if
(
line
!=
NULL
)
free
(
line
);
return
info
;
taosCloseFile
(
&
pFile
);
return
code
;
}
#endif
#endif
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录