Flutter Engine
The Flutter Engine
cpuinfo.h
Go to the documentation of this file.
1// Copyright (c) 2014, 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 RUNTIME_VM_CPUINFO_H_
6#define RUNTIME_VM_CPUINFO_H_
7
8#include "platform/assert.h"
9#include "platform/utils.h"
10#include "vm/allocation.h"
11
12namespace dart {
13
14// Indices into cpuinfo field name arrays.
22};
23
24// For Intel architectures, the method to use to get CPU information.
26 // Use the cpuid instruction.
28
29 // Use system calls.
31
32 // Don't query anything.
34
35 // Use whatever the default is for a particular OS:
36 // Linux, Windows -> CpuId,
37 // Android, MacOS -> System.
39};
40
41class CpuInfo : public AllStatic {
42 public:
43 static void Init();
44 static void Cleanup();
45
46 static const char* FieldName(CpuInfoIndices idx) {
47 ASSERT((idx >= 0) && (idx < kCpuInfoMax));
48 return fields_[idx];
49 }
50
51 // Returns true if the cpuinfo field contains the string.
52 static bool FieldContains(CpuInfoIndices idx, const char* search_string);
53
54 // Returns true if the cpuinfo field [field] exists and is non-empty.
55 static bool HasField(const char* field);
56
57 // Returns the field describing the CPU model. Caller is responsible for
58 // freeing the result.
59 static const char* GetCpuModel() {
61 return ExtractField(kCpuInfoHardware);
62 } else {
63 return Utils::StrDup("Unknown");
64 }
65 }
66
67 private:
68 // Returns the field. Caller is responsible for freeing the result.
69 static const char* ExtractField(CpuInfoIndices idx);
70
71 // The method to use to acquire info about the CPU.
72 static CpuInfoMethod method_;
73
74 // Cpuinfo field names.
75 static const char* fields_[kCpuInfoMax];
76};
77
78} // namespace dart
79
80#endif // RUNTIME_VM_CPUINFO_H_
static const char * FieldName(CpuInfoIndices idx)
Definition: cpuinfo.h:46
static void Init()
static const char * GetCpuModel()
Definition: cpuinfo.h:59
static void Cleanup()
static bool FieldContains(CpuInfoIndices idx, const char *search_string)
static bool HasField(const char *field)
static char * StrDup(const char *s)
#define ASSERT(E)
Definition: dart_vm.cc:33
CpuInfoMethod
Definition: cpuinfo.h:25
@ kCpuInfoNone
Definition: cpuinfo.h:33
@ kCpuInfoDefault
Definition: cpuinfo.h:38
@ kCpuInfoCpuId
Definition: cpuinfo.h:27
@ kCpuInfoSystem
Definition: cpuinfo.h:30
CpuInfoIndices
Definition: cpuinfo.h:15
@ kCpuInfoFeatures
Definition: cpuinfo.h:19
@ kCpuInfoArchitecture
Definition: cpuinfo.h:20
@ kCpuInfoProcessor
Definition: cpuinfo.h:16
@ kCpuInfoHardware
Definition: cpuinfo.h:18
@ kCpuInfoMax
Definition: cpuinfo.h:21
@ kCpuInfoModel
Definition: cpuinfo.h:17