| 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 void CpuInfo::InitOnce() { | |
| 22 InitializeFields(); | |
| 23 } | |
| 24 | |
| 25 | |
| 26 bool CpuInfo::FieldContains(const char* field, const char* search_string) { | |
| 27 ASSERT(search_string != NULL); | |
| 28 char dest[1024]; | |
| 29 size_t dest_len = 1024; | |
| 30 | |
| 31 ASSERT(HasField(field)); | |
| 32 if (sysctlbyname(field, dest, &dest_len, NULL, 0) != 0) { | |
| 33 UNREACHABLE(); | |
| 34 return false; | |
| 35 } | |
| 36 | |
| 37 return (strcasestr(dest, search_string) != NULL); | |
| 38 } | |
| 39 | |
| 40 | |
| 41 char* CpuInfo::ExtractField(const char* field) { | |
| 42 ASSERT(field != NULL); | |
| 43 size_t result_len; | |
| 44 | |
| 45 ASSERT(HasField(field)); | |
| 46 if (sysctlbyname(field, NULL, &result_len, NULL, 0) != 0) { | |
| 47 UNREACHABLE(); | |
| 48 return 0; | |
| 49 } | |
| 50 | |
| 51 char* result = new char[result_len]; | |
| 52 if (sysctlbyname(field, result, &result_len, NULL, 0) != 0) { | |
| 53 UNREACHABLE(); | |
| 54 return 0; | |
| 55 } | |
| 56 | |
| 57 return result; | |
| 58 } | |
| 59 | |
| 60 | |
| 61 bool CpuInfo::HasField(const char* field) { | |
| 62 ASSERT(field != NULL); | |
| 63 int ret = sysctlbyname(field, NULL, NULL, NULL, 0); | |
| 64 return (ret != ENOENT); | |
| 65 } | |
| 66 | |
| 67 | |
| 68 const char* CpuInfo::fields_[kCpuInfoMax] = {0}; | |
| 69 void CpuInfo::InitializeFields() { | |
| 70 fields_[kCpuInfoProcessor] = "machdep.cpu.vendor"; | |
| 71 fields_[kCpuInfoModel] = "machdep.cpu.brand_string"; | |
| 72 fields_[kCpuInfoFeatures] = "machdep.cpu.features"; | |
| 73 } | |
| 74 | |
| 75 } // namespace dart | |
| 76 | |
| 77 #endif // defined(TARGET_OS_MACOS) | |
| OLD | NEW |