Flutter Engine
The Flutter Engine
third_party
dart-lang
sdk
runtime
vm
cpuinfo_macos.cc
Go to the documentation of this file.
1
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2
// for details. All rights reserved. Use of this source code is governed by a
3
// BSD-style license that can be found in the LICENSE file.
4
5
#include "
vm/globals.h
"
6
#if defined(DART_HOST_OS_MACOS)
7
8
#include "
vm/cpuinfo.h
"
9
10
#include <errno.h>
// NOLINT
11
#include <sys/sysctl.h>
// NOLINT
12
#include <sys/types.h>
// NOLINT
13
14
#include "
platform/assert.h
"
15
16
namespace
dart
{
17
18
CpuInfoMethod
CpuInfo::method_ =
kCpuInfoDefault
;
19
const
char
* CpuInfo::fields_[
kCpuInfoMax
] = {};
20
21
void
CpuInfo::Init
() {
22
method_ =
kCpuInfoSystem
;
23
24
fields_[
kCpuInfoProcessor
] =
"machdep.cpu.vendor"
;
25
fields_[
kCpuInfoModel
] =
"machdep.cpu.brand_string"
;
26
fields_[
kCpuInfoHardware
] =
"machdep.cpu.brand_string"
;
27
fields_[
kCpuInfoFeatures
] =
"machdep.cpu.features"
;
28
fields_[
kCpuInfoArchitecture
] =
nullptr
;
29
}
30
31
void
CpuInfo::Cleanup
() {}
32
33
bool
CpuInfo::FieldContains
(
CpuInfoIndices
idx,
const
char
* search_string) {
34
ASSERT
(method_ !=
kCpuInfoDefault
);
35
ASSERT
(search_string !=
nullptr
);
36
const
char
* field =
FieldName
(idx);
37
char
dest
[1024];
38
size_t
dest_len = 1024;
39
40
ASSERT
(
HasField
(field));
41
if
(sysctlbyname(field,
dest
, &dest_len,
nullptr
, 0) != 0) {
42
UNREACHABLE
();
43
return
false
;
44
}
45
46
return
(strcasestr(
dest
, search_string) !=
nullptr
);
47
}
48
49
const
char
* CpuInfo::ExtractField(
CpuInfoIndices
idx) {
50
ASSERT
(method_ !=
kCpuInfoDefault
);
51
const
char
* field =
FieldName
(idx);
52
ASSERT
(field !=
nullptr
);
53
size_t
result_len;
54
55
ASSERT
(
HasField
(field));
56
if
(sysctlbyname(field,
nullptr
, &result_len,
nullptr
, 0) != 0) {
57
UNREACHABLE
();
58
return
0;
59
}
60
61
char
*
result
=
reinterpret_cast<
char
*
>
(
malloc
(result_len));
62
if
(sysctlbyname(field,
result
, &result_len,
nullptr
, 0) != 0) {
63
UNREACHABLE
();
64
return
0;
65
}
66
67
return
result
;
68
}
69
70
bool
CpuInfo::HasField
(
const
char
* field) {
71
ASSERT
(method_ !=
kCpuInfoDefault
);
72
ASSERT
(field !=
nullptr
);
73
int
ret = sysctlbyname(field,
nullptr
,
nullptr
,
nullptr
, 0);
74
return
(ret == 0);
75
}
76
77
}
// namespace dart
78
79
#endif
// defined(DART_HOST_OS_MACOS)
assert.h
UNREACHABLE
#define UNREACHABLE()
Definition:
assert.h:248
dart::CpuInfo::FieldName
static const char * FieldName(CpuInfoIndices idx)
Definition:
cpuinfo.h:46
dart::CpuInfo::Init
static void Init()
dart::CpuInfo::Cleanup
static void Cleanup()
dart::CpuInfo::FieldContains
static bool FieldContains(CpuInfoIndices idx, const char *search_string)
dart::CpuInfo::HasField
static bool HasField(const char *field)
cpuinfo.h
ASSERT
#define ASSERT(E)
Definition:
entrypoints_verification_test.cc:25
result
GAsyncResult * result
Definition:
fl_text_input_plugin.cc:106
dart
Definition:
dart_vm.cc:33
dart::CpuInfoMethod
CpuInfoMethod
Definition:
cpuinfo.h:25
dart::kCpuInfoDefault
@ kCpuInfoDefault
Definition:
cpuinfo.h:38
dart::kCpuInfoSystem
@ kCpuInfoSystem
Definition:
cpuinfo.h:30
dart::malloc
void * malloc(size_t size)
Definition:
allocation.cc:19
dart::CpuInfoIndices
CpuInfoIndices
Definition:
cpuinfo.h:15
dart::kCpuInfoFeatures
@ kCpuInfoFeatures
Definition:
cpuinfo.h:19
dart::kCpuInfoArchitecture
@ kCpuInfoArchitecture
Definition:
cpuinfo.h:20
dart::kCpuInfoProcessor
@ kCpuInfoProcessor
Definition:
cpuinfo.h:16
dart::kCpuInfoHardware
@ kCpuInfoHardware
Definition:
cpuinfo.h:18
dart::kCpuInfoMax
@ kCpuInfoMax
Definition:
cpuinfo.h:21
dart::kCpuInfoModel
@ kCpuInfoModel
Definition:
cpuinfo.h:17
zip.dest
dest
Definition:
zip.py:79
globals.h
Generated on Sun Jun 23 2024 21:55:39 for Flutter Engine by
1.9.4