Chromium Code Reviews| Index: runtime/vm/cpuinfo.h |
| =================================================================== |
| --- runtime/vm/cpuinfo.h (revision 0) |
| +++ runtime/vm/cpuinfo.h (revision 0) |
| @@ -0,0 +1,75 @@ |
| +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
|
siva
2014/02/21 19:28:55
2014
zra
2014/02/21 21:51:55
Done.
|
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +#ifndef VM_CPUINFO_H_ |
| +#define VM_CPUINFO_H_ |
| + |
| +#include "platform/assert.h" |
| +#include "vm/allocation.h" |
| + |
| +namespace dart { |
| + |
| +// Indices into cpuinfo field name arrays. |
| +enum CpuInfoIndices { |
| + kCpuInfoProcessor = 0, |
| + kCpuInfoModel = 1, |
| + kCpuInfoHardware = 2, |
| + kCpuInfoFeatures = 3, |
| + kCpuInfoMax = 4, |
| +}; |
| + |
| +// For Intel architectures, the method to use to get CPU information. |
| +enum CpuInfoMethod { |
| + // Use the cpuid instruction. |
| + kCpuInfoCpuId, |
| + |
| + // Use system calls. |
| + kCpuInfoSystem, |
| + |
| + // Use whatever the default is for a particular OS: |
| + // Linux, Windows -> CpuId, |
| + // Android, MacOS -> System. |
| + kCpuInfoDefault, |
| +}; |
| + |
| +class CpuInfo : public AllStatic { |
| + public: |
| + // If necessary, allocates a buffer [data_] and reads cpuinfo into |
| + // that buffer. |
| + static void InitOnce(CpuInfoMethod method); |
| + |
| + static const char* FieldName(CpuInfoIndices idx) { |
| + ASSERT((idx >= 0) && (idx < kCpuInfoMax)); |
| + return fields_[idx]; |
| + } |
| + |
| + // Returns true if the cpuinfo field contains the string. |
| + static bool FieldContains(CpuInfoIndices idx, const char* search_string); |
| + static bool FieldContainsByString( |
| + const char* field, const char* search_string); |
| + |
| + // Returns true if the cpuinfo field [field] exists and is non-empty. |
| + static bool HasField(const char* field); |
| + |
| + // Returns the field. |
| + static const char* ExtractField(CpuInfoIndices idx); |
| + static const char* ExtractFieldByString(const char* field); |
|
siva
2014/02/21 19:28:55
Document that the caller of this method is respons
zra
2014/02/21 21:51:55
Done.
|
| + |
| + // Returns the field describing the CPU model. |
|
siva
2014/02/21 19:28:55
Document that the caller of this method should fre
zra
2014/02/21 21:51:55
Done.
|
| + static const char* GetCpuModel() { |
| + ASSERT(HasField(FieldName(kCpuInfoModel))); |
| + return ExtractField(kCpuInfoModel); |
| + } |
| + |
| + private: |
| + // The method to use to acquire info about the CPU. |
| + static CpuInfoMethod method_; |
| + |
| + // Cpuinfo field names. |
| + static const char* fields_[kCpuInfoMax]; |
| +}; |
| + |
| +} // namespace dart |
| + |
| +#endif // VM_CPUINFO_H_ |