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

Side by Side Diff: tests/service_tests/performance/performance_test.cc

Issue 1659163007: Rename fletch -> dartino (Closed) Base URL: https://github.com/dartino/sdk.git@master
Patch Set: address comments Created 4 years, 10 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
OLDNEW
1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dartino 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.md file. 3 // BSD-style license that can be found in the LICENSE.md file.
4 4
5 #include <pthread.h> 5 #include <pthread.h>
6 #include <sys/time.h> 6 #include <sys/time.h>
7 7
8 #include <cstdio> 8 #include <cstdio>
9 9
10 #include "include/service_api.h" 10 #include "include/service_api.h"
11 #include "include/fletch_api.h" 11 #include "include/dartino_api.h"
12 12
13 #include "src/shared/assert.h" 13 #include "src/shared/assert.h"
14 #include "src/shared/platform.h" 14 #include "src/shared/platform.h"
15 15
16 #include "src/vm/thread_pool.h" 16 #include "src/vm/thread_pool.h"
17 17
18 #include "cc/performance_service.h" 18 #include "cc/performance_service.h"
19 19
20 static pthread_mutex_t mutex; 20 static pthread_mutex_t mutex;
21 static pthread_cond_t cond; 21 static pthread_cond_t cond;
22 static int status = 0; 22 static int status = 0;
23 23
24 static const int kDone = 1; 24 static const int kDone = 1;
25 static const int kCallCount = 10000; 25 static const int kCallCount = 10000;
26 26
27 static fletch::Monitor* echo_monitor = fletch::Platform::CreateMonitor(); 27 static dartino::Monitor* echo_monitor = dartino::Platform::CreateMonitor();
28 static bool echo_async_done = false; 28 static bool echo_async_done = false;
29 29
30 static uint64_t GetMicroseconds() { 30 static uint64_t GetMicroseconds() {
31 struct timeval tv; 31 struct timeval tv;
32 if (gettimeofday(&tv, NULL) < 0) return -1; 32 if (gettimeofday(&tv, NULL) < 0) return -1;
33 uint64_t result = tv.tv_sec * 1000000LL; 33 uint64_t result = tv.tv_sec * 1000000LL;
34 result += tv.tv_usec; 34 result += tv.tv_usec;
35 return result; 35 return result;
36 } 36 }
37 37
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 void EchoInThread(void* data) { 118 void EchoInThread(void* data) {
119 intptr_t value = reinterpret_cast<intptr_t>(data); 119 intptr_t value = reinterpret_cast<intptr_t>(data);
120 for (int i = 0; i < 64; i++) { 120 for (int i = 0; i < 64; i++) {
121 int result = PerformanceService::echo(value + i); 121 int result = PerformanceService::echo(value + i);
122 ASSERT(result == value + i); 122 ASSERT(result == value + i);
123 } 123 }
124 } 124 }
125 125
126 static void RunThreadTests() { 126 static void RunThreadTests() {
127 const int kThreadCount = 32; 127 const int kThreadCount = 32;
128 fletch::ThreadPool thread_pool(kThreadCount); 128 dartino::ThreadPool thread_pool(kThreadCount);
129 thread_pool.Start(); 129 thread_pool.Start();
130 for (int i = 0; i < kThreadCount; i++) { 130 for (int i = 0; i < kThreadCount; i++) {
131 while (!thread_pool.TryStartThread(EchoInThread, 131 while (!thread_pool.TryStartThread(EchoInThread,
132 reinterpret_cast<void*>(i))) { 132 reinterpret_cast<void*>(i))) {
133 } 133 }
134 } 134 }
135 thread_pool.JoinAll(); 135 thread_pool.JoinAll();
136 } 136 }
137 137
138 static void ChangeStatusAndNotify(int new_status) { 138 static void ChangeStatusAndNotify(int new_status) {
139 pthread_mutex_lock(&mutex); 139 pthread_mutex_lock(&mutex);
140 status = new_status; 140 status = new_status;
141 pthread_cond_signal(&cond); 141 pthread_cond_signal(&cond);
142 pthread_mutex_unlock(&mutex); 142 pthread_mutex_unlock(&mutex);
143 } 143 }
144 144
145 static void WaitForStatus(int expected) { 145 static void WaitForStatus(int expected) {
146 pthread_mutex_lock(&mutex); 146 pthread_mutex_lock(&mutex);
147 while (expected != status) pthread_cond_wait(&cond, &mutex); 147 while (expected != status) pthread_cond_wait(&cond, &mutex);
148 pthread_mutex_unlock(&mutex); 148 pthread_mutex_unlock(&mutex);
149 } 149 }
150 150
151 static void* DartThreadEntry(void* arg) { 151 static void* DartThreadEntry(void* arg) {
152 const char* path = static_cast<char*>(arg); 152 const char* path = static_cast<char*>(arg);
153 FletchSetup(); 153 DartinoSetup();
154 FletchRunSnapshotFromFile(path); 154 DartinoRunSnapshotFromFile(path);
155 FletchTearDown(); 155 DartinoTearDown();
156 ChangeStatusAndNotify(kDone); 156 ChangeStatusAndNotify(kDone);
157 return NULL; 157 return NULL;
158 } 158 }
159 159
160 static void RunSnapshotInNewThread(char* path) { 160 static void RunSnapshotInNewThread(char* path) {
161 pthread_t thread; 161 pthread_t thread;
162 int result = pthread_create(&thread, NULL, DartThreadEntry, path); 162 int result = pthread_create(&thread, NULL, DartThreadEntry, path);
163 if (result != 0) { 163 if (result != 0) {
164 perror("Failed to start thread"); 164 perror("Failed to start thread");
165 exit(1); 165 exit(1);
(...skipping 19 matching lines...) Expand all
185 printf("Usage: %s <snapshot>\n", argv[0]); 185 printf("Usage: %s <snapshot>\n", argv[0]);
186 return 1; 186 return 1;
187 } 187 }
188 SetupPerformanceTest(argc, argv); 188 SetupPerformanceTest(argc, argv);
189 RunEchoTests(); 189 RunEchoTests();
190 RunTreeTests(); 190 RunTreeTests();
191 RunThreadTests(); 191 RunThreadTests();
192 TearDownPerformanceTest(); 192 TearDownPerformanceTest();
193 return 0; 193 return 0;
194 } 194 }
OLDNEW
« no previous file with comments | « tests/service_tests/performance/java/SnapshotRunner.java ('k') | tests/service_tests/service_tests.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698