Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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(TARGET_OS_MACOS) | |
| 7 | |
| 8 #include "vm/cpuinfo.h" | |
| 9 | |
| 10 #include <errno.h> // NOLINT | |
| 11 #include <sys/types.h> // NOLINT | |
| 12 #include <sys/sysctl.h> // NOLINT | |
| 13 | |
| 14 #include "platform/assert.h" | |
| 15 | |
| 16 namespace dart { | |
| 17 | |
| 18 char* CpuInfo::data_ = NULL; | |
| 19 intptr_t CpuInfo::datalen_ = 0; | |
| 20 | |
| 21 // No-op on MacOS. | |
| 22 void CpuInfo::InitOnce() {} | |
| 23 | |
| 24 | |
| 25 bool CpuInfo::FieldContains(const char* field, const char* search_string) { | |
| 26 ASSERT(search_string != NULL); | |
| 27 char dest[1024]; | |
| 28 size_t dest_len = 1024; | |
| 29 | |
| 30 ASSERT(HasField(field)); | |
| 31 if (sysctlbyname(field, dest, &dest_len, NULL, 0) != 0) { | |
| 32 UNREACHABLE(); | |
| 33 return false; | |
| 34 } | |
| 35 | |
| 36 return (strcasestr(dest, search_string) != NULL); | |
| 37 } | |
| 38 | |
| 39 | |
| 40 char* CpuInfo::ExtractField(const char* field) { | |
| 41 ASSERT(field != NULL); | |
| 42 size_t result_len; | |
| 43 | |
| 44 ASSERT(HasField(field)); | |
| 45 if (sysctlbyname(field, NULL, &result_len, NULL, 0) != 0) { | |
| 46 UNREACHABLE(); | |
| 47 return 0; | |
| 48 } | |
| 49 | |
| 50 char* result = new char[result_len]; | |
| 51 if (sysctlbyname(field, result, &result_len, NULL, 0) != 0) { | |
| 52 UNREACHABLE(); | |
| 53 return 0; | |
| 54 } | |
| 55 | |
| 56 return result; | |
| 57 } | |
| 58 | |
| 59 | |
| 60 bool CpuInfo::HasField(const char* field) { | |
| 61 ASSERT(field != NULL); | |
| 62 int ret = sysctlbyname(field, NULL, NULL, NULL, 0); | |
| 63 return (ret != ENOENT); | |
| 64 } | |
| 65 | |
| 66 | |
| 67 const char *CpuInfo::fields_[] = { | |
|
Ivan Posva
2014/01/21 21:41:02
How about adding index values for these fields?
zra
2014/01/24 21:18:27
Unfortunately, there are no designated initializer
| |
| 68 "machdep.cpu.vendor", | |
| 69 "machdep.cpu.brand_string", | |
|
Cutch
2014/01/15 20:50:49
Wouldn't it be better if the field names were abst
zra
2014/01/24 21:18:27
There is an abstracted interface through the enum
| |
| 70 "machdep.cpu.features", | |
| 71 }; | |
| 72 | |
| 73 } // namespace dart | |
| 74 | |
| 75 #endif // defined(TARGET_OS_MACOS) | |
| OLD | NEW |