var UIOT_Debug = function () {
    this.logData = new Array();
    this.startTime = Date.now();
};
UIOT_Debug.prototype.push = function (key) {
    var time = Date.now() - this.startTime;
    this.logData.push({
        key: key,
        time: time
    });
};
UIOT_Debug.prototype.upload = function (iot,title) {
    var logData = this.logData;
//  console.log(logData);
    var http = new XMLHttpRequest();
    iot.business.websql.getMap('userinfo', function (userinfo) {
        var params = {
            username: userinfo.username,
            cloud_app_id: '10004',
            title: title,
            log_data: JSON.stringify(logData),
            environment: iot.utils.getBrowserInfo(),
            log_type: 2,
            code_type: 3
        };
        http.open('POST', 'https://admin.iot.u-gen.net/admin/api/debug/uploadDebugLog', true);
        http.setRequestHeader('Accept', 'application/json');
        http.setRequestHeader('Content-type', 'application/json; charset=UTF-8');
        http.onreadystatechange = function() {
            if (http.readyState === 4 && http.status === 200) {
                var response = JSON.parse(http.responseText);
//              console.log(response);
            }
        };
        http.send(JSON.stringify(params));
    }, function (error) {
    });
};

var iotDebug = new UIOT_Debug();
iotDebug.push('start: debug');

function debugScript(script) {
    var src = script.src;
    var array = src.split('/');
    iotDebug.push('load: ' + array[array.length - 1]);
}