| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/globals.h" | 5 #include "vm/globals.h" |
| 6 #if defined(TARGET_OS_LINUX) | 6 #if defined(TARGET_OS_LINUX) |
| 7 | 7 |
| 8 #include "vm/cpuinfo.h" | 8 #include "vm/cpuinfo.h" |
| 9 #include "vm/cpuid.h" | 9 #include "vm/cpuid.h" |
| 10 #include "vm/proccpuinfo.h" | 10 #include "vm/proccpuinfo.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 CpuId::Cleanup(); | 60 CpuId::Cleanup(); |
| 61 } else { | 61 } else { |
| 62 ASSERT(method_ == kCpuInfoSystem); | 62 ASSERT(method_ == kCpuInfoSystem); |
| 63 ProcCpuInfo::Cleanup(); | 63 ProcCpuInfo::Cleanup(); |
| 64 } | 64 } |
| 65 } | 65 } |
| 66 | 66 |
| 67 | 67 |
| 68 bool CpuInfo::FieldContains(CpuInfoIndices idx, const char* search_string) { | 68 bool CpuInfo::FieldContains(CpuInfoIndices idx, const char* search_string) { |
| 69 if (method_ == kCpuInfoCpuId) { | 69 if (method_ == kCpuInfoCpuId) { |
| 70 return strstr(CpuId::field(idx), search_string); | 70 const char* field = CpuId::field(idx); |
| 71 bool contains = (strstr(field, search_string) != NULL); |
| 72 free(const_cast<char*>(field)); |
| 73 return contains; |
| 71 } else { | 74 } else { |
| 72 ASSERT(method_ == kCpuInfoSystem); | 75 ASSERT(method_ == kCpuInfoSystem); |
| 73 return ProcCpuInfo::FieldContains(FieldName(idx), search_string); | 76 return ProcCpuInfo::FieldContains(FieldName(idx), search_string); |
| 74 } | 77 } |
| 75 } | 78 } |
| 76 | 79 |
| 77 | 80 |
| 78 bool CpuInfo::FieldContainsByString(const char* field, | |
| 79 const char* search_string) { | |
| 80 if (method_ == kCpuInfoCpuId) { | |
| 81 for (int i = 0; i < kCpuInfoMax; i++) { | |
| 82 if (strcmp(field, fields_[i]) == 0) { | |
| 83 return FieldContains(static_cast<CpuInfoIndices>(i), search_string); | |
| 84 } | |
| 85 } | |
| 86 UNIMPLEMENTED(); | |
| 87 return false; | |
| 88 } else { | |
| 89 ASSERT(method_ == kCpuInfoSystem); | |
| 90 return ProcCpuInfo::FieldContains(field, search_string); | |
| 91 } | |
| 92 } | |
| 93 | |
| 94 | |
| 95 const char* CpuInfo::ExtractField(CpuInfoIndices idx) { | 81 const char* CpuInfo::ExtractField(CpuInfoIndices idx) { |
| 96 if (method_ == kCpuInfoCpuId) { | 82 if (method_ == kCpuInfoCpuId) { |
| 97 return CpuId::field(idx); | 83 return CpuId::field(idx); |
| 98 } else { | 84 } else { |
| 99 ASSERT(method_ == kCpuInfoSystem); | 85 ASSERT(method_ == kCpuInfoSystem); |
| 100 return ProcCpuInfo::ExtractField(FieldName(idx)); | 86 return ProcCpuInfo::ExtractField(FieldName(idx)); |
| 101 } | 87 } |
| 102 } | 88 } |
| 103 | 89 |
| 104 | 90 |
| 105 const char* CpuInfo::ExtractFieldByString(const char* field) { | |
| 106 if (method_ == kCpuInfoCpuId) { | |
| 107 for (int i = 0; i < kCpuInfoMax; i++) { | |
| 108 if (strcmp(field, fields_[i]) == 0) { | |
| 109 return ExtractField(static_cast<CpuInfoIndices>(i)); | |
| 110 } | |
| 111 } | |
| 112 UNIMPLEMENTED(); | |
| 113 return NULL; | |
| 114 } else { | |
| 115 ASSERT(method_ == kCpuInfoSystem); | |
| 116 return ProcCpuInfo::ExtractField(field); | |
| 117 } | |
| 118 } | |
| 119 | |
| 120 | |
| 121 bool CpuInfo::HasField(const char* field) { | 91 bool CpuInfo::HasField(const char* field) { |
| 122 if (method_ == kCpuInfoCpuId) { | 92 if (method_ == kCpuInfoCpuId) { |
| 123 return (strcmp(field, fields_[kCpuInfoProcessor]) == 0) || | 93 return (strcmp(field, fields_[kCpuInfoProcessor]) == 0) || |
| 124 (strcmp(field, fields_[kCpuInfoModel]) == 0) || | 94 (strcmp(field, fields_[kCpuInfoModel]) == 0) || |
| 125 (strcmp(field, fields_[kCpuInfoHardware]) == 0) || | 95 (strcmp(field, fields_[kCpuInfoHardware]) == 0) || |
| 126 (strcmp(field, fields_[kCpuInfoFeatures]) == 0); | 96 (strcmp(field, fields_[kCpuInfoFeatures]) == 0); |
| 127 } else { | 97 } else { |
| 128 ASSERT(method_ == kCpuInfoSystem); | 98 ASSERT(method_ == kCpuInfoSystem); |
| 129 return ProcCpuInfo::HasField(field); | 99 return ProcCpuInfo::HasField(field); |
| 130 } | 100 } |
| 131 } | 101 } |
| 132 | 102 |
| 133 } // namespace dart | 103 } // namespace dart |
| 134 | 104 |
| 135 #endif // defined(TARGET_OS_LINUX) | 105 #endif // defined(TARGET_OS_LINUX) |
| OLD | NEW |