| 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 1915 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1926 | 1926 |
| 1927 private: | 1927 private: |
| 1928 JSONArray* jsarr_; | 1928 JSONArray* jsarr_; |
| 1929 }; | 1929 }; |
| 1930 | 1930 |
| 1931 | 1931 |
| 1932 static bool HandleVM(JSONStream* js) { | 1932 static bool HandleVM(JSONStream* js) { |
| 1933 JSONObject jsobj(js); | 1933 JSONObject jsobj(js); |
| 1934 jsobj.AddProperty("type", "VM"); | 1934 jsobj.AddProperty("type", "VM"); |
| 1935 jsobj.AddProperty("id", "vm"); | 1935 jsobj.AddProperty("id", "vm"); |
| 1936 jsobj.AddProperty("architecture", CPU::Id()); | 1936 jsobj.AddProperty("targetCPU", CPU::Id()); |
| 1937 jsobj.AddProperty("hostCPU", HostCPUFeatures::hardware()); |
| 1937 jsobj.AddProperty("version", Version::String()); | 1938 jsobj.AddProperty("version", Version::String()); |
| 1938 jsobj.AddProperty("assertsEnabled", FLAG_enable_asserts); | 1939 jsobj.AddProperty("assertsEnabled", FLAG_enable_asserts); |
| 1939 jsobj.AddProperty("typeChecksEnabled", FLAG_enable_type_checks); | 1940 jsobj.AddProperty("typeChecksEnabled", FLAG_enable_type_checks); |
| 1940 int64_t start_time_micros = Dart::vm_isolate()->start_time(); | 1941 int64_t start_time_micros = Dart::vm_isolate()->start_time(); |
| 1941 int64_t uptime_micros = (OS::GetCurrentTimeMicros() - start_time_micros); | 1942 int64_t uptime_micros = (OS::GetCurrentTimeMicros() - start_time_micros); |
| 1942 double seconds = (static_cast<double>(uptime_micros) / | 1943 double seconds = (static_cast<double>(uptime_micros) / |
| 1943 static_cast<double>(kMicrosecondsPerSecond)); | 1944 static_cast<double>(kMicrosecondsPerSecond)); |
| 1944 jsobj.AddProperty("uptime", seconds); | 1945 jsobj.AddProperty("uptime", seconds); |
| 1945 | 1946 |
| 1946 // Construct the isolate list. | 1947 // Construct the isolate list. |
| 1947 { | 1948 { |
| 1948 JSONArray jsarr(&jsobj, "isolates"); | 1949 JSONArray jsarr(&jsobj, "isolates"); |
| 1949 ServiceIsolateVisitor visitor(&jsarr); | 1950 ServiceIsolateVisitor visitor(&jsarr); |
| 1950 Isolate::VisitIsolates(&visitor); | 1951 Isolate::VisitIsolates(&visitor); |
| 1951 } | 1952 } |
| 1952 return true; | 1953 return true; |
| 1953 } | 1954 } |
| 1954 | 1955 |
| 1955 | 1956 |
| 1957 static bool HandleFlags(JSONStream* js) { |
| 1958 if (js->num_arguments() == 1) { |
| 1959 Flags::PrintJSON(js); |
| 1960 return true; |
| 1961 } else if (js->num_arguments() == 2) { |
| 1962 const char* arg = js->GetArgument(1); |
| 1963 if (strcmp(arg, "set") == 0) { |
| 1964 if (js->num_arguments() > 2) { |
| 1965 PrintError(js, "expected at most 2 arguments but found %" Pd "\n", |
| 1966 js->num_arguments()); |
| 1967 } else { |
| 1968 if (js->HasOption("name") && js->HasOption("value")) { |
| 1969 JSONObject jsobj(js); |
| 1970 const char* flag_name = js->LookupOption("name"); |
| 1971 const char* flag_value = js->LookupOption("value"); |
| 1972 const char* error = NULL; |
| 1973 if (Flags::SetFlag(flag_name, flag_value, &error)) { |
| 1974 jsobj.AddProperty("type", "Success"); |
| 1975 jsobj.AddProperty("id", ""); |
| 1976 } else { |
| 1977 jsobj.AddProperty("type", "Failure"); |
| 1978 jsobj.AddProperty("id", ""); |
| 1979 jsobj.AddProperty("message", error); |
| 1980 } |
| 1981 } else { |
| 1982 PrintError(js, "expected to find 'name' and 'value' options"); |
| 1983 } |
| 1984 } |
| 1985 } |
| 1986 return true; |
| 1987 } else { |
| 1988 PrintError(js, "Command too long"); |
| 1989 return true; |
| 1990 } |
| 1991 } |
| 1992 |
| 1993 |
| 1956 static RootMessageHandlerEntry root_handlers[] = { | 1994 static RootMessageHandlerEntry root_handlers[] = { |
| 1957 { "_echo", HandleRootEcho }, | 1995 { "_echo", HandleRootEcho }, |
| 1958 { "vm", HandleVM }, | 1996 { "vm", HandleVM }, |
| 1997 { "flags", HandleFlags }, |
| 1959 }; | 1998 }; |
| 1960 | 1999 |
| 1961 | 2000 |
| 1962 static RootMessageHandler FindRootMessageHandler(const char* command) { | 2001 static RootMessageHandler FindRootMessageHandler(const char* command) { |
| 1963 intptr_t num_message_handlers = sizeof(root_handlers) / | 2002 intptr_t num_message_handlers = sizeof(root_handlers) / |
| 1964 sizeof(root_handlers[0]); | 2003 sizeof(root_handlers[0]); |
| 1965 for (intptr_t i = 0; i < num_message_handlers; i++) { | 2004 for (intptr_t i = 0; i < num_message_handlers; i++) { |
| 1966 const RootMessageHandlerEntry& entry = root_handlers[i]; | 2005 const RootMessageHandlerEntry& entry = root_handlers[i]; |
| 1967 if (strcmp(command, entry.command) == 0) { | 2006 if (strcmp(command, entry.command) == 0) { |
| 1968 return entry.handler; | 2007 return entry.handler; |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2064 while (current != NULL) { | 2103 while (current != NULL) { |
| 2065 if (strcmp(name, current->name()) == 0) { | 2104 if (strcmp(name, current->name()) == 0) { |
| 2066 return current; | 2105 return current; |
| 2067 } | 2106 } |
| 2068 current = current->next(); | 2107 current = current->next(); |
| 2069 } | 2108 } |
| 2070 return NULL; | 2109 return NULL; |
| 2071 } | 2110 } |
| 2072 | 2111 |
| 2073 } // namespace dart | 2112 } // namespace dart |
| OLD | NEW |