Log In
New Account
  
 
Home My Page Project Tree Code Snippets Project Openings NUTSS
 
 
Summary Tracker Lists CVS Files
 

CVS | Administration

Annotation of libnutss/examples/process_data.m, revision 1.1

1.1     ! ths         1: function re = process_data(sampleclocks)
        !             2:
        !             3:     capacityPerPeer = 400;
        !             4:
        !             5:     fid = fopen('args.txt','r');
        !             6:     n = fscanf(fid,'nodes: %d\n',1);
        !             7:     fclose(fid);
        !             8:     capacities = zeros(1,n);
        !             9:     peers = zeros(n,1);
        !            10:     rejections = zeros(n,1);
        !            11:     retirations = zeros(n,1);
        !            12:     f = cell(1,n);
        !            13:     % read the files, get all the data organized
        !            14:     for i=1:n
        !            15:         fid=fopen(['peer_node' num2str(i) '.txt'],'r');
        !            16:         if(fid > 0)
        !            17:            numpeers = fscanf(fid,'%d %d');
        !            18:            peers(i,1:length(numpeers)) = numpeers;
        !            19:            fclose(fid);
        !            20:         end
        !            21:     end
        !            22:     for i=1:n
        !            23:         fid=fopen(['data_node' num2str(i) '.txt'],'r');
        !            24:         if(fid > 0)
        !            25:             cap = fscanf(fid,'%d',1);
        !            26:             if length(cap) > 0
        !            27:                 capacities(i) = cap;
        !            28:             else
        !            29:                 continue;
        !            30:             end
        !            31:             t = textscan(fid,'%d%s');
        !            32:             m = length(t{1});
        !            33:             times = []; weights = [];
        !            34:             durations = [];
        !            35:             for j=1:m
        !            36:                 if(strcmp(t{2}{j},'reject'))
        !            37:                     rejections(i,j) = t{1}(j);
        !            38:                 elseif(strcmp(t{2}{j},'retire'))
        !            39:                     retirations(i,j) = t{1}(j);
        !            40:                 else
        !            41:                     data = sscanf(t{2}{j},'%d;%d;%d;');
        !            42:                     if(length(data) > 0)
        !            43:                         times = [times t{1}(j)];
        !            44:                         durations = [durations data(1)];
        !            45:                         weights = [weights data(2)];
        !            46:                     end
        !            47:                 end
        !            48:             end
        !            49:             f{i} = [times;durations;weights];
        !            50:             fclose(fid);
        !            51:         end
        !            52:     end
        !            53:     figure(); axes(); title('Load Versus Time');
        !            54:     xlabel('Time (m)'); ylabel('Load'); hold on;
        !            55:     d = zeros(n,1); m = zeros(n,1); s = zeros(n,1);
        !            56:     samples = zeros(n,1); sampletimes = zeros(n,1);
        !            57:
        !            58:     first_denial = min(retirations(find(retirations > 0)));
        !            59:     if length(first_denial) > 0
        !            60:         sampleclocks = [first_denial(1)/60 sampleclocks];
        !            61:     end
        !            62:     % reconstruct load over time from recorded events
        !            63:     for i=1:n
        !            64:         if(length(f{i}) > 0)
        !            65:             rqsts = length(f{i}(1,:));
        !            66:             times = zeros(1,rqsts*2);
        !            67:             delta = zeros(1,rqsts*2);
        !            68:             k = 1;
        !            69:             for j=1:rqsts
        !            70:                 times(k) = f{i}(1,j);
        !            71:                 delta(k) = f{i}(3,j);
        !            72:                 times(k+1) = f{i}(1,j)+f{i}(2,j);
        !            73:                 delta(k+1) = -f{i}(3,j);
        !            74:                 k = k + 2;
        !            75:             end
        !            76:             [sortedtimes,permutation]=sort(times./60);
        !            77:             d(i,1:2*rqsts) = cumsum(delta(permutation));
        !            78:             %%
        !            79:             if(length(sortedtimes(find(d(i,:) > capacities(i)))) > 0)
        !            80:                 i
        !            81:             end
        !            82:             %%
        !            83:             m(i) = mean(d(i,1:2*rqsts));
        !            84:             s(i) = std(d(i,1:2*rqsts));
        !            85:             plot(sortedtimes,d(i,1:2*rqsts));
        !            86:             temp = rejections(i,find(rejections(i,:)))./60;
        !            87:             plot(temp,ones(size(temp))*capacities(i),'g*');
        !            88:             temp = retirations(i,find(retirations(i,:)))./60;
        !            89:             plot(temp,ones(size(temp))*capacities(i),'r*');
        !            90:             k = 1;
        !            91:             for sampleclock=sampleclocks
        !            92:                 temp = abs(sortedtimes-sampleclock);
        !            93:                 samp = find(min(temp)==temp);
        !            94:                 sample(i,k) = d(i,samp(1));
        !            95:                 sampletimes(i,k) = sortedtimes(samp(1));
        !            96:                 k = k + 1;
        !            97:                 % this code below plots load with no gradation, the way it
        !            98:                 % works otherwise is as if load grows and shrinks gradually
        !            99:                 % rather than incrementally, this makes it completely discrete
        !           100:     %             temp = zeros(1,3*rqsts+1);
        !           101:     %             temptimes = zeros(1,3*rqsts);
        !           102:     %             get = 1;
        !           103:     %             temptimes(1) = sortedtimes(get);
        !           104:     %             for put=1:2:3*rqsts
        !           105:     %                 temp(put) = d(i,get);
        !           106:     %                 temp(put+1) = d(i,get);
        !           107:     %                 temptimes(put+1) = sortedtimes(get);
        !           108:     %                 temptimes(put+2) = sortedtimes(get);
        !           109:     %                 get = get+1;
        !           110:     %             end
        !           111:
        !           112:     %             points = min(length(temp),length(temptimes));
        !           113:     %             plot(temptimes(1:points),temp(1:points));
        !           114:             end
        !           115:         end
        !           116:     end
        !           117:     hold off;
        !           118:     for k=1:length(sampleclocks)
        !           119: %         figure(); axes(); title(['Distribution of Load per Peer at ' num2str(sampleclocks(k)) ' Minutes']);
        !           120: %         xlabel('Load per Peer'); ylabel('Number of Nodes'); hold on;
        !           121: %         hist(sample(:,k)'./peers,35); hold off;
        !           122: %         figure(); axes(); title(['Relative Load at ' num2str(sampleclocks(k)) ' Minutes']);
        !           123: %         xlabel('Node'); ylabel('Percent Load'); hold on;
        !           124: %         bar(sample(:,k)'./peers./capacityPerPeer.*100); hold off;
        !           125:         figure(); axes(); title(['Sorted Relative Load at ' num2str(sampleclocks(k)) ' Minutes']);
        !           126:         xlabel('Node'); ylabel('Percent Load'); hold on;
        !           127:         loads = sort(sample(:,k)'./capacities.*100);
        !           128:      bar(loads(find(~isnan(loads) & loads ~= 0))); hold off;
        !           129:         % also show loads sorted by capacity
        !           130:         figure(); axes(); title(['Relative Load at ' num2str(sampleclocks(k)) ' Minutes Sorted by Capacity']);
        !           131:         xlabel('Node (Capacities Low to High)'); ylabel('Percent Load'); hold on;
        !           132:         [garbage,permu] = sort(capacities,'ascend');
        !           133:         loads = (sample(:,k)'./capacities.*100);
        !           134:         loads = loads(permu);
        !           135:         bar(loads(find(~isnan(loads) & loads ~= 0))); hold off;
        !           136:     end
        !           137:
        !           138:     return;
        !           139:
        !           140:     [n,t] = size(peers);
        !           141:     f1 = figure(); f2 = figure();
        !           142:     for i=1:n
        !           143:         times = [];
        !           144:         degree = [];
        !           145:         mypeers = [];
        !           146:         for k=2:2:t
        !           147:             if peers(i,k) > 0
        !           148:                 mypeers(k/2) = peers(i,k);
        !           149:                 degree(k/2) = capacities(i) / peers(i,k);
        !           150:                 times(k/2) = peers(i,k-1) / 60;
        !           151:             else
        !           152:                 break;
        !           153:             end
        !           154:         end
        !           155:         figure(f1);
        !           156:         plot(times,degree);
        !           157:         axis([0 45 0 1200]);
        !           158:         title(['Node ' num2str(i) ' Capacity ' num2str(capacities(i))]);
        !           159:         xlabel('Time'); ylabel('Capacity / Peer');
        !           160:         figure(f2);
        !           161:         plot(times,mypeers);
        !           162:         axis([0 45 0 42]);
        !           163:         title(['Node ' num2str(i) ' Capacity ' num2str(capacities(i))]);
        !           164:         xlabel('Time'); ylabel('Peers');
        !           165:     end
        !           166: %     figure(); axes(); title('Distribution of Mean Load');
        !           167: %     xlabel('Mean Load'); ylabel('Nodes'); hold on;
        !           168: %     hist(m,35); hold off;
        !           169: %     figure(); axes(); title('Distribution of Standard Deviation of Load');
        !           170: %     xlabel('Standard Deviation of Load'); ylabel('Nodes'); hold on;
        !           171: %     hist(s,35); hold off;
        !           172: end

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>
 

GForge.cis.cornell.edu is brought to you by

Cornell Computing and Information Science


Powered By GForge Collaborative Development Environment