Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(277)

Side by Side Diff: runtime/vm/service_test.cc

Issue 409213004: Initial backend for metrics in Observatory (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/service.cc ('k') | sdk/lib/profiler/profiler.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "platform/globals.h" 5 #include "platform/globals.h"
6 6
7 #include "include/dart_debugger_api.h" 7 #include "include/dart_debugger_api.h"
8 #include "vm/dart_api_impl.h" 8 #include "vm/dart_api_impl.h"
9 #include "vm/dart_entry.h" 9 #include "vm/dart_entry.h"
10 #include "vm/debugger.h" 10 #include "vm/debugger.h"
(...skipping 1966 matching lines...) Expand 10 before | Expand all | Expand 10 after
1977 Service::HandleIsolateMessage(isolate, service_msg); 1977 Service::HandleIsolateMessage(isolate, service_msg);
1978 handler.HandleNextMessage(); 1978 handler.HandleNextMessage();
1979 EXPECT_STREQ("alpha", handler.msg()); 1979 EXPECT_STREQ("alpha", handler.msg());
1980 service_msg = Eval(lib, "[0, port, ['beta'], [], []]"); 1980 service_msg = Eval(lib, "[0, port, ['beta'], [], []]");
1981 Service::HandleIsolateMessage(isolate, service_msg); 1981 Service::HandleIsolateMessage(isolate, service_msg);
1982 handler.HandleNextMessage(); 1982 handler.HandleNextMessage();
1983 EXPECT_STREQ("beta", handler.msg()); 1983 EXPECT_STREQ("beta", handler.msg());
1984 } 1984 }
1985 1985
1986 1986
1987 TEST_CASE(Service_MetricsList) {
1988 const char* kScript =
1989 "import 'dart:profiler';\n"
1990 "var port;\n" // Set to our mock port by C++.
1991 "\n"
1992 "main() {\n"
1993 " var counter = new Counter('a.b.c', 'description');\n"
1994 " Metrics.register(counter);\n"
1995 " return counter;\n"
1996 "}\n"
1997 "";
1998
1999 Isolate* isolate = Isolate::Current();
2000 Dart_Handle h_lib = TestCase::LoadTestScript(kScript, NULL);
2001 EXPECT_VALID(h_lib);
2002 Library& lib = Library::Handle();
2003 lib ^= Api::UnwrapHandle(h_lib);
2004 EXPECT(!lib.IsNull());
2005 Dart_Handle result = Dart_Invoke(h_lib, NewString("main"), 0, NULL);
2006 EXPECT_VALID(result);
2007
2008 // Build a mock message handler and wrap it in a dart port.
2009 ServiceTestMessageHandler handler;
2010 Dart_Port port_id = PortMap::CreatePort(&handler);
2011 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id));
2012 EXPECT_VALID(port);
2013 EXPECT_VALID(Dart_SetField(h_lib, NewString("port"), port));
2014
2015 Array& service_msg = Array::Handle();
2016 service_msg = Eval(h_lib, "[0, port, ['metrics'], [], []]");
2017 Service::HandleIsolateMessage(isolate, service_msg);
2018 handler.HandleNextMessage();
2019 // Expect MetricList.
2020 // TODO(johnmccutchan): Test that list length is 1.
2021 EXPECT_SUBSTRING("\"type\":\"MetricList\"", handler.msg());
2022 }
2023
2024
2025 TEST_CASE(Service_Metric) {
2026 const char* kScript =
2027 "import 'dart:profiler';\n"
2028 "var port;\n" // Set to our mock port by C++.
2029 "\n"
2030 "main() {\n"
2031 " var counter = new Counter('a.b.c', 'description');\n"
2032 " Metrics.register(counter);\n"
2033 " return counter;\n"
2034 "}\n"
2035 "";
2036
2037 Isolate* isolate = Isolate::Current();
2038 Dart_Handle h_lib = TestCase::LoadTestScript(kScript, NULL);
2039 EXPECT_VALID(h_lib);
2040 Library& lib = Library::Handle();
2041 lib ^= Api::UnwrapHandle(h_lib);
2042 EXPECT(!lib.IsNull());
2043 Dart_Handle result = Dart_Invoke(h_lib, NewString("main"), 0, NULL);
2044 EXPECT_VALID(result);
2045
2046 // Build a mock message handler and wrap it in a dart port.
2047 ServiceTestMessageHandler handler;
2048 Dart_Port port_id = PortMap::CreatePort(&handler);
2049 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id));
2050 EXPECT_VALID(port);
2051 EXPECT_VALID(Dart_SetField(h_lib, NewString("port"), port));
2052
2053 // Request existing metric.
2054 Array& service_msg = Array::Handle();
2055 service_msg = Eval(h_lib, "[0, port, ['metrics', 'a.b.c'], [], []]");
2056 Service::HandleIsolateMessage(isolate, service_msg);
2057 handler.HandleNextMessage();
2058
2059 // Expect Counter.
2060 EXPECT_SUBSTRING("\"type\":\"Counter\"", handler.msg());
2061
2062 // Request invalid metric.
2063 service_msg = Eval(h_lib, "[0, port, ['metrics', 'a.b.c.d'], [], []]");
2064 Service::HandleIsolateMessage(isolate, service_msg);
2065 handler.HandleNextMessage();
2066
2067 // Expect error.
2068 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg());
2069 }
2070
2071
1987 // TODO(zra): Remove when tests are ready to enable. 2072 // TODO(zra): Remove when tests are ready to enable.
1988 #if !defined(TARGET_ARCH_ARM64) 2073 #if !defined(TARGET_ARCH_ARM64)
1989 2074
1990 TEST_CASE(Service_Profile) { 2075 TEST_CASE(Service_Profile) {
1991 const char* kScript = 2076 const char* kScript =
1992 "var port;\n" // Set to our mock port by C++. 2077 "var port;\n" // Set to our mock port by C++.
1993 "\n" 2078 "\n"
1994 "var x = 7;\n" 2079 "var x = 7;\n"
1995 "main() {\n" 2080 "main() {\n"
1996 " x = x * x;\n" 2081 " x = x * x;\n"
(...skipping 29 matching lines...) Expand all
2026 service_msg = Eval(lib, "[0, port, ['profile'], ['tags'], ['hidden']]"); 2111 service_msg = Eval(lib, "[0, port, ['profile'], ['tags'], ['hidden']]");
2027 Service::HandleIsolateMessage(isolate, service_msg); 2112 Service::HandleIsolateMessage(isolate, service_msg);
2028 handler.HandleNextMessage(); 2113 handler.HandleNextMessage();
2029 // Expect error. 2114 // Expect error.
2030 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg()); 2115 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg());
2031 } 2116 }
2032 2117
2033 #endif // !defined(TARGET_ARCH_ARM64) 2118 #endif // !defined(TARGET_ARCH_ARM64)
2034 2119
2035 } // namespace dart 2120 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/service.cc ('k') | sdk/lib/profiler/profiler.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698