Parse benchmark data and use the client to upload it to the datastore. Parse the given benchmark data from the serialized JSON-format used to write the test results file. Create the different datastore Entities from that data and upload them to the datastore in a batch using the client conne
(client, data)
| 139 | |
| 140 | |
| 141 | def upload_benchmark_data(client, data): |
| 142 | """Parse benchmark data and use the client to upload it to the datastore. |
| 143 | |
| 144 | Parse the given benchmark data from the serialized JSON-format used to write |
| 145 | the test results file. Create the different datastore Entities from that data |
| 146 | and upload them to the datastore in a batch using the client connection. |
| 147 | |
| 148 | Args: |
| 149 | client: datastore client connection |
| 150 | data: JSON-encoded benchmark data |
| 151 | """ |
| 152 | test_result = json.loads(data) |
| 153 | |
| 154 | test_name = text_type(test_result["name"]) |
| 155 | start_time = datetime.datetime.utcfromtimestamp( |
| 156 | float(test_result["startTime"])) |
| 157 | batch = [] |
| 158 | |
| 159 | # Create the Test Entity containing all the test information as a |
| 160 | # non-indexed JSON blob. |
| 161 | t_key = client.key("Test") |
| 162 | t_val = datastore.Entity(t_key, exclude_from_indexes=["info"]) |
| 163 | t_val.update({ |
| 164 | "test": test_name, |
| 165 | "start": start_time, |
| 166 | "info": text_type(data) |
| 167 | }) |
| 168 | batch.append(t_val) |
| 169 | |
| 170 | # Create one Entry Entity for each benchmark entry. The wall-clock timing is |
| 171 | # the attribute to be fetched and displayed. The full entry information is |
| 172 | # also stored as a non-indexed JSON blob. |
| 173 | for ent in test_result["entries"].get("entry", []): |
| 174 | ent_name = text_type(ent["name"]) |
| 175 | e_key = client.key("Entry") |
| 176 | e_val = datastore.Entity(e_key, exclude_from_indexes=["info"]) |
| 177 | e_val.update({ |
| 178 | "test": test_name, |
| 179 | "start": start_time, |
| 180 | "entry": ent_name, |
| 181 | "timing": ent["wallTime"], |
| 182 | "info": text_type(json.dumps(ent)) |
| 183 | }) |
| 184 | batch.append(e_val) |
| 185 | |
| 186 | # Put the whole batch of Entities in the datastore. |
| 187 | client.put_multi(batch) |
| 188 | |
| 189 | |
| 190 | def upload_benchmark_files(opts): |
no test coverage detected