OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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/service.h" | 5 #include "vm/service.h" |
6 | 6 |
7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
8 #include "platform/globals.h" | 8 #include "platform/globals.h" |
9 | 9 |
10 #include "vm/compiler.h" | 10 #include "vm/compiler.h" |
(...skipping 1894 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1905 | 1905 |
1906 private: | 1906 private: |
1907 JSONArray* jsarr_; | 1907 JSONArray* jsarr_; |
1908 }; | 1908 }; |
1909 | 1909 |
1910 | 1910 |
1911 static bool HandleVM(JSONStream* js) { | 1911 static bool HandleVM(JSONStream* js) { |
1912 JSONObject jsobj(js); | 1912 JSONObject jsobj(js); |
1913 jsobj.AddProperty("type", "VM"); | 1913 jsobj.AddProperty("type", "VM"); |
1914 jsobj.AddProperty("id", "vm"); | 1914 jsobj.AddProperty("id", "vm"); |
1915 jsobj.AddProperty("architecture", CPU::Id()); | 1915 jsobj.AddProperty("targetCPU", CPU::Id()); |
| 1916 jsobj.AddProperty("hostCPU", HostCPUFeatures::hardware()); |
1916 jsobj.AddProperty("version", Version::String()); | 1917 jsobj.AddProperty("version", Version::String()); |
1917 jsobj.AddProperty("assertsEnabled", FLAG_enable_asserts); | 1918 jsobj.AddProperty("assertsEnabled", FLAG_enable_asserts); |
1918 jsobj.AddProperty("typeChecksEnabled", FLAG_enable_type_checks); | 1919 jsobj.AddProperty("typeChecksEnabled", FLAG_enable_type_checks); |
1919 int64_t start_time_micros = Dart::vm_isolate()->start_time(); | 1920 int64_t start_time_micros = Dart::vm_isolate()->start_time(); |
1920 int64_t uptime_micros = (OS::GetCurrentTimeMicros() - start_time_micros); | 1921 int64_t uptime_micros = (OS::GetCurrentTimeMicros() - start_time_micros); |
1921 double seconds = (static_cast<double>(uptime_micros) / | 1922 double seconds = (static_cast<double>(uptime_micros) / |
1922 static_cast<double>(kMicrosecondsPerSecond)); | 1923 static_cast<double>(kMicrosecondsPerSecond)); |
1923 jsobj.AddProperty("uptime", seconds); | 1924 jsobj.AddProperty("uptime", seconds); |
1924 | 1925 |
1925 // Construct the isolate list. | 1926 // Construct the isolate list. |
1926 { | 1927 { |
1927 JSONArray jsarr(&jsobj, "isolates"); | 1928 JSONArray jsarr(&jsobj, "isolates"); |
1928 ServiceIsolateVisitor visitor(&jsarr); | 1929 ServiceIsolateVisitor visitor(&jsarr); |
1929 Isolate::VisitIsolates(&visitor); | 1930 Isolate::VisitIsolates(&visitor); |
1930 } | 1931 } |
1931 return true; | 1932 return true; |
1932 } | 1933 } |
1933 | 1934 |
1934 | 1935 |
| 1936 static bool HandleFlags(JSONStream* js) { |
| 1937 if (js->num_arguments() == 1) { |
| 1938 Flags::PrintJSON(js); |
| 1939 return true; |
| 1940 } else if (js->num_arguments() == 2) { |
| 1941 const char* arg = js->GetArgument(1); |
| 1942 if (strcmp(arg, "set") == 0) { |
| 1943 if (js->num_arguments() > 2) { |
| 1944 PrintError(js, "expected at most 2 arguments but found %" Pd "\n", |
| 1945 js->num_arguments()); |
| 1946 } else { |
| 1947 if (js->HasOption("name") && js->HasOption("value")) { |
| 1948 JSONObject jsobj(js); |
| 1949 const char* flag_name = js->LookupOption("name"); |
| 1950 const char* flag_value = js->LookupOption("value"); |
| 1951 const char* error = NULL; |
| 1952 if (Flags::SetFlag(flag_name, flag_value, &error)) { |
| 1953 jsobj.AddProperty("type", "Success"); |
| 1954 jsobj.AddProperty("id", ""); |
| 1955 } else { |
| 1956 jsobj.AddProperty("type", "Failure"); |
| 1957 jsobj.AddProperty("id", ""); |
| 1958 jsobj.AddProperty("message", error); |
| 1959 } |
| 1960 } else { |
| 1961 PrintError(js, "expected to find 'name' and 'value' options"); |
| 1962 } |
| 1963 } |
| 1964 } |
| 1965 return true; |
| 1966 } else { |
| 1967 PrintError(js, "Command too long"); |
| 1968 return true; |
| 1969 } |
| 1970 } |
| 1971 |
| 1972 |
1935 static RootMessageHandlerEntry root_handlers[] = { | 1973 static RootMessageHandlerEntry root_handlers[] = { |
1936 { "_echo", HandleRootEcho }, | 1974 { "_echo", HandleRootEcho }, |
1937 { "vm", HandleVM }, | 1975 { "vm", HandleVM }, |
| 1976 { "flags", HandleFlags }, |
1938 }; | 1977 }; |
1939 | 1978 |
1940 | 1979 |
1941 static RootMessageHandler FindRootMessageHandler(const char* command) { | 1980 static RootMessageHandler FindRootMessageHandler(const char* command) { |
1942 intptr_t num_message_handlers = sizeof(root_handlers) / | 1981 intptr_t num_message_handlers = sizeof(root_handlers) / |
1943 sizeof(root_handlers[0]); | 1982 sizeof(root_handlers[0]); |
1944 for (intptr_t i = 0; i < num_message_handlers; i++) { | 1983 for (intptr_t i = 0; i < num_message_handlers; i++) { |
1945 const RootMessageHandlerEntry& entry = root_handlers[i]; | 1984 const RootMessageHandlerEntry& entry = root_handlers[i]; |
1946 if (strcmp(command, entry.command) == 0) { | 1985 if (strcmp(command, entry.command) == 0) { |
1947 return entry.handler; | 1986 return entry.handler; |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2043 while (current != NULL) { | 2082 while (current != NULL) { |
2044 if (strcmp(name, current->name()) == 0) { | 2083 if (strcmp(name, current->name()) == 0) { |
2045 return current; | 2084 return current; |
2046 } | 2085 } |
2047 current = current->next(); | 2086 current = current->next(); |
2048 } | 2087 } |
2049 return NULL; | 2088 return NULL; |
2050 } | 2089 } |
2051 | 2090 |
2052 } // namespace dart | 2091 } // namespace dart |
OLD | NEW |