| 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 #ifndef VM_CPUINFO_H_ | |
| 6 #define VM_CPUINFO_H_ | |
| 7 | |
| 8 #include "platform/assert.h" | |
| 9 #include "vm/allocation.h" | |
| 10 | |
| 11 namespace dart { | |
| 12 | |
| 13 class CpuInfo : public AllStatic { | |
| 14 public: | |
| 15 // Indices into cpuinfo field name arrays. | |
| 16 enum CpuInfoIndices { | |
| 17 kCpuInfoProcessor = 0, | |
| 18 kCpuInfoModel = 1, | |
| 19 kCpuInfoFeatures = 2, | |
| 20 kCpuInfoMax = 3, | |
| 21 }; | |
| 22 | |
| 23 // If necessary, allocates a buffer [data_] and reads cpuinfo into | |
| 24 // that buffer. | |
| 25 static void InitOnce(); | |
| 26 | |
| 27 static const char* FieldName(CpuInfoIndices idx) { | |
| 28 ASSERT((idx >= 0) && (idx < kCpuInfoMax)); | |
| 29 return fields_[idx]; | |
| 30 } | |
| 31 | |
| 32 // Returns true if the cpuinfo field [field] contains the | |
| 33 // string [search_string]. | |
| 34 static bool FieldContains(const char* field, const char* search_string); | |
| 35 static bool FieldContainsById(CpuInfoIndices idx, const char* search_string) { | |
| 36 return FieldContains(FieldName(idx), search_string); | |
| 37 } | |
| 38 | |
| 39 // Returns true if the cpuinfo field [field] exists and is non-empty. | |
| 40 static bool HasField(const char* field); | |
| 41 | |
| 42 // Reads the cpuinfo field [field] into the buffer [dest] and returns the | |
| 43 // length of the field. | |
| 44 // If [dest] is NULL, ExtractField just returns the length. | |
| 45 static char* ExtractField(const char* field); | |
| 46 | |
| 47 // Reads the cpuinfo field describing the CPU model into the buffer [dest]. | |
| 48 static char* GetCpuModel() { | |
| 49 ASSERT(HasField(FieldName(kCpuInfoModel))); | |
| 50 return ExtractField(FieldName(kCpuInfoModel)); | |
| 51 } | |
| 52 | |
| 53 private: | |
| 54 // On Linux and Android data_ holds /proc/cpuinfo after Read(). | |
| 55 static char* data_; | |
| 56 | |
| 57 // On Linux and Android, the length of /proc/cpuinfo. | |
| 58 static intptr_t datalen_; | |
| 59 | |
| 60 // Fills in the fields_ array. | |
| 61 static void InitializeFields(); | |
| 62 | |
| 63 // Cpuinfo field names. | |
| 64 static const char* fields_[kCpuInfoMax]; | |
| 65 }; | |
| 66 | |
| 67 } // namespace dart | |
| 68 | |
| 69 #endif // VM_CPUINFO_H_ | |
| OLD | NEW |