Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
benchmark
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
benchmark
Commits
03c4485d
Commit
03c4485d
authored
Oct 07, 2016
by
Eric Fiselier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix #295. Remove use of BSD extensions for comparing strings
parent
36a251ab
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
3 deletions
+19
-3
sysinfo.cc
src/sysinfo.cc
+19
-3
No files found.
src/sysinfo.cc
View file @
03c4485d
...
@@ -87,6 +87,22 @@ bool ReadIntFromFile(const char* file, long* value) {
...
@@ -87,6 +87,22 @@ bool ReadIntFromFile(const char* file, long* value) {
}
}
#endif
#endif
#if defined BENCHMARK_OS_LINUX || defined BENCHMARK_OS_CYGWIN
static
std
::
string
convertToLowerCase
(
std
::
string
s
)
{
for
(
auto
&
ch
:
s
)
ch
=
std
::
tolower
(
ch
);
return
s
;
}
static
bool
startsWithKey
(
std
::
string
Value
,
std
::
string
Key
,
bool
IgnoreCase
=
true
)
{
if
(
IgnoreCase
)
{
Key
=
convertToLowerCase
(
std
::
move
(
Key
));
Value
=
convertToLowerCase
(
std
::
move
(
Value
));
}
return
Value
.
compare
(
0
,
Key
.
size
(),
Key
)
==
0
;
}
#endif
void
InitializeSystemInfo
()
{
void
InitializeSystemInfo
()
{
#if defined BENCHMARK_OS_LINUX || defined BENCHMARK_OS_CYGWIN
#if defined BENCHMARK_OS_LINUX || defined BENCHMARK_OS_CYGWIN
char
line
[
1024
];
char
line
[
1024
];
...
@@ -160,21 +176,21 @@ void InitializeSystemInfo() {
...
@@ -160,21 +176,21 @@ void InitializeSystemInfo() {
// When parsing the "cpu MHz" and "bogomips" (fallback) entries, we only
// When parsing the "cpu MHz" and "bogomips" (fallback) entries, we only
// accept postive values. Some environments (virtual machines) report zero,
// accept postive values. Some environments (virtual machines) report zero,
// which would cause infinite looping in WallTime_Init.
// which would cause infinite looping in WallTime_Init.
if
(
!
saw_mhz
&&
st
rncasecmp
(
line
,
"cpu MHz"
,
sizeof
(
"cpu MHz"
)
-
1
)
==
0
)
{
if
(
!
saw_mhz
&&
st
artsWithKey
(
line
,
"cpu MHz"
)
)
{
const
char
*
freqstr
=
strchr
(
line
,
':'
);
const
char
*
freqstr
=
strchr
(
line
,
':'
);
if
(
freqstr
)
{
if
(
freqstr
)
{
cpuinfo_cycles_per_second
=
strtod
(
freqstr
+
1
,
&
err
)
*
1000000.0
;
cpuinfo_cycles_per_second
=
strtod
(
freqstr
+
1
,
&
err
)
*
1000000.0
;
if
(
freqstr
[
1
]
!=
'\0'
&&
*
err
==
'\0'
&&
cpuinfo_cycles_per_second
>
0
)
if
(
freqstr
[
1
]
!=
'\0'
&&
*
err
==
'\0'
&&
cpuinfo_cycles_per_second
>
0
)
saw_mhz
=
true
;
saw_mhz
=
true
;
}
}
}
else
if
(
st
rncasecmp
(
line
,
"bogomips"
,
sizeof
(
"bogomips"
)
-
1
)
==
0
)
{
}
else
if
(
st
artsWithKey
(
line
,
"bogomips"
)
)
{
const
char
*
freqstr
=
strchr
(
line
,
':'
);
const
char
*
freqstr
=
strchr
(
line
,
':'
);
if
(
freqstr
)
{
if
(
freqstr
)
{
bogo_clock
=
strtod
(
freqstr
+
1
,
&
err
)
*
1000000.0
;
bogo_clock
=
strtod
(
freqstr
+
1
,
&
err
)
*
1000000.0
;
if
(
freqstr
[
1
]
!=
'\0'
&&
*
err
==
'\0'
&&
bogo_clock
>
0
)
if
(
freqstr
[
1
]
!=
'\0'
&&
*
err
==
'\0'
&&
bogo_clock
>
0
)
saw_bogo
=
true
;
saw_bogo
=
true
;
}
}
}
else
if
(
st
rncmp
(
line
,
"processor"
,
sizeof
(
"processor"
)
-
1
)
==
0
)
{
}
else
if
(
st
artsWithKey
(
line
,
"processor"
,
/*IgnoreCase*/
false
)
)
{
// The above comparison is case-sensitive because ARM kernels often
// The above comparison is case-sensitive because ARM kernels often
// include a "Processor" line that tells you about the CPU, distinct
// include a "Processor" line that tells you about the CPU, distinct
// from the usual "processor" lines that give you CPU ids. No current
// from the usual "processor" lines that give you CPU ids. No current
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment