aboutsummaryrefslogtreecommitdiffhomepage
path: root/bench/ResultsWriter.cpp
blob: 0ab8cb19080a25343978b1ccfeba0b510667349a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
 * Copyright 2014 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 *
 * Helper functions for result writing operations.
 */

#include "ResultsWriter.h"
#include "SkString.h"
#include "SkTArray.h"

Json::Value* SkFindNamedNode(Json::Value* root, const char name[]) {
    Json::Value* search_results = NULL;
    for(Json::Value::iterator iter = root->begin();
            iter!= root->end(); ++iter) {
        if(SkString(name).equals((*iter)["name"].asCString())) {
            search_results = &(*iter);
            break;
        }
    }

    if(search_results != NULL) {
        return search_results;
    } else {
        Json::Value* new_val = &(root->append(Json::Value()));
        (*new_val)["name"] = name;
        return new_val;
    }
}

Json::Value SkMakeBuilderJSON(const SkString &builderName) {
    static const int kNumKeys = 6;
    static const char* kKeys[kNumKeys] = {
        "role", "os", "model", "gpu", "arch", "configuration"};
    Json::Value builderData;

    if (!builderName.isEmpty()) {
        SkTArray<SkString> splitBuilder;
        SkStrSplit(builderName.c_str(), "-", &splitBuilder);
        SkASSERT(splitBuilder.count() >= kNumKeys);
        for (int i = 0; i < kNumKeys && i < splitBuilder.count(); ++i) {
            builderData[kKeys[i]] = splitBuilder[i].c_str();
        }
        builderData["builderName"] = builderName.c_str();
        if (kNumKeys < splitBuilder.count()) {
            SkString extras;
            for (int i = kNumKeys; i < splitBuilder.count(); ++i) {
                extras.append(splitBuilder[i]);
                if (i != splitBuilder.count() - 1) {
                    extras.append("-");
                }
            }
            builderData["badParams"] = extras.c_str();
        }
    } 
    return builderData;
}